From 05fbf0eb5b47d4a839cfb911a59fa1bd7e3883eb Mon Sep 17 00:00:00 2001 From: Toad-Dev <748280+Toad-Dev@users.noreply.github.com> Date: Mon, 20 Dec 2021 09:07:05 -0800 Subject: [PATCH] Fix NPE when pistons extend (#43). - MixinLevel was needed in <= 1.16 to make sure pending block entities had a valid world, but in 1.17 and up all block entities have their world set immediately (after checking that their blockPos is valid). - Unfortunately, this bug leaves broken pistons in the world :( A piston will never seem to extend in the block location where the game hit the NPE, even if other block entities are put in that position and replaced with a new piston... --- .../fabric/mixin/MixinLevel.java | 59 ------------------- src/main/resources/computercraft.mixins.json | 1 - 2 files changed, 60 deletions(-) delete mode 100644 src/main/java/dan200/computercraft/fabric/mixin/MixinLevel.java diff --git a/src/main/java/dan200/computercraft/fabric/mixin/MixinLevel.java b/src/main/java/dan200/computercraft/fabric/mixin/MixinLevel.java deleted file mode 100644 index f9132b54e..000000000 --- a/src/main/java/dan200/computercraft/fabric/mixin/MixinLevel.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * This file is part of ComputerCraft - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2021. Do not distribute without permission. - * Send enquiries to dratcliffe@gmail.com - */ -package dan200.computercraft.fabric.mixin; - -import dan200.computercraft.shared.common.TileGeneric; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.entity.BlockEntity; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import javax.annotation.Nullable; -import java.util.Collection; - -/** - * Horrible bodge to ensure a {@link BlockEntity}'s world is always present when setting a TE during another TE's tick. - * - * Forge does this, this is just a bodge to get Fabric in line with that behaviour. - */ -@Mixin( Level.class ) -public class MixinLevel -{ - @Shadow - protected boolean tickingBlockEntities; - - @Inject( method = "setBlockEntity", at = @At( "HEAD" ) ) - public void setBlockEntity( @Nullable BlockEntity entity, CallbackInfo info ) - { - if( entity != null && !entity.isRemoved() && entity.getLevel().isInWorldBounds( entity.getBlockPos() ) && tickingBlockEntities ) - { - setWorld( entity, this ); - } - } - - private static void setWorld( BlockEntity entity, Object world ) - { - if( entity.getLevel() != world && entity instanceof TileGeneric ) - { - entity.setLevel( (Level) world ); //TODO why? - } - } - - // @Inject( method = "addBlockEntities", at = @At( "HEAD" ) ) - public void addBlockEntities( Collection entities, CallbackInfo info ) - { - if( tickingBlockEntities ) - { - for( BlockEntity entity : entities ) - { - setWorld( entity, this ); - } - } - } -} diff --git a/src/main/resources/computercraft.mixins.json b/src/main/resources/computercraft.mixins.json index 8acb52d3e..9d0594a1f 100644 --- a/src/main/resources/computercraft.mixins.json +++ b/src/main/resources/computercraft.mixins.json @@ -8,7 +8,6 @@ "MixinBlock", "MixinEntity", - "MixinLevel", "MixinMatrix4f", "MixinServerLevel", "MixinServerPlayerGameMode"