Don't crash when block entities are placed

- Block entities got a huge refactor in 1.17, a lot of the old code needs to be rethought
This commit is contained in:
Jozufozu 2021-09-15 14:28:44 -07:00
parent 40034daa64
commit 8407fed299
3 changed files with 10 additions and 36 deletions

View file

@ -1,7 +1,5 @@
package com.jozufozu.flywheel.backend.instancing;
import javax.annotation.Nonnull;
import com.jozufozu.flywheel.backend.Backend;
import com.jozufozu.flywheel.event.BeginFrameEvent;
import com.jozufozu.flywheel.event.ReloadRenderersEvent;
@ -42,13 +40,11 @@ public class InstancedRenderDispatcher {
getEntities(entity.level).queueUpdate(entity);
}
@Nonnull
public static InstanceManager<BlockEntity> getTiles(LevelAccessor world) {
return instanceWorlds.get(world)
.getTileEntityInstanceManager();
}
@Nonnull
public static InstanceManager<Entity> getEntities(LevelAccessor world) {
return instanceWorlds.get(world)
.getEntityInstanceManager();

View file

@ -20,7 +20,7 @@ import net.minecraftforge.api.distmarker.OnlyIn;
@Mixin(LevelRenderer.class)
public class FixFabulousDepthMixin {
@Inject(method = "renderLevel", at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/client/shader/ShaderGroup;process(F)V"))
@Inject(method = "renderLevel", at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/client/renderer/PostChain;process(F)V"))
private void disableTransparencyShaderDepth(PoseStack p_228426_1_, float p_228426_2_, long p_228426_3_, boolean p_228426_5_, Camera p_228426_6_, GameRenderer p_228426_7_, LightTexture p_228426_8_, Matrix4f p_228426_9_, CallbackInfo ci) {
GlStateManager._depthMask(false);
}

View file

@ -1,9 +1,5 @@
package com.jozufozu.flywheel.mixin;
import java.util.Set;
import net.minecraft.world.level.block.entity.TickingBlockEntity;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@ -11,46 +7,28 @@ import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import com.jozufozu.flywheel.backend.instancing.InstanceManager;
import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
@OnlyIn(Dist.CLIENT)
@Mixin(value = Level.class, priority = 1100) // this and create.mixins.json have high priority to load after Performant
@Mixin(value = LevelChunk.class, priority = 1100) // this and create.mixins.json have high priority to load after Performant
public class TileWorldHookMixin {
final Level self = (Level) (Object) this;
@Shadow
@Final
public boolean isClientSide;
Level level;
@Shadow
@Final
protected Set<BlockEntity> f_46434_; // FIXME: is this correct?
@Inject(at = @At("TAIL"), method = "addBlockEntityTicker(Lnet/minecraft/world/level/block/entity/TickingBlockEntity;)V")
private void onAddTile(TickingBlockEntity te, CallbackInfo ci) {
if (isClientSide) {
InstancedRenderDispatcher.getTiles(self)
.queueAdd((BlockEntity) te);
}
}
/**
* Without this we don't unload instances when a chunk unloads.
*/
@Inject(at = @At(value = "INVOKE", target = "Ljava/util/Set;clear()V", ordinal = 0), method = "tickBlockEntities")
private void onChunkUnload(CallbackInfo ci) {
if (isClientSide) {
InstanceManager<BlockEntity> kineticRenderer = InstancedRenderDispatcher.getTiles(self);
for (BlockEntity tile : f_46434_) {
kineticRenderer.remove(tile);
}
@Inject(at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/world/level/block/entity/BlockEntity;clearRemoved()V"),
method = "setBlockEntity")
private void onAddTile(BlockEntity te, CallbackInfo ci) {
if (level.isClientSide) {
InstancedRenderDispatcher.getTiles(level)
.queueAdd(te);
}
}
}