Fix crash if mechanical piston pushes a bed

This commit is contained in:
Snownee 2020-12-10 22:15:56 +08:00
parent e529c254c8
commit f425b150bd
2 changed files with 11 additions and 2 deletions

View file

@ -7,6 +7,7 @@ import java.util.Set;
import net.minecraft.util.Direction; import net.minecraft.util.Direction;
import net.minecraft.util.Direction.Axis; import net.minecraft.util.Direction.Axis;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IWorld;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.gen.feature.template.Template.BlockInfo; import net.minecraft.world.gen.feature.template.Template.BlockInfo;
@ -38,6 +39,15 @@ public abstract class TranslatingContraption extends Contraption {
return cachedColliders; return cachedColliders;
} }
@Override
public void removeBlocksFromWorld(IWorld world, BlockPos offset) {
int count = blocks.size();
super.removeBlocksFromWorld(world, offset);
if (count != blocks.size()) {
cachedColliders = null;
}
}
@Override @Override
protected boolean canAxisBeStabilized(Axis axis) { protected boolean canAxisBeStabilized(Axis axis) {
return false; return false;

View file

@ -81,8 +81,7 @@ public class PulleyTileEntity extends LinearActuatorTileEntity {
world.setBlockState(offset, Blocks.AIR.getDefaultState(), 66); world.setBlockState(offset, Blocks.AIR.getDefaultState(), 66);
} }
if (contraption != null && !contraption.getBlocks() if (!contraption.getBlocks().isEmpty()) {
.isEmpty()) {
contraption.removeBlocksFromWorld(world, BlockPos.ZERO); contraption.removeBlocksFromWorld(world, BlockPos.ZERO);
movedContraption = ControlledContraptionEntity.create(world, this, contraption); movedContraption = ControlledContraptionEntity.create(world, this, contraption);
movedContraption.setPosition(anchor.getX(), anchor.getY(), anchor.getZ()); movedContraption.setPosition(anchor.getX(), anchor.getY(), anchor.getZ());