use of net.minecraft.block.CauldronBlock in project AntimatterAPI by GregTech-Intergalactical.
the class MaterialItem method onItemUse.
@Override
public ActionResultType onItemUse(ItemUseContext context) {
if (context.getPlayer() == null)
return ActionResultType.PASS;
World world = context.getWorld();
PlayerEntity player = context.getPlayer();
BlockPos pos = context.getPos();
ItemStack stack = player.getHeldItem(context.getHand());
BlockState state = world.getBlockState(pos);
if (type == Data.DUST_IMPURE && state.getBlock() instanceof CauldronBlock) {
int level = state.get(CauldronBlock.LEVEL);
if (level > 0) {
MaterialItem item = (MaterialItem) stack.getItem();
player.setHeldItem(context.getHand(), Data.DUST_IMPURE.get(item.getMaterial(), stack.getCount()));
world.setBlockState(context.getPos(), state.with(CauldronBlock.LEVEL, --level));
world.playSound(player, pos, SoundEvents.ITEM_BUCKET_EMPTY, SoundCategory.BLOCKS, 1.0F, 1.0F);
return ActionResultType.SUCCESS;
}
}
return ActionResultType.FAIL;
}
use of net.minecraft.block.CauldronBlock in project SophisticatedBackpacks by P3pp3rF1y.
the class CommonProxy method onCauldronInteract.
private void onCauldronInteract(PlayerInteractEvent.RightClickBlock event) {
PlayerEntity player = event.getPlayer();
Hand hand = event.getHand();
ItemStack backpack = player.getItemInHand(hand);
if (!(backpack.getItem() instanceof BackpackItem)) {
return;
}
BlockPos pos = event.getPos();
World world = event.getWorld();
BlockState state = world.getBlockState(pos);
Block block = state.getBlock();
if (block != Blocks.CAULDRON) {
return;
}
int level = state.getValue(CauldronBlock.LEVEL);
LazyOptional<IBackpackWrapper> backpackWrapperCapability = backpack.getCapability(CapabilityBackpackWrapper.getCapabilityInstance());
if (level == 0 || backpackWrapperCapability.map(this::hasDefaultColor).orElse(true)) {
return;
}
if (!world.isClientSide) {
backpackWrapperCapability.ifPresent(w -> {
w.setColors(BackpackWrapper.DEFAULT_CLOTH_COLOR, BackpackWrapper.DEFAULT_BORDER_COLOR);
((CauldronBlock) block).setWaterLevel(world, pos, state, level - 1);
});
}
event.setCanceled(true);
event.setCancellationResult(ActionResultType.SUCCESS);
}
Aggregations