Skip to content

Commit

Permalink
WIP 1.21.2 update
Browse files Browse the repository at this point in the history
  • Loading branch information
tr7zw committed Oct 22, 2024
1 parent f9b76f9 commit c04be8e
Show file tree
Hide file tree
Showing 13 changed files with 192 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
37 changes: 37 additions & 0 deletions .github/workflows/tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
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/[email protected]
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/[email protected]
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/[email protected]
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ public class Config {
public int hitboxLimit = 50;
public boolean skipMarkerArmorStands = true;
public boolean tickCulling = true;
public Set<String> 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<String> 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;
Expand Down
4 changes: 3 additions & 1 deletion settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
2 changes: 1 addition & 1 deletion src/main/java/dev/tr7zw/entityculling/CullTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 2 additions & 10 deletions src/main/java/dev/tr7zw/entityculling/EntityCullingModBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
59 changes: 59 additions & 0 deletions src/main/java/dev/tr7zw/entityculling/NMSCullingHelper.java
Original file line number Diff line number Diff line change
@@ -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<Entity>) 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<Entity>) 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
}

}
8 changes: 7 additions & 1 deletion src/main/java/dev/tr7zw/entityculling/Provider.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<T extends Entity> {

Expand All @@ -13,4 +14,8 @@ public interface EntityRendererInter<T extends Entity> {
void shadowRenderNameTag(T entity, Component component, PoseStack poseStack, MultiBufferSource multiBufferSource,
int light, float f);

boolean ignoresCulling(T entity);

AABB getCullingBox(T entity);

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<T extends Entity> implements EntityRendererInter<T> {

@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

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,17 +33,17 @@ 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<Entity> entityRenderer = (EntityRenderer<Entity>) entityRenderDispatcher.getRenderer(entity);
EntityRenderer entityRenderer = (EntityRenderer) entityRenderDispatcher.getRenderer(entity);
@SuppressWarnings("unchecked")
EntityRendererInter<Entity> entityRendererInter = (EntityRendererInter<Entity>) entityRenderer;
if (EntityCullingModBase.instance.config.renderNametagsThroughWalls && matrices != null
&& vertexConsumers != null && entityRendererInter.shadowShouldShowName(entity)) {
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;
Expand Down
2 changes: 1 addition & 1 deletion versions/mainProject
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.21-fabric
1.21.2-fabric

0 comments on commit c04be8e

Please sign in to comment.