|
| 1 | +package dev.tr7zw.entityculling.mixin; |
| 2 | + |
| 3 | +import dev.tr7zw.entityculling.*; |
| 4 | +import dev.tr7zw.entityculling.access.*; |
| 5 | +import dev.tr7zw.entityculling.util.*; |
| 6 | +import dev.tr7zw.entityculling.versionless.occlusionculling.provider.*; |
| 7 | +import net.minecraft.world.level.block.*; |
| 8 | +import net.minecraft.world.level.block.state.*; |
| 9 | +import net.minecraft.world.level.chunk.*; |
| 10 | +import org.spongepowered.asm.mixin.*; |
| 11 | +import org.spongepowered.asm.mixin.injection.*; |
| 12 | +import org.spongepowered.asm.mixin.injection.callback.*; |
| 13 | + |
| 14 | +@Mixin(LevelChunkSection.class) |
| 15 | +public class LevelChunkSectionMixin implements ChunkSectionAccess { |
| 16 | + |
| 17 | + @Unique |
| 18 | + private volatile Object entityCulling$providerData; |
| 19 | + |
| 20 | + @Unique |
| 21 | + private volatile boolean entityCulling$Dirty = true; |
| 22 | + |
| 23 | + @Override |
| 24 | + public void ec$setProviderData(Object data) { |
| 25 | + this.entityCulling$providerData = data; |
| 26 | + } |
| 27 | + |
| 28 | + @Override |
| 29 | + public <T> T ec$getProviderData(Class<T> clazz) { |
| 30 | + if (clazz.isInstance(entityCulling$providerData)) { |
| 31 | + return clazz.cast(entityCulling$providerData); |
| 32 | + } |
| 33 | + return null; |
| 34 | + } |
| 35 | + |
| 36 | + @Override |
| 37 | + public boolean ec$isDirty() { |
| 38 | + return entityCulling$Dirty; |
| 39 | + } |
| 40 | + |
| 41 | + @Override |
| 42 | + public void ec$setDirty(boolean dirty) { |
| 43 | + this.entityCulling$Dirty = dirty; |
| 44 | + } |
| 45 | + |
| 46 | + @Override |
| 47 | + public PalettedContainer<BlockState> entityCulling$getStates() { |
| 48 | + return getStates(); |
| 49 | + } |
| 50 | + |
| 51 | + @Shadow |
| 52 | + private PalettedContainer<BlockState> getStates() { |
| 53 | + throw new AssertionError(); |
| 54 | + } |
| 55 | + |
| 56 | + @Inject(method = "setBlockState(IIILnet/minecraft/world/level/block/state/BlockState;)Lnet/minecraft/world/level/block/state/BlockState;", at = @At("RETURN"), require = 0) |
| 57 | + public void setBlockState(final int sectionX, final int sectionY, final int sectionZ, final BlockState state, |
| 58 | + CallbackInfoReturnable<BlockState> ci) { |
| 59 | + onSetBlockState(sectionX, sectionY, sectionZ, state); |
| 60 | + } |
| 61 | + |
| 62 | + @Inject(method = "setBlockState(IIILnet/minecraft/world/level/block/state/BlockState;Z)Lnet/minecraft/world/level/block/state/BlockState;", at = @At("RETURN"), require = 0) |
| 63 | + public void setBlockStateLegacy(final int sectionX, final int sectionY, final int sectionZ, final BlockState state, |
| 64 | + final boolean checkThreading, CallbackInfoReturnable<BlockState> ci) { |
| 65 | + onSetBlockState(sectionX, sectionY, sectionZ, state); |
| 66 | + } |
| 67 | + |
| 68 | + @Inject(method = "recalcBlockCounts", at = @At("HEAD")) |
| 69 | + public void recalcBlockCounts(CallbackInfo ci) { |
| 70 | + entityCulling$Dirty = true; |
| 71 | + if (EntityCullingModBase.instance != null) { |
| 72 | + EntityCullingModBase.instance.getDataProvider().recalcBlockCounts(this); |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + @Unique |
| 77 | + private void onSetBlockState(int sectionX, int sectionY, int sectionZ, BlockState state) { |
| 78 | + if (EntityCullingModBase.instance != null) { |
| 79 | + EntityCullingModBase.instance.getDataProvider().onChange(this, sectionX, sectionY, sectionZ, |
| 80 | + ECUtil.isOpaqueFullCube(state)); |
| 81 | + } |
| 82 | + } |
| 83 | + |
| 84 | +} |
0 commit comments