Skip to content

Commit

Permalink
re-add upstream piston fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
oh-noey committed Sep 15, 2024
1 parent 7eb8840 commit 92aa6c7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import net.minecraft.world.level.block.Mirror;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.piston.PistonBaseBlock;
import net.minecraft.world.level.block.piston.PistonMovingBlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.world.level.chunk.LevelChunkSection;
Expand Down Expand Up @@ -134,6 +136,24 @@ public void transformHitBox(@NotNull HitBox hitbox, @NotNull AffineTransformatio

@Nullable
private BlockEntity removeBlockEntity(@NotNull Level world, @NotNull BlockPos position) {
BlockEntity testEntity = world.getChunkAt(position).getBlockEntity(position);
//Prevents moving pistons by locking up by forcing their movement to finish
if (testEntity instanceof PistonMovingBlockEntity)
{
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import net.minecraft.world.level.block.Mirror;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.piston.PistonBaseBlock;
import net.minecraft.world.level.block.piston.PistonMovingBlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.world.level.chunk.LevelChunkSection;
Expand Down Expand Up @@ -134,6 +136,24 @@ public void transformHitBox(@NotNull HitBox hitbox, @NotNull AffineTransformatio

@Nullable
private BlockEntity removeBlockEntity(@NotNull Level world, @NotNull BlockPos position) {
BlockEntity testEntity = world.getChunkAt(position).getBlockEntity(position);
//Prevents moving pistons by locking up by forcing their movement to finish
if (testEntity instanceof PistonMovingBlockEntity)
{
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 92aa6c7

Please sign in to comment.