|
|
|
@ -82,28 +82,33 @@ public class PhaseShifterBlock extends EnergyBlock {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
|
|
|
|
|
ItemStack stack = player.getStackInHand(hand);
|
|
|
|
|
BlockEntity entity = world.getBlockEntity(pos);
|
|
|
|
|
ActionResult result = super.onUse(state, world, pos, player, hand, hit);
|
|
|
|
|
if (result != ActionResult.PASS) {
|
|
|
|
|
return result;
|
|
|
|
|
} else {
|
|
|
|
|
ItemStack stack = player.getStackInHand(hand);
|
|
|
|
|
BlockEntity entity = world.getBlockEntity(pos);
|
|
|
|
|
|
|
|
|
|
if (stack.getItem() instanceof DyeItem) {
|
|
|
|
|
DyeColor newColor = ((DyeItem) stack.getItem()).getColor();
|
|
|
|
|
if (state.get(COLOR) != newColor) {
|
|
|
|
|
world.setBlockState(pos, state.with(COLOR, newColor));
|
|
|
|
|
if (!player.isCreative()) {
|
|
|
|
|
stack.decrement(1);
|
|
|
|
|
if (stack.getItem() instanceof DyeItem && player.shouldCancelInteraction()) {
|
|
|
|
|
DyeColor newColor = ((DyeItem) stack.getItem()).getColor();
|
|
|
|
|
if (state.get(COLOR) != newColor) {
|
|
|
|
|
world.setBlockState(pos, state.with(COLOR, newColor));
|
|
|
|
|
if (!player.isCreative()) {
|
|
|
|
|
stack.decrement(1);
|
|
|
|
|
}
|
|
|
|
|
return ActionResult.SUCCESS;
|
|
|
|
|
} else {
|
|
|
|
|
return ActionResult.PASS;
|
|
|
|
|
}
|
|
|
|
|
return ActionResult.SUCCESS;
|
|
|
|
|
} else {
|
|
|
|
|
return ActionResult.PASS;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (entity instanceof Inventory) {
|
|
|
|
|
if (!world.isClient()) {
|
|
|
|
|
player.openHandledScreen(new SimpleNamedScreenHandlerFactory((i, inv, player2) -> new HopperScreenHandler(i, inv, (Inventory) entity), new TranslatableText("block." + EnergonRelics.NAMESPACE + ".phase_shifter")));
|
|
|
|
|
if (entity instanceof Inventory) {
|
|
|
|
|
if (!world.isClient()) {
|
|
|
|
|
player.openHandledScreen(new SimpleNamedScreenHandlerFactory((i, inv, player2) -> new HopperScreenHandler(i, inv, (Inventory) entity), new TranslatableText("block." + EnergonRelics.NAMESPACE + ".phase_shifter")));
|
|
|
|
|
}
|
|
|
|
|
return ActionResult.SUCCESS;
|
|
|
|
|
} else {
|
|
|
|
|
return ActionResult.FAIL;
|
|
|
|
|
}
|
|
|
|
|
return ActionResult.SUCCESS;
|
|
|
|
|
} else {
|
|
|
|
|
return ActionResult.FAIL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|