Skip to content

Commit

Permalink
made breaking pipes not use playerWillDestroy
Browse files Browse the repository at this point in the history
closes #220
  • Loading branch information
Ellpeck committed Nov 30, 2024
1 parent 4a0cde4 commit 04f2bf3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 21 deletions.
3 changes: 1 addition & 2 deletions src/main/java/de/ellpeck/prettypipes/items/WrenchItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,10 @@ public InteractionResult useOn(UseOnContext context) {
if (!world.isClientSide) {
if (tile.cover != null) {
// remove the cover
tile.removeCover(player, context.getHand());
tile.removeCover();
Utility.sendBlockEntityToClients(tile);
} else {
// remove the pipe
PipeBlock.dropItems(world, pos, player);
Block.dropResources(state, world, pos, tile, null, ItemStack.EMPTY);
world.removeBlock(pos, false);
}
Expand Down
22 changes: 5 additions & 17 deletions src/main/java/de/ellpeck/prettypipes/pipe/PipeBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,12 @@ public void onRemove(BlockState state, Level worldIn, BlockPos pos, BlockState n
network.removeNode(pos);
network.onPipeChanged(pos, state);
if (worldIn.getBlockEntity(pos) instanceof PipeBlockEntity pipe) {
Utility.dropInventory(pipe, pipe.modules);
for (var item : pipe.getItems())
item.drop(worldIn, item.getContent());
pipe.getItems().clear();
if (pipe.cover != null)
pipe.removeCover();
for (var craft : pipe.getActiveCrafts()) {
for (var lock : craft.ingredientsToRequest)
network.resolveNetworkLock(lock);
Expand All @@ -273,12 +278,6 @@ public void onRemove(BlockState state, Level worldIn, BlockPos pos, BlockState n
}
}

@Override
public BlockState playerWillDestroy(Level worldIn, BlockPos pos, BlockState state, Player player) {
PipeBlock.dropItems(worldIn, pos, player);
return super.playerWillDestroy(worldIn, pos, state, player);
}

@Override
public boolean hasAnalogOutputSignal(BlockState state) {
return true;
Expand Down Expand Up @@ -320,15 +319,4 @@ public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, Block
return BaseEntityBlock.createTickerHelper(type, Registry.pipeBlockEntity, PipeBlockEntity::tick);
}

public static void dropItems(Level worldIn, BlockPos pos, Player player) {
var tile = Utility.getBlockEntity(PipeBlockEntity.class, worldIn, pos);
if (tile != null) {
Utility.dropInventory(tile, tile.modules);
for (var item : tile.getItems())
item.drop(worldIn, item.getContent());
if (tile.cover != null)
tile.removeCover(player, InteractionHand.MAIN_HAND);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -353,10 +353,10 @@ public int getModuleSlot(ItemStack module) {
return -1;
}

public void removeCover(Player player, InteractionHand hand) {
public void removeCover() {
if (this.level.isClientSide)
return;
var drops = Block.getDrops(this.cover, (ServerLevel) this.level, this.worldPosition, null, player, player.getItemInHand(hand));
var drops = Block.getDrops(this.cover, (ServerLevel) this.level, this.worldPosition, null);
for (var drop : drops)
Containers.dropItemStack(this.level, this.worldPosition.getX(), this.worldPosition.getY(), this.worldPosition.getZ(), drop);
this.cover = null;
Expand Down

0 comments on commit 04f2bf3

Please sign in to comment.