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) {
|
public void onReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean isMoving) {
|
||||||
super.onReplaced(state, world, pos, newState, 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 &&
|
if (getDirection() != BlockDirection.NONE &&
|
||||||
state.getBlock() == newState.getBlock() &&
|
state.getBlock() == newState.getBlock() &&
|
||||||
state.get(getDirection().getProperty()) != newState.get(getDirection().getProperty())) {
|
state.get(getDirection().getProperty()) != newState.get(getDirection().getProperty())) {
|
||||||
|
@@ -9,19 +9,14 @@ public class ColoredNetworkBlock extends NetworkNodeBlock {
|
|||||||
super(props);
|
super(props);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Don't do block drops if we change the color.
|
||||||
@Override
|
@Override
|
||||||
public void onReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean isMoving) {
|
public void onReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean isMoving) {
|
||||||
if (state.getBlock().getClass().equals(newState.getBlock().getClass())) {
|
if (state.getBlock().getClass().equals(newState.getBlock().getClass())) {
|
||||||
//From BaseBlock#onReplaced as this gets skipped otherwise
|
checkIfDirectionHasChanged(state, world, pos, newState);
|
||||||
if (getDirection() != BlockDirection.NONE &&
|
} else {
|
||||||
state.getBlock() == newState.getBlock() &&
|
super.onReplaced(state, world, pos, newState, isMoving);
|
||||||
state.get(getDirection().getProperty()) != newState.get(getDirection().getProperty())) {
|
|
||||||
onDirectionChanged(world, pos, newState.get(getDirection().getProperty()));
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
super.onReplaced(state, world, pos, newState, isMoving);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -46,9 +46,9 @@ public abstract class NetworkNodeBlock extends BaseBlock {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("deprecation")
|
@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()) {
|
if (state.getBlock() != newState.getBlock()) {
|
||||||
TileEntity tile = worldIn.getTileEntity(pos);
|
TileEntity tile = world.getTileEntity(pos);
|
||||||
|
|
||||||
if (tile instanceof NetworkNodeTile) {
|
if (tile instanceof NetworkNodeTile) {
|
||||||
IItemHandler handler = ((NetworkNodeTile) tile).getNode().getDrops();
|
IItemHandler handler = ((NetworkNodeTile) tile).getNode().getDrops();
|
||||||
@@ -60,13 +60,13 @@ public abstract class NetworkNodeBlock extends BaseBlock {
|
|||||||
drops.add(handler.getStackInSlot(i));
|
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
|
// 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
|
@Override
|
||||||
|
Reference in New Issue
Block a user