Remove some duplication.
This commit is contained in:
@@ -39,6 +39,10 @@ public abstract class BaseBlock extends Block {
|
||||
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())) {
|
||||
|
@@ -9,19 +9,14 @@ public class ColoredNetworkBlock extends NetworkNodeBlock {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -46,9 +46,9 @@ public abstract class NetworkNodeBlock extends BaseBlock {
|
||||
|
||||
@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();
|
||||
@@ -60,13 +60,13 @@ public abstract class NetworkNodeBlock extends BaseBlock {
|
||||
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
|
||||
|
Reference in New Issue
Block a user