From c04be8e12ae52dca6ac0363213ac6428315e0f0a Mon Sep 17 00:00:00 2001 From: tr7zw Date: Tue, 22 Oct 2024 21:36:29 +0200 Subject: [PATCH] WIP 1.21.2 update --- .github/workflows/build.yml | 2 +- .github/workflows/tag.yml | 37 ++++++++ .../entityculling/versionless/Config.java | 9 +- settings.json | 4 +- .../dev/tr7zw/entityculling/CullTask.java | 2 +- .../entityculling/EntityCullingModBase.java | 12 +-- .../tr7zw/entityculling/NMSCullingHelper.java | 59 +++++++++++++ .../dev/tr7zw/entityculling/Provider.java | 8 +- .../access/EntityRendererInter.java | 5 ++ .../entityculling/mixin/ClientWorldMixin.java | 5 +- .../mixin/EntityRendererMixin.java | 84 ++++++++++++++----- .../mixin/WorldRendererMixin.java | 7 +- versions/mainProject | 2 +- 13 files changed, 192 insertions(+), 44 deletions(-) create mode 100644 src/main/java/dev/tr7zw/entityculling/NMSCullingHelper.java diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fcb8806..b5f512c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -28,7 +28,7 @@ jobs: - name: build run: ./gradlecw build - name: capture build artifacts - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: Artifacts path: 'versions/**/build/libs/*.jar' diff --git a/.github/workflows/tag.yml b/.github/workflows/tag.yml index 5b45cd7..c49bb4d 100644 --- a/.github/workflows/tag.yml +++ b/.github/workflows/tag.yml @@ -355,3 +355,40 @@ jobs: name: ${{github.ref_name}}-1.21(.1) - Fabric files: 'versions/1.21-fabric/build/libs/!(*-@(dev|sources|javadoc|all)).jar' game-versions: 1.21.x + - name: Publish-1.21.2-neoforge-Curseforge + uses: Kir-Antipov/mc-publish@v3.3.0 + with: + curseforge-id: 448233 + curseforge-token: ${{ secrets.CURSEFORGE_TOKEN }} + loaders: neoforge + name: ${{github.ref_name}}-1.21.2 - NeoForge + version-type: beta + files: 'versions/1.21.2-neoforge/build/libs/!(*-@(dev|sources|javadoc|all)).jar' + game-versions: 1.21.2 + - name: Publish-1.21.2-neoforge-Modrinth + uses: Kir-Antipov/mc-publish@v3.3.0 + with: + modrinth-id: NNAgCjsB + modrinth-token: ${{ secrets.MODRINTH_TOKEN }} + loaders: neoforge + name: ${{github.ref_name}}-1.21.2 - NeoForge + files: 'versions/1.21.2-neoforge/build/libs/!(*-@(dev|sources|javadoc|all)).jar' + game-versions: 1.21.2 + - name: Publish-1.21.2-fabric-Curseforge + uses: Kir-Antipov/mc-publish@v3.3.0 + with: + curseforge-id: 448233 + curseforge-token: ${{ secrets.CURSEFORGE_TOKEN }} + loaders: fabric + name: ${{github.ref_name}}-1.21.2 - Fabric + files: 'versions/1.21.2-fabric/build/libs/!(*-@(dev|sources|javadoc|all)).jar' + game-versions: 1.21.2 + - name: Publish-1.21.2-fabric-Modrinth + uses: Kir-Antipov/mc-publish@v3.3.0 + with: + modrinth-id: NNAgCjsB + modrinth-token: ${{ secrets.MODRINTH_TOKEN }} + loaders: fabric + name: ${{github.ref_name}}-1.21.2 - Fabric + files: 'versions/1.21.2-fabric/build/libs/!(*-@(dev|sources|javadoc|all)).jar' + game-versions: 1.21.2 diff --git a/EntityCulling-Versionless/src/main/java/dev/tr7zw/entityculling/versionless/Config.java b/EntityCulling-Versionless/src/main/java/dev/tr7zw/entityculling/versionless/Config.java index 876fd34..35f0490 100644 --- a/EntityCulling-Versionless/src/main/java/dev/tr7zw/entityculling/versionless/Config.java +++ b/EntityCulling-Versionless/src/main/java/dev/tr7zw/entityculling/versionless/Config.java @@ -18,11 +18,10 @@ public class Config { public int hitboxLimit = 50; public boolean skipMarkerArmorStands = true; public boolean tickCulling = true; - public Set tickCullingWhitelist = new HashSet<>( - Arrays.asList("minecraft:firework_rocket", "minecraft:boat", "create:carriage_contraption", - "create:contraption", "create:gantry_contraption", "create:stationary_contraption", - "mts:builder_existing", "mts:builder_rendering", "mts:builder_seat", - "drg_flares:drg_flares", "alexscaves:gum_worm", "alexscaves:gum_worm_segment")); + public Set tickCullingWhitelist = new HashSet<>(Arrays.asList("minecraft:firework_rocket", "minecraft:boat", + "create:carriage_contraption", "create:contraption", "create:gantry_contraption", + "create:stationary_contraption", "mts:builder_existing", "mts:builder_rendering", "mts:builder_seat", + "drg_flares:drg_flares", "alexscaves:gum_worm", "alexscaves:gum_worm_segment")); public boolean disableF3 = false; public boolean skipEntityCulling = false; public boolean skipBlockEntityCulling = false; diff --git a/settings.json b/settings.json index 9c03da7..1b0b7bf 100644 --- a/settings.json +++ b/settings.json @@ -17,6 +17,8 @@ "1.20.6-fabric", "1.21-forge", "1.21-neoforge", - "1.21-fabric" + "1.21-fabric", + "1.21.2-neoforge", + "1.21.2-fabric" ] } diff --git a/src/main/java/dev/tr7zw/entityculling/CullTask.java b/src/main/java/dev/tr7zw/entityculling/CullTask.java index 555b626..1facc4c 100644 --- a/src/main/java/dev/tr7zw/entityculling/CullTask.java +++ b/src/main/java/dev/tr7zw/entityculling/CullTask.java @@ -118,7 +118,7 @@ private void cullEntities(Vec3 cameraMC, Vec3d camera) { // render it continue; } - AABB boundingBox = entity.getBoundingBoxForCulling(); + AABB boundingBox = NMSCullingHelper.getCullingBox(entity); if (boundingBox.getXsize() > hitboxLimit || boundingBox.getYsize() > hitboxLimit || boundingBox.getZsize() > hitboxLimit) { cullable.setCulled(false); // To big to bother to cull diff --git a/src/main/java/dev/tr7zw/entityculling/EntityCullingModBase.java b/src/main/java/dev/tr7zw/entityculling/EntityCullingModBase.java index fbdb050..ea04f05 100644 --- a/src/main/java/dev/tr7zw/entityculling/EntityCullingModBase.java +++ b/src/main/java/dev/tr7zw/entityculling/EntityCullingModBase.java @@ -11,12 +11,9 @@ import dev.tr7zw.util.NMSHelper; import net.minecraft.ChatFormatting; import net.minecraft.client.KeyMapping; -import net.minecraft.client.Minecraft; -import net.minecraft.client.player.LocalPlayer; import net.minecraft.core.BlockPos; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.network.chat.Component; -import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; import net.minecraft.world.level.block.entity.BlockEntity; @@ -84,15 +81,10 @@ public void clientTick() { return; pressed = true; enabled = !enabled; - LocalPlayer player = Minecraft.getInstance().player; if (enabled) { - if (player != null) { - player.sendSystemMessage(Component.literal("Culling on").withStyle(ChatFormatting.GREEN)); - } + NMSCullingHelper.sendChatMessage(Component.literal("Culling on").withStyle(ChatFormatting.GREEN)); } else { - if (player != null) { - player.sendSystemMessage(Component.literal("Culling off").withStyle(ChatFormatting.RED)); - } + NMSCullingHelper.sendChatMessage(Component.literal("Culling off").withStyle(ChatFormatting.RED)); } } else { pressed = false; diff --git a/src/main/java/dev/tr7zw/entityculling/NMSCullingHelper.java b/src/main/java/dev/tr7zw/entityculling/NMSCullingHelper.java new file mode 100644 index 0000000..dc83868 --- /dev/null +++ b/src/main/java/dev/tr7zw/entityculling/NMSCullingHelper.java @@ -0,0 +1,59 @@ +package dev.tr7zw.entityculling; + +import dev.tr7zw.entityculling.access.EntityRendererInter; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.entity.EntityRenderer; +import net.minecraft.network.chat.Component; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.phys.AABB; +import net.minecraft.world.phys.Vec3; + +public class NMSCullingHelper { + + private final static Minecraft MC = Minecraft.getInstance(); + + @SuppressWarnings("unchecked") + public static boolean ignoresCulling(Entity entity) { + // spotless:off + //#if MC <= 12101 + //$$ return entity.noCulling; + //#else + return ((EntityRendererInter) MC.getEntityRenderDispatcher().getRenderer(entity)) + .ignoresCulling(entity); + //#endif + //spotless:on + } + + @SuppressWarnings("unchecked") + public static AABB getCullingBox(Entity entity) { + // spotless:off + //#if MC <= 12101 + //$$ return entity.getBoundingBoxForCulling(); + //#else + return ((EntityRendererInter) MC.getEntityRenderDispatcher().getRenderer(entity)).getCullingBox(entity); + //#endif + //spotless:on + } + + public static Vec3 getRenderOffset(EntityRenderer entityRenderer, Entity entity, float tickDelta) { + // spotless:off + //#if MC <= 12101 + //$$ return entityRenderer.getRenderOffset(entity, tickDelta); + //#else + return entityRenderer.getRenderOffset(entityRenderer.createRenderState(entity, tickDelta)); + //#endif + //spotless:on + } + + public static void sendChatMessage(Component message) { + // spotless:off + //#if MC <= 12101 + //$$ if (MC.player != null) + //$$ MC.player.sendSystemMessage(message); + //#else + MC.getChatListener().handleSystemMessage(message, false); + //#endif + //spotless:on + } + +} diff --git a/src/main/java/dev/tr7zw/entityculling/Provider.java b/src/main/java/dev/tr7zw/entityculling/Provider.java index 3ec2882..cb018a7 100644 --- a/src/main/java/dev/tr7zw/entityculling/Provider.java +++ b/src/main/java/dev/tr7zw/entityculling/Provider.java @@ -20,7 +20,13 @@ public boolean prepareChunk(int chunkX, int chunkZ) { @Override public boolean isOpaqueFullCube(int x, int y, int z) { BlockPos pos = new BlockPos(x, y, z); - return world.getBlockState(pos).isSolidRender(world, pos); + // spotless:off + //#if MC <= 12101 + //$$ return world.getBlockState(pos).isSolidRender(world, pos); + //#else + return world.getBlockState(pos).isSolidRender(); + //#endif + //spotless:on } @Override diff --git a/src/main/java/dev/tr7zw/entityculling/access/EntityRendererInter.java b/src/main/java/dev/tr7zw/entityculling/access/EntityRendererInter.java index f5a0bcf..47f464b 100644 --- a/src/main/java/dev/tr7zw/entityculling/access/EntityRendererInter.java +++ b/src/main/java/dev/tr7zw/entityculling/access/EntityRendererInter.java @@ -5,6 +5,7 @@ import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.network.chat.Component; import net.minecraft.world.entity.Entity; +import net.minecraft.world.phys.AABB; public interface EntityRendererInter { @@ -13,4 +14,8 @@ public interface EntityRendererInter { void shadowRenderNameTag(T entity, Component component, PoseStack poseStack, MultiBufferSource multiBufferSource, int light, float f); + boolean ignoresCulling(T entity); + + AABB getCullingBox(T entity); + } \ No newline at end of file diff --git a/src/main/java/dev/tr7zw/entityculling/mixin/ClientWorldMixin.java b/src/main/java/dev/tr7zw/entityculling/mixin/ClientWorldMixin.java index 446a673..612789f 100644 --- a/src/main/java/dev/tr7zw/entityculling/mixin/ClientWorldMixin.java +++ b/src/main/java/dev/tr7zw/entityculling/mixin/ClientWorldMixin.java @@ -6,6 +6,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import dev.tr7zw.entityculling.EntityCullingModBase; +import dev.tr7zw.entityculling.NMSCullingHelper; import dev.tr7zw.entityculling.versionless.access.Cullable; import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientLevel; @@ -30,8 +31,8 @@ public void tickEntity(Entity entity, CallbackInfo info) { return; // disabled } // Use abstract minecart instead of whitelist to also catch modded Minecarts - if (entity.noCulling || entity == mc.player || entity == mc.cameraEntity || entity.isPassenger() - || entity.isVehicle() || (entity instanceof AbstractMinecart)) { + if (NMSCullingHelper.ignoresCulling(entity) || entity == mc.player || entity == mc.cameraEntity + || entity.isPassenger() || entity.isVehicle() || (entity instanceof AbstractMinecart)) { EntityCullingModBase.instance.tickedEntities++; return; // never skip the client tick for the player or entities in vehicles/with // passengers. Also respect the "noCulling" flag diff --git a/src/main/java/dev/tr7zw/entityculling/mixin/EntityRendererMixin.java b/src/main/java/dev/tr7zw/entityculling/mixin/EntityRendererMixin.java index bdee746..5d67495 100644 --- a/src/main/java/dev/tr7zw/entityculling/mixin/EntityRendererMixin.java +++ b/src/main/java/dev/tr7zw/entityculling/mixin/EntityRendererMixin.java @@ -10,40 +10,86 @@ import net.minecraft.client.renderer.entity.EntityRenderer; import net.minecraft.network.chat.Component; import net.minecraft.world.entity.Entity; +import net.minecraft.world.phys.AABB; @Mixin(EntityRenderer.class) public abstract class EntityRendererMixin implements EntityRendererInter { @Override public boolean shadowShouldShowName(T entity) { - return shouldShowName(entity); + // spotless:off + //#if MC <= 12101 + //$$ return shouldShowName(entity); + //#else + return ((EntityRenderer)(Object)this).createRenderState(entity, 0).nameTag != null; + //#endif + //spotless:on } @Override public void shadowRenderNameTag(T entity, Component component, PoseStack poseStack, - MultiBufferSource multiBufferSource, int light, float f) { - renderNameTag(entity, component, poseStack, multiBufferSource, light + MultiBufferSource multiBufferSource, int light, float delta) { // spotless:off - //#if MC >= 12005 - , f); - //#else - //$$); - //#endif - //spotless:on + //#if MC >= 12102 + renderNameTag(((EntityRenderer)(Object)this).createRenderState(entity, delta), component, poseStack, multiBufferSource, light); + //#elseif MC >= 12005 + //$$ renderNameTag(entity, component, poseStack, multiBufferSource, light, delta); + //#else + //$$ renderNameTag(entity, component, poseStack, multiBufferSource, light); + //#endif + //spotless:on } + // spotless:off + //#if MC <= 12101 + //$$ @Shadow + //$$ public abstract boolean shouldShowName(T entity); + //#endif + //spotless:on + @Shadow - public abstract boolean shouldShowName(T entity); + // spotless:off + //#if MC >= 12102 + public abstract void renderNameTag(net.minecraft.client.renderer.entity.state.EntityRenderState entityRenderState, Component component, PoseStack poseStack, + MultiBufferSource multiBufferSource, int i); + //#elseif MC >= 12005 + //$$ public abstract void renderNameTag(T entity, Component component, PoseStack poseStack, + //$$ MultiBufferSource multiBufferSource, int i, float f); + //#else + //$$ public abstract void renderNameTag(T entity, Component component, PoseStack poseStack, + //$$ MultiBufferSource multiBufferSource, int i); + //#endif + //spotless:on + + @Override + public boolean ignoresCulling(T entity) { + // spotless:off + //#if MC <= 12101 + //$$ return entity.noCulling; + //#else + return !affectedByCulling(entity); + //#endif + //spotless:on + } + + @Override + public AABB getCullingBox(T entity) { + // spotless:off + //#if MC <= 12101 + //$$ return entity.getBoundingBoxForCulling(); + //#else + return getBoundingBoxForCulling(entity); + //#endif + //spotless:on + } + // spotless:off + //#if MC >= 12102 @Shadow - public abstract void renderNameTag(T entity, Component component, PoseStack poseStack, - MultiBufferSource multiBufferSource, int i - // spotless:off - //#if MC >= 12005 - , float f); - //#else - //$$); - //#endif - //spotless:on + abstract boolean affectedByCulling(T entity); + @Shadow + abstract AABB getBoundingBoxForCulling(T entity); + //#endif + //spotless:on } diff --git a/src/main/java/dev/tr7zw/entityculling/mixin/WorldRendererMixin.java b/src/main/java/dev/tr7zw/entityculling/mixin/WorldRendererMixin.java index 0598e89..b724a4d 100644 --- a/src/main/java/dev/tr7zw/entityculling/mixin/WorldRendererMixin.java +++ b/src/main/java/dev/tr7zw/entityculling/mixin/WorldRendererMixin.java @@ -9,6 +9,7 @@ import com.mojang.blaze3d.vertex.PoseStack; import dev.tr7zw.entityculling.EntityCullingModBase; +import dev.tr7zw.entityculling.NMSCullingHelper; import dev.tr7zw.entityculling.access.EntityRendererInter; import dev.tr7zw.entityculling.versionless.access.Cullable; import net.minecraft.client.renderer.LevelRenderer; @@ -32,9 +33,9 @@ private void renderEntity(Entity entity, double cameraX, double cameraY, double return; } Cullable cullable = (Cullable) entity; - if (!cullable.isForcedVisible() && cullable.isCulled() && !entity.noCulling) { + if (!cullable.isForcedVisible() && cullable.isCulled() && !NMSCullingHelper.ignoresCulling(entity)) { @SuppressWarnings("unchecked") - EntityRenderer entityRenderer = (EntityRenderer) entityRenderDispatcher.getRenderer(entity); + EntityRenderer entityRenderer = (EntityRenderer) entityRenderDispatcher.getRenderer(entity); @SuppressWarnings("unchecked") EntityRendererInter entityRendererInter = (EntityRendererInter) entityRenderer; if (EntityCullingModBase.instance.config.renderNametagsThroughWalls && matrices != null @@ -42,7 +43,7 @@ private void renderEntity(Entity entity, double cameraX, double cameraY, double double x = Mth.lerp((double) tickDelta, (double) entity.xOld, (double) entity.getX()) - cameraX; double y = Mth.lerp((double) tickDelta, (double) entity.yOld, (double) entity.getY()) - cameraY; double z = Mth.lerp((double) tickDelta, (double) entity.zOld, (double) entity.getZ()) - cameraZ; - Vec3 vec3d = entityRenderer.getRenderOffset(entity, tickDelta); + Vec3 vec3d = NMSCullingHelper.getRenderOffset(entityRenderer, entity, tickDelta); double d = x + vec3d.x; double e = y + vec3d.y; double f = z + vec3d.z; diff --git a/versions/mainProject b/versions/mainProject index dfdd511..00af18c 100644 --- a/versions/mainProject +++ b/versions/mainProject @@ -1 +1 @@ -1.21-fabric \ No newline at end of file +1.21.2-fabric \ No newline at end of file