Java Code Examples for net.minecraft.init.Items#water_bucket()

The following examples show how to use net.minecraft.init.Items#water_bucket() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BlockLargePot.java    From GardenCollection with MIT License 6 votes vote down vote up
@Override
protected boolean applySubstrateToGarden (World world, int x, int y, int z, EntityPlayer player, int slot, ItemStack itemStack) {
    if (getGardenSubstrate(world, x, y, z, slot) != null)
        return false;

    if (itemStack.getItem() == Items.water_bucket) {
        TileEntityGarden garden = getTileEntity(world, x, y, z);
        garden.setSubstrate(new ItemStack(Blocks.water));
        garden.markDirty();

        if (player != null && !player.capabilities.isCreativeMode)
            player.inventory.setInventorySlotContents(player.inventory.currentItem, new ItemStack(Items.bucket));

        world.markBlockForUpdate(x, y, z);
        return true;
    }

    return super.applySubstrateToGarden(world, x, y, z, player, slot, itemStack);
}
 
Example 2
Source File: BlockLargePot.java    From GardenCollection with MIT License 5 votes vote down vote up
@Override
protected boolean applyItemToGarden (World world, int x, int y, int z, EntityPlayer player, ItemStack itemStack, float hitX, float hitY, float hitZ, boolean hitValid) {
    ItemStack item = (itemStack == null) ? player.inventory.getCurrentItem() : itemStack;
    if (item == null)
        return false;

    TileEntityGarden garden = getTileEntity(world, x, y, z);

    if (garden.getSubstrate() != null) {
        if (item.getItem() == Items.bucket) {
            if (Block.getBlockFromItem(garden.getSubstrate().getItem()) == Blocks.water) {
                player.inventory.setInventorySlotContents(player.inventory.currentItem, new ItemStack(Items.water_bucket));
                garden.setSubstrate(null);
                garden.markDirty();
                world.markBlockForUpdate(x, y, z);
            }
            return true;
        }

        if (item.getItem() == Items.water_bucket) {
            applyWaterToSubstrate(world, x, y, z, garden, player);
            return true;
        }
        else if (item.getItem() instanceof ItemHoe) {
            applyHoeToSubstrate(world, x, y, z, garden, player);
            return true;
        }
    }

    return super.applyItemToGarden(world, x, y, z, player, itemStack, hitX, hitY, hitZ, hitValid);
}
 
Example 3
Source File: NoFall.java    From LiquidBounce with GNU General Public License v3.0 4 votes vote down vote up
@EventTarget
private void onMotionUpdate(MotionEvent event) {
    if (!modeValue.get().equalsIgnoreCase("MLG"))
        return;

    if (event.getEventState() == EventState.PRE) {
        currentMlgRotation = null;
        mlgTimer.update();

        if (!mlgTimer.hasTimePassed(10))
            return;

        if (mc.thePlayer.fallDistance > minFallDistance.get()) {
            FallingPlayer fallingPlayer = new FallingPlayer(
                    mc.thePlayer.posX,
                    mc.thePlayer.posY,
                    mc.thePlayer.posZ,
                    mc.thePlayer.motionX,
                    mc.thePlayer.motionY,
                    mc.thePlayer.motionZ,
                    mc.thePlayer.rotationYaw,
                    mc.thePlayer.moveStrafing,
                    mc.thePlayer.moveForward
            );

            double maxDist = mc.playerController.getBlockReachDistance() + 1.5;

            FallingPlayer.CollisionResult collision = fallingPlayer.findCollision((int) Math.ceil((1.0 / mc.thePlayer.motionY) * (-maxDist)));

            if (collision == null)
                return;

            boolean ok = new Vec3(mc.thePlayer.posX, mc.thePlayer.posY + mc.thePlayer.eyeHeight, mc.thePlayer.posZ).distanceTo(new Vec3(collision.getPos()).addVector(0.5, 0.5, 0.5)) < mc.playerController.getBlockReachDistance() + Math.sqrt(0.75);

            if (mc.thePlayer.motionY < (collision.getPos().getY() + 1) - mc.thePlayer.posY) {
                ok = true;
            }

            if (!ok)
                return;

            int index = -1;

            for (int i = 36; i < 45; i++) {
                ItemStack itemStack = mc.thePlayer.inventoryContainer.getSlot(i).getStack();

                if (itemStack != null && (itemStack.getItem() == Items.water_bucket || itemStack.getItem() instanceof ItemBlock && ((ItemBlock) itemStack.getItem()).getBlock() == Blocks.web)) {
                    index = i - 36;

                    if (mc.thePlayer.inventory.currentItem == index)
                        break;
                }
            }

            if (index == -1)
                return;

            currentMlgItemIndex = index;
            currentMlgBlock = collision.getPos();

            if (mc.thePlayer.inventory.currentItem != index) {
                mc.thePlayer.sendQueue.addToSendQueue(new C09PacketHeldItemChange(index));
            }

            currentMlgRotation = RotationUtils.faceBlock(collision.getPos());
            currentMlgRotation.getRotation().toPlayer(mc.thePlayer);
        }
    } else if (currentMlgRotation != null) {
        ItemStack stack = mc.thePlayer.inventoryContainer.getSlot(currentMlgItemIndex + 36).getStack();

        if (stack.getItem() instanceof ItemBucket) {
            mc.playerController.sendUseItem(mc.thePlayer, mc.theWorld, stack);
        } else {
            Vec3i dirVec = EnumFacing.UP.getDirectionVec();

            if (mc.playerController.onPlayerRightClick(mc.thePlayer, mc.theWorld, stack, currentMlgBlock, EnumFacing.UP, new Vec3(dirVec.getX() * 0.5, dirVec.getY() * 0.5, dirVec.getZ() * 0.5).add(new Vec3(currentMlgBlock)))) {
                mlgTimer.reset();
            }
        }

        if (mc.thePlayer.inventory.currentItem != currentMlgItemIndex)
            mc.thePlayer.sendQueue.addToSendQueue(new C09PacketHeldItemChange(mc.thePlayer.inventory.currentItem));
    }
}