Skip to content

Commit

Permalink
Remove some duplication.
Browse files Browse the repository at this point in the history
  • Loading branch information
raoulvdberge committed Oct 24, 2020
1 parent 3d82ada commit a6773c3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ protected void onDirectionChanged(World world, BlockPos pos, Direction newDirect
public void onReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean isMoving) {
super.onReplaced(state, world, pos, newState, isMoving);

checkIfDirectionHasChanged(state, world, pos, newState);
}

protected void checkIfDirectionHasChanged(BlockState state, World world, BlockPos pos, BlockState newState) {
if (getDirection() != BlockDirection.NONE &&
state.getBlock() == newState.getBlock() &&
state.get(getDirection().getProperty()) != newState.get(getDirection().getProperty())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,14 @@ public ColoredNetworkBlock(Properties props) {
super(props);
}

// Don't do block drops if we change the color.
@Override
public void onReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean isMoving) {
if (state.getBlock().getClass().equals(newState.getBlock().getClass())) {
//From BaseBlock#onReplaced as this gets skipped otherwise
if (getDirection() != BlockDirection.NONE &&
state.getBlock() == newState.getBlock() &&
state.get(getDirection().getProperty()) != newState.get(getDirection().getProperty())) {
onDirectionChanged(world, pos, newState.get(getDirection().getProperty()));
}
return;
checkIfDirectionHasChanged(state, world, pos, newState);
} else {
super.onReplaced(state, world, pos, newState, isMoving);
}

super.onReplaced(state, world, pos, newState, isMoving);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ public void neighborChanged(BlockState state, World world, BlockPos pos, Block b

@Override
@SuppressWarnings("deprecation")
public void onReplaced(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving) {
public void onReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean isMoving) {
if (state.getBlock() != newState.getBlock()) {
TileEntity tile = worldIn.getTileEntity(pos);
TileEntity tile = world.getTileEntity(pos);

if (tile instanceof NetworkNodeTile) {
IItemHandler handler = ((NetworkNodeTile) tile).getNode().getDrops();
Expand All @@ -60,13 +60,13 @@ public void onReplaced(BlockState state, World worldIn, BlockPos pos, BlockState
drops.add(handler.getStackInSlot(i));
}

InventoryHelper.dropItems(worldIn, pos, drops);
InventoryHelper.dropItems(world, pos, drops);
}
}
}

// Call onReplaced after the drops check so the tile still exists
super.onReplaced(state, worldIn, pos, newState, isMoving);
super.onReplaced(state, world, pos, newState, isMoving);
}

@Override
Expand Down

0 comments on commit a6773c3

Please sign in to comment.