Skip to content

Commit

Permalink
Use NMS code to fix pistons
Browse files Browse the repository at this point in the history
  • Loading branch information
drfiveminusmint committed Sep 11, 2024
1 parent 64fb3be commit 30d4946
Showing 1 changed file with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,23 @@
import net.countercraft.movecraft.util.MathUtils;
import net.countercraft.movecraft.util.UnsafeUtils;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.ContainerLevelAccess;
import net.minecraft.world.level.BlockEventData;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.DirectionalBlock;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityTicker;
import net.minecraft.world.level.block.piston.PistonBaseBlock;
import net.minecraft.world.level.block.piston.PistonMovingBlockEntity;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.DirectionProperty;
import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.world.level.chunk.LevelChunkSection;
import net.minecraft.world.ticks.LevelChunkTicks;
Expand Down Expand Up @@ -218,10 +223,21 @@ public void translateCraft(@NotNull Craft craft, @NotNull MovecraftLocation disp
@Nullable
private BlockEntity removeBlockEntity(@NotNull Level world, @NotNull BlockPos position) {
BlockEntity testEntity = world.getChunkAt(position).getBlockEntity(position);
if (testEntity instanceof PistonMovingBlockEntity)
if (testEntity instanceof PistonMovingBlockEntity) //attempt to prevent piston bug
{
((PistonMovingBlockEntity)testEntity).finalTick(); //attempt to prevent piston bug
return null;
BlockState oldState;
if (((PistonMovingBlockEntity) testEntity).isSourcePiston() && testEntity.getBlockState().getBlock() instanceof PistonBaseBlock) {
if (((PistonMovingBlockEntity) testEntity).getMovedState().is(Blocks.PISTON))
oldState = Blocks.PISTON.defaultBlockState()
.setValue(PistonBaseBlock.FACING, ((PistonMovingBlockEntity) testEntity).getMovedState().getValue(PistonBaseBlock.FACING));
else
oldState = Blocks.STICKY_PISTON.defaultBlockState()
.setValue(PistonBaseBlock.FACING, ((PistonMovingBlockEntity) testEntity).getMovedState().getValue(PistonBaseBlock.FACING));
} else
oldState = ((PistonMovingBlockEntity) testEntity).getMovedState();
((PistonMovingBlockEntity) testEntity).finalTick();
setBlockFast(world, position, oldState);
return world.getBlockEntity(position);
}
return world.getChunkAt(position).blockEntities.remove(position);
}
Expand Down

0 comments on commit 30d4946

Please sign in to comment.