|
|
|
@ -3,6 +3,7 @@ package com.thebrokenrail.energonrelics.block;
|
|
|
|
|
import com.thebrokenrail.energonrelics.EnergonRelics;
|
|
|
|
|
import com.thebrokenrail.energonrelics.api.block.energy.EnergyBlock;
|
|
|
|
|
import com.thebrokenrail.energonrelics.block.entity.shifter.PhaseShifterBlockEntity;
|
|
|
|
|
import net.fabricmc.fabric.api.event.player.UseBlockCallback;
|
|
|
|
|
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
|
|
|
|
import net.minecraft.block.Block;
|
|
|
|
|
import net.minecraft.block.BlockState;
|
|
|
|
@ -25,6 +26,7 @@ import net.minecraft.text.TranslatableText;
|
|
|
|
|
import net.minecraft.util.ActionResult;
|
|
|
|
|
import net.minecraft.util.DyeColor;
|
|
|
|
|
import net.minecraft.util.Hand;
|
|
|
|
|
import net.minecraft.util.Identifier;
|
|
|
|
|
import net.minecraft.util.hit.BlockHitResult;
|
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
@ -86,31 +88,38 @@ public class PhaseShifterBlock extends EnergyBlock {
|
|
|
|
|
if (result != ActionResult.PASS) {
|
|
|
|
|
return result;
|
|
|
|
|
} else {
|
|
|
|
|
ItemStack stack = player.getStackInHand(hand);
|
|
|
|
|
BlockEntity entity = world.getBlockEntity(pos);
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
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 {
|
|
|
|
|
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.FAIL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void register(Identifier id) {
|
|
|
|
|
super.register(id);
|
|
|
|
|
UseBlockCallback.EVENT.register((player, world, hand, hit) -> {
|
|
|
|
|
if (!player.isSpectator() && player.shouldCancelInteraction()) {
|
|
|
|
|
BlockState state = world.getBlockState(hit.getBlockPos());
|
|
|
|
|
ItemStack stack = player.getStackInHand(hand);
|
|
|
|
|
if (stack.getItem() instanceof DyeItem) {
|
|
|
|
|
DyeColor newColor = ((DyeItem) stack.getItem()).getColor();
|
|
|
|
|
if (state.get(PhaseShifterBlock.COLOR) != newColor) {
|
|
|
|
|
world.setBlockState(hit.getBlockPos(), state.with(PhaseShifterBlock.COLOR, newColor));
|
|
|
|
|
if (!player.isCreative()) {
|
|
|
|
|
stack.decrement(1);
|
|
|
|
|
}
|
|
|
|
|
return ActionResult.SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
return ActionResult.SUCCESS;
|
|
|
|
|
} else {
|
|
|
|
|
return ActionResult.FAIL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ActionResult.PASS;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|