Search in sources :

Example 1 with FillBucketEvent

use of net.minecraftforge.event.entity.player.FillBucketEvent in project SecurityCraft by Geforce132.

the class ItemModifiedBucket method onItemRightClick.

/**
     * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
     */
public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) {
    boolean flag = this.isFull == Blocks.air;
    MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(par2World, par3EntityPlayer, flag);
    if (movingobjectposition == null) {
        return par1ItemStack;
    } else {
        FillBucketEvent event = new FillBucketEvent(par3EntityPlayer, par1ItemStack, par2World, movingobjectposition);
        if (MinecraftForge.EVENT_BUS.post(event)) {
            return par1ItemStack;
        }
        if (event.getResult() == Event.Result.ALLOW) {
            if (par3EntityPlayer.capabilities.isCreativeMode) {
                return par1ItemStack;
            }
            if (--par1ItemStack.stackSize <= 0) {
                return event.result;
            }
            if (!par3EntityPlayer.inventory.addItemStackToInventory(event.result)) {
                par3EntityPlayer.dropPlayerItemWithRandomChoice(event.result, false);
            }
            return par1ItemStack;
        }
        if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) {
            int i = movingobjectposition.blockX;
            int j = movingobjectposition.blockY;
            int k = movingobjectposition.blockZ;
            if (!par2World.canMineBlock(par3EntityPlayer, i, j, k)) {
                return par1ItemStack;
            }
            if (flag) {
                if (!par3EntityPlayer.canPlayerEdit(i, j, k, movingobjectposition.sideHit, par1ItemStack)) {
                    return par1ItemStack;
                }
                Material material = par2World.getBlock(i, j, k).getMaterial();
                int l = par2World.getBlockMetadata(i, j, k);
                //if (material == Material.water && l == 0)
                if (material == Material.water && l == 0) {
                    par2World.setBlockToAir(i, j, k);
                    // return this.func_150910_a(par1ItemStack, par3EntityPlayer, mod_SecurityCraft.fWaterBucket);
                    return new ItemStack(mod_SecurityCraft.fWaterBucket, 1, 0);
                }
                if (material == Material.lava && l == 0) {
                    par2World.setBlockToAir(i, j, k);
                    //return this.func_150910_a(par1ItemStack, par3EntityPlayer, mod_SecurityCraft.fLavaBucket);
                    return new ItemStack(mod_SecurityCraft.fLavaBucket, 1, 0);
                }
            } else {
                if (this.isFull == Blocks.air) {
                    return new ItemStack(Items.bucket);
                }
                if (movingobjectposition.sideHit == 0) {
                    --j;
                }
                if (movingobjectposition.sideHit == 1) {
                    ++j;
                }
                if (movingobjectposition.sideHit == 2) {
                    --k;
                }
                if (movingobjectposition.sideHit == 3) {
                    ++k;
                }
                if (movingobjectposition.sideHit == 4) {
                    --i;
                }
                if (movingobjectposition.sideHit == 5) {
                    ++i;
                }
                if (!par3EntityPlayer.canPlayerEdit(i, j, k, movingobjectposition.sideHit, par1ItemStack)) {
                    return par1ItemStack;
                }
                if (this.tryPlaceContainedLiquid(par2World, i, j, k) && !par3EntityPlayer.capabilities.isCreativeMode) {
                    return new ItemStack(Items.bucket);
                }
            }
        }
        return par1ItemStack;
    }
}
Also used : MovingObjectPosition(net.minecraft.util.MovingObjectPosition) FillBucketEvent(net.minecraftforge.event.entity.player.FillBucketEvent) Material(net.minecraft.block.material.Material) ItemStack(net.minecraft.item.ItemStack)

Aggregations

Material (net.minecraft.block.material.Material)1 ItemStack (net.minecraft.item.ItemStack)1 MovingObjectPosition (net.minecraft.util.MovingObjectPosition)1 FillBucketEvent (net.minecraftforge.event.entity.player.FillBucketEvent)1