use of net.minecraft.item.BucketItem in project AgriCraft by AgriCraft.
the class BlockIrrigationTank method onBlockActivated.
@Override
@Deprecated
@SuppressWarnings("deprecation")
public ActionResultType onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult hit) {
ItemStack stack = player.getHeldItem(hand);
if (stack.getItem() instanceof BucketItem) {
BucketItem bucket = (BucketItem) stack.getItem();
Fluid fluid = bucket.getFluid();
if (fluid == Fluids.WATER) {
// try to fill from a bucket
TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileEntityIrrigationTank) {
TileEntityIrrigationTank tank = (TileEntityIrrigationTank) tile;
if (tank.pushWater(FluidAttributes.BUCKET_VOLUME, false) == FluidAttributes.BUCKET_VOLUME) {
tank.pushWater(FluidAttributes.BUCKET_VOLUME, true);
if (!player.isCreative()) {
player.setHeldItem(hand, new ItemStack(Items.BUCKET));
}
return ActionResultType.SUCCESS;
}
}
} else if (fluid == Fluids.EMPTY) {
// try to drain to a bucket
TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileEntityIrrigationTank) {
TileEntityIrrigationTank tank = (TileEntityIrrigationTank) tile;
if (tank.drainWater(FluidAttributes.BUCKET_VOLUME, false) == FluidAttributes.BUCKET_VOLUME) {
tank.drainWater(FluidAttributes.BUCKET_VOLUME, true);
player.setHeldItem(hand, new ItemStack(Items.WATER_BUCKET));
return ActionResultType.SUCCESS;
}
}
}
} else if (stack.getItem() == Items.LADDER) {
// try to place a ladder
if (!LADDER.fetch(state)) {
if (!world.isRemote()) {
world.setBlockState(pos, LADDER.apply(state, true));
if (!player.isCreative()) {
player.getHeldItem(hand).shrink(1);
}
}
return ActionResultType.SUCCESS;
}
}
return ActionResultType.FAIL;
}
Aggregations