Compare commits

...

2 Commits

Author SHA1 Message Date
470b5839a4 尝试修复客户端崩溃问题 2026-05-31 21:52:07 +08:00
GiantLuigi4
594c4decf3 improve keyboard camera 2024-10-21 23:53:07 -04:00
7 changed files with 227 additions and 122 deletions

View File

@ -1,113 +1,179 @@
plugins {
id 'eclipse'
id 'java'
id 'idea'
id 'maven-publish'
id 'net.neoforged.gradle' version '[6.0.18,6.2)'
id 'org.spongepowered.mixin' version '0.7.+'
id 'org.parchmentmc.librarian.forgegradle' version '1.+'
id 'com.github.johnrengelman.shadow' version '8.1.1'
id 'net.neoforged.moddev.legacyforge' version '2.0.103'
}
apply plugin: 'org.spongepowered.mixin'
println('Java: ' + System.getProperty('java.version') + ' JVM: ' + System.getProperty('java.vm.version') + '(' + System.getProperty('java.vendor') + ') Arch: ' + System.getProperty('os.arch'))
// Only add ProGuard if building with it
def enableProguard = project.hasProperty("enableProguard") && project.enableProguard.toBoolean()
if (enableProguard) {
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.guardsquare:proguard-gradle:7.7.0'
}
}
}
version = mod_version
group = maven_group // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = archives_base_name
base {
archivesName = mod_id
}
group = mod_group_id
version = "${minecraft_version}-${mod_version}"
// set java version
java.toolchain.languageVersion = JavaLanguageVersion.of(17)
// required for making a functional mod
sourceSets.main.resources.srcDirs += 'src/generated/resources'
mixin.add sourceSets.main, "webdisplays.refmap.json"
println "Java: ${System.getProperty 'java.version'}"
// neoforge gradle
minecraft {
mappings channel: 'parchment', version: '2023.06.26-1.20.1'
repositories {
mavenCentral()
maven { url = "https://libraries.minecraft.net/" }
maven { url = "https://cursemaven.com" }
maven { url = "https://maven.parchmentmc.org" }
maven { url = 'https://mcef-download.cinemamod.com/repositories/releases/' }
maven { url = "https://dl.cloudsmith.io/public/geckolib3/geckolib/maven/" }
maven { url = "https://maven.theillusivec4.top/" }
maven { url = "https://repo.lucko.me/" }
maven { url = "https://maven.kosmx.dev/" }
maven { url = "https://modmaven.dev" }
flatDir { dir "libs" }
}
accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')
legacyForge {
version = "${minecraft_version}-${forge_version}"
copyIdeResources = true
// Access transformer
accessTransformers = files("src/main/resources/META-INF/accesstransformer.cfg")
// Parchment mappings
parchment {
minecraftVersion = minecraft_version
mappingsVersion = mapping_lasting_version
}
runs {
client {
properties 'mixin.env.remapRefMap': 'true'
property 'mixin.env.refMapRemappingFile', "${project.projectDir}/build/createSrgToMcp/output.srg"
workingDirectory project.file('run')
arg "-mixin.config=webdisplays.mixins.json"
property 'forge.logging.console.level', 'debug'
configureEach {
systemProperty 'forge.logging.console.level', 'debug'
logLevel = org.slf4j.event.Level.DEBUG
}
mods {
webdisplays {
source sourceSets.main
}
}
client {
client()
programArgument "-mixin.config=${mod_id}.mixins.json"
systemProperty 'mixin.debug.export', 'true'
}
server {
properties 'mixin.env.remapRefMap': 'true'
property 'mixin.env.refMapRemappingFile', "${project.projectDir}/build/createSrgToMcp/output.srg"
workingDirectory project.file('run')
arg "-mixin.config=webdisplays.mixins.json"
property 'forge.logging.console.level', 'debug'
mods {
webdisplays {
source sourceSets.main
}
}
server()
programArgument "-mixin.config=${mod_id}.mixins.json"
}
data {
workingDirectory project.file('run')
properties 'mixin.env.remapRefMap': 'true'
property 'mixin.env.refMapRemappingFile', "${project.projectDir}/build/createSrgToMcp/output.srg"
property 'forge.logging.console.level', 'debug'
args '--mod', 'webdisplays', '--all', '--output', file('src/generated/resources/'), '--existing', sourceSets.main.resources.srcDirs[0]
mods {
webdisplays {
source sourceSets.main
}
}
data()
programArguments.addAll '--mod', mod_id, '--all',
'--output', file('src/generated/resources/').absolutePath,
'--existing', file('src/main/resources/').absolutePath
}
}
mods {
"${mod_id}" {
sourceSet sourceSets.main
}
}
}
repositories{
maven {
name = "cursemaven"
url = "https://www.cursemaven.com"
}
maven { url 'https://mcef-download.cinemamod.com/repositories/releases/' }
sourceSets.main.resources {
srcDir 'src/generated/resources'
}
dependencies {
minecraft 'net.neoforged:forge:1.20.1-47.1.65'
annotationProcessor 'org.spongepowered:mixin:0.8.5:processor'
// useful for debugging performance problems
implementation fg.deobf("curse.maven:spark-361579:4381167")
// here because we need to manually open the VR keyboard
compileOnly fg.deobf("curse.maven:vivecraft-667903:4794431")
implementation fg.deobf("com.cinemamod:mcef-forge:2.1.1-1.20.1") {
// MCEF dependency
modImplementation("com.cinemamod:mcef-forge:2.1.1-1.20.1") {
transitive = false
}
// Optional mods (make sure versions exist)
modRuntimeOnly "curse.maven:spark-361579:4738952"
modCompileOnly "curse.maven:vivecraft-667903:4794431"
modImplementation "software.bernie.geckolib:geckolib-forge-${minecraft_version}:${geckolib_version}"
modCompileOnly "top.theillusivec4.curios:curios-forge:${curios_version}:api"
modRuntimeOnly "top.theillusivec4.curios:curios-forge:${curios_version}"
// Mixin Extras
compileOnly annotationProcessor("io.github.llamalad7:mixinextras-common:0.4.1")
modImplementation "io.github.llamalad7:mixinextras-forge:0.4.1"
}
// jar meta-info
jar {
tasks.named('jar', Jar) {
manifest {
attributes([
"Specification-Title": "WebDisplays",
"Specification-Vendor": "CinemaMod Group",
"Specification-Version": "1", // We are version 1 of ourselves
"Implementation-Title": project.name,
"Implementation-Version": project.version,
"Implementation-Vendor": "CinemaMod Group",
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"),
"MixinConfigs": "webdisplays.mixins.json"
'Specification-Title': mod_name,
'Specification-Vendor': mod_authors,
'Specification-Version': '1',
'Implementation-Title': project.name,
'Implementation-Version': project.version,
'Implementation-Vendor': mod_authors,
'MixinConfigs': "${mod_id}.mixins.json"
])
}
// Exclude ProGuard renamed files if ProGuard is used
if (enableProguard) {
exclude 'META-INF/versions/**'
}
}
// Generate sources jar
tasks.register('sourcesJar', Jar) {
dependsOn classes
archiveClassifier = 'sources'
from sourceSets.main.allSource
}
// Reobfuscation handling
tasks.named('reobfJar') {
if (enableProguard) {
dependsOn 'proguard'
input = file("${buildDir}/libs/${mod_id}-${minecraft_version}-${mod_version}-proguard.jar")
} else {
dependsOn 'jar'
input = tasks.jar.archiveFile.get().asFile
}
}
// ProGuard configuration (if enabled)
if (enableProguard) {
tasks.register('proguard', proguard.gradle.ProGuardTask) {
dependsOn tasks.jar
configuration 'proguard.pro'
libraryjars "${System.getProperty('java.home')}/jmods"
def inputJar = tasks.jar.archiveFile.get().asFile
injars inputJar
outjars "${buildDir}/libs/${mod_id}-${minecraft_version}-${mod_version}-proguard.jar"
}
}
publishing {
publications {
mavenJava(MavenPublication) {
artifactId = mod_id
artifact reobfJar
artifact sourcesJar
}
}
repositories {
maven {
name = "local"
url = layout.buildDirectory.dir("repo")
}
}
}

View File

@ -1,5 +1,36 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs = -Xmx3G
mod_version = 2.0.2-1.20.1
maven_group = com.cinemamod
archives_base_name = webdisplays
# Gradle settings
org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=false
org.gradle.parallel=true
org.gradle.caching=true
# ProGuard
enableProguard=false
# Mod properties
mod_id=webdisplays
mod_name=WebDisplays
mod_version=2.0.3
mod_group_id=com.cinemamod
mod_authors=CinemaMod Group
mod_description=Web browser displays for Minecraft
mod_license=All Rights Reserved
mod_credits=CinemaMod Group
# Minecraft/Forge versions
minecraft_version=1.20.1
forge_version=47.3.4
minecraft_version_range=[1.20.1,1.21)
forge_version_range=[47,)
loader_version_range=[47,)
# Parchment mappings
mapping_channel=parchment
mapping_version=2023.09.03-1.20.1
mapping_lasting_version=2023.09.03
# Other mod versions
jei_version=15.20.0.112
player_anim_version=1.0.2-rc1+1.20
geckolib_version=4.2.1
curios_version=5.5.0+1.20.1

View File

@ -1,28 +1,11 @@
pluginManagement {
repositories {
mavenLocal()
gradlePluginPortal()
maven {
name = 'NeoForged'
url = 'https://maven.neoforged.net/releases'
}
maven { url = 'https://maven.neoforged.net/releases' }
maven { url = 'https://maven.parchmentmc.org' } // Add this line
}
// resolutionStrategy {
// eachPlugin {
// switch (requested.id.toString()) {
// case "net.minecraftforge.gradle": {
// useModule("${requested.id}:ForgeGradle:${requested.version}")
// break
// }
// case "org.spongepowered.mixin": {
// useModule("org.spongepowered:mixingradle:${requested.version}")
// break;
// }
// }
// }
// }
}
plugins {
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.5.0'
}
id 'org.gradle.toolchains.foojay-resolver-convention' version '1.0.0'
}

View File

@ -21,6 +21,7 @@ import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.client.multiplayer.ClientAdvancements;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderers;
import net.minecraft.client.renderer.entity.EntityRenderDispatcher;
import net.minecraft.core.BlockPos;
import net.minecraft.core.NonNullList;
import net.minecraft.nbt.CompoundTag;
@ -589,7 +590,9 @@ public class ClientProxy extends SharedProxy implements ResourceManagerReloadLis
if (!tes.isLoaded())
tes.load();
} else {
Camera camera = mc.getEntityRenderDispatcher().camera;
EntityRenderDispatcher entityRenderDispatcher = mc.getEntityRenderDispatcher();
if (entityRenderDispatcher == null) return;
Camera camera = entityRenderDispatcher.camera;
Entity entity = null;
// ide inspection says this is a bunch of constant expressions

View File

@ -17,7 +17,6 @@ import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.client.event.ViewportEvent;
import net.minecraftforge.fml.ModList;
import net.minecraftforge.fml.loading.FMLPaths;
import net.montoyo.wd.WebDisplays;
@ -287,11 +286,9 @@ public class GuiKeyboard extends WDScreen {
protected void mouse(double mouseX, double mouseY, Consumer<Vector2i> func) {
float pct = Minecraft.getInstance().getPartialTick();
ViewportEvent.ComputeFov fov = new ViewportEvent.ComputeFov(
Minecraft.getInstance().gameRenderer,
double fov = Minecraft.getInstance().gameRenderer.getFov(
Minecraft.getInstance().getEntityRenderDispatcher().camera,
pct, Minecraft.getInstance().options.fov().get(),
true
pct, true
);
mouseX /= width;
@ -301,7 +298,7 @@ public class GuiKeyboard extends WDScreen {
mouseY -= 0.5;
mouseY = -mouseY;
Matrix4f proj = Minecraft.getInstance().gameRenderer.getProjectionMatrix(fov.getFOV());
Matrix4f proj = Minecraft.getInstance().gameRenderer.getProjectionMatrix(fov);
Entity e = Minecraft.getInstance().getEntityRenderDispatcher().camera.getEntity();
@ -310,14 +307,12 @@ public class GuiKeyboard extends WDScreen {
camera.mulPose(Axis.XP.rotationDegrees(angle[0]));
camera.mulPose(Axis.YP.rotationDegrees(angle[1] + 180.0F));
Vector4f coord = new Vector4f(0, 0, 0, 0);
coord.add(proj.invert().transform(new Vector4f(2f * (float) mouseX, 2 * (float) mouseY, 0, 1f)));
Vector4f coord = new Vector4f(2f * (float) mouseX, 2 * (float) mouseY, 0, 1f);
coord.add(proj.invert().transform(coord));
coord = camera.last().pose().invert().transform(coord);
coord.w = 0;
coord.normalize();
Vec3 vec3 = e.getEyePosition(pct);
Vec3 vec31 = new Vec3(coord.x, coord.y, coord.z);
Vec3 vec31 = new Vec3(coord.x, coord.y, coord.z).normalize();
BlockHitResult result = tes.trace(side, vec3, vec31);
if (result.getType() != HitResult.Type.MISS) {
@ -343,6 +338,8 @@ public class GuiKeyboard extends WDScreen {
WDNetworkRegistry.INSTANCE.sendToServer(C2SMessageScreenCtrl.laserDown(tes, side, hit, button));
});
KeyboardCamera.setMouse(button, true);
return super.mouseClicked(mouseX, mouseY, button);
}
@ -354,6 +351,8 @@ public class GuiKeyboard extends WDScreen {
WDNetworkRegistry.INSTANCE.sendToServer(C2SMessageScreenCtrl.laserUp(tes, side, button));
});
KeyboardCamera.setMouse(button, false);
return super.mouseReleased(mouseX, mouseY, button);
}

View File

@ -30,6 +30,10 @@ public class KeyboardCamera {
private static double nextX = -1;
private static double nextY = -1;
private static double focalX = -1;
private static double focalY = -1;
private static final boolean[] mouseStatus = new boolean[2];
protected static Vec2 pxToHit(ScreenData scr, Vec2 dst) {
float cx, cy;
@ -82,14 +86,20 @@ public class KeyboardCamera {
if (scr != null) {
Vec2 c;
if (lock.hasFocused()) {
if (ClientConfig.Input.keyboardCamera) {
nextX = lock.getX();
nextY = lock.getY();
if (!mouseStatus[0] && !mouseStatus[1]) {
if (lock.hasFocused()) {
if (ClientConfig.Input.keyboardCamera) {
nextX = lock.getX();
nextY = lock.getY();
c = pxToHit(scr, new Vec2((float) nextX, (float) nextY));
c = pxToHit(scr, new Vec2((float) nextX, (float) nextY));
} else c = new Vec2(scr.size.x / 2f, scr.size.y / 2f);
} else c = new Vec2(scr.size.x / 2f, scr.size.y / 2f);
} else c = new Vec2(scr.size.x / 2f, scr.size.y / 2f);
// } else c = new Vec2((float) focalX, (float) focalY);
} else return;
focalX = c.x;
focalY = c.y;
nextX = c.x;
nextY = c.y;
@ -158,6 +168,10 @@ public class KeyboardCamera {
return angle;
}
public static void setMouse(int side, boolean pressed) {
mouseStatus[side] = pressed;
}
public static void updateCamera(ViewportEvent.ComputeCameraAngles event) {
if (tes == null) {
xCrd = -1;
@ -199,6 +213,11 @@ public class KeyboardCamera {
protected static int delay = 8;
public static void gameTick(TickEvent.ClientTickEvent event) {
if (mouseStatus[0] || mouseStatus[1]) {
oxCrd = Mth.lerp(0.5, oxCrd, xCrd);
oyCrd = Mth.lerp(0.5, oyCrd, yCrd);
return;
}
if (event.phase.equals(TickEvent.Phase.END)) {
if (side == null) {
delay = 1;

View File

@ -7,4 +7,8 @@ public-f net.minecraft.world.phys.AABB f_82289_
public-f net.minecraft.world.phys.AABB f_82290_
public-f net.minecraft.world.phys.AABB f_82291_
public-f net.minecraft.world.phys.AABB f_82292_
public-f net.minecraft.world.phys.AABB f_82293_
public-f net.minecraft.world.phys.AABB f_82293_
# GameRenderer
public net.minecraft.client.renderer.GameRenderer m_109141_(Lnet/minecraft/client/Camera;FZ)D # getFov