Search in sources :

Example 6 with ItemBucket

use of net.minecraft.item.ItemBucket in project MinecraftForge by MinecraftForge.

the class ForgeHooks method onPlaceItemIntoWorld.

public static EnumActionResult onPlaceItemIntoWorld(@Nonnull ItemStack itemstack, @Nonnull EntityPlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull EnumFacing side, float hitX, float hitY, float hitZ, @Nonnull EnumHand hand) {
    // handle all placement events here
    int meta = itemstack.getItemDamage();
    int size = itemstack.getCount();
    NBTTagCompound nbt = null;
    if (itemstack.getTagCompound() != null) {
        nbt = (NBTTagCompound) itemstack.getTagCompound().copy();
    }
    if (// if not bucket
    !(itemstack.getItem() instanceof ItemBucket)) {
        world.captureBlockSnapshots = true;
    }
    EnumActionResult ret = itemstack.getItem().onItemUse(player, world, pos, hand, side, hitX, hitY, hitZ);
    world.captureBlockSnapshots = false;
    if (ret == EnumActionResult.SUCCESS) {
        // save new item data
        int newMeta = itemstack.getItemDamage();
        int newSize = itemstack.getCount();
        NBTTagCompound newNBT = null;
        if (itemstack.getTagCompound() != null) {
            newNBT = (NBTTagCompound) itemstack.getTagCompound().copy();
        }
        net.minecraftforge.event.world.BlockEvent.PlaceEvent placeEvent = null;
        @SuppressWarnings("unchecked") List<net.minecraftforge.common.util.BlockSnapshot> blockSnapshots = (List<BlockSnapshot>) world.capturedBlockSnapshots.clone();
        world.capturedBlockSnapshots.clear();
        // make sure to set pre-placement item data for event
        itemstack.setItemDamage(meta);
        itemstack.setCount(size);
        if (nbt != null) {
            itemstack.setTagCompound(nbt);
        }
        if (blockSnapshots.size() > 1) {
            placeEvent = ForgeEventFactory.onPlayerMultiBlockPlace(player, blockSnapshots, side, hand);
        } else if (blockSnapshots.size() == 1) {
            placeEvent = ForgeEventFactory.onPlayerBlockPlace(player, blockSnapshots.get(0), side, hand);
        }
        if (placeEvent != null && (placeEvent.isCanceled())) {
            // cancel placement
            ret = EnumActionResult.FAIL;
            // revert back all captured blocks
            for (net.minecraftforge.common.util.BlockSnapshot blocksnapshot : blockSnapshots) {
                world.restoringBlockSnapshots = true;
                blocksnapshot.restore(true, false);
                world.restoringBlockSnapshots = false;
            }
        } else {
            // Change the stack to its new content
            itemstack.setItemDamage(newMeta);
            itemstack.setCount(newSize);
            if (nbt != null) {
                itemstack.setTagCompound(newNBT);
            }
            for (BlockSnapshot snap : blockSnapshots) {
                int updateFlag = snap.getFlag();
                IBlockState oldBlock = snap.getReplacedBlock();
                IBlockState newBlock = world.getBlockState(snap.getPos());
                if (// Containers get placed automatically
                !newBlock.getBlock().hasTileEntity(newBlock)) {
                    newBlock.getBlock().onBlockAdded(world, snap.getPos(), newBlock);
                }
                world.markAndNotifyBlock(snap.getPos(), null, oldBlock, newBlock, updateFlag);
            }
            player.addStat(StatList.getObjectUseStats(itemstack.getItem()));
        }
    }
    world.capturedBlockSnapshots.clear();
    return ret;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) BlockSnapshot(net.minecraftforge.common.util.BlockSnapshot) BlockSnapshot(net.minecraftforge.common.util.BlockSnapshot) ItemBucket(net.minecraft.item.ItemBucket) EnumActionResult(net.minecraft.util.EnumActionResult) NonNullList(net.minecraft.util.NonNullList) ArrayList(java.util.ArrayList) StatList(net.minecraft.stats.StatList) List(java.util.List) NoteBlockEvent(net.minecraftforge.event.world.NoteBlockEvent) BlockEvent(net.minecraftforge.event.world.BlockEvent)

Example 7 with ItemBucket

use of net.minecraft.item.ItemBucket in project Trains-In-Motion-1.7.10 by EternalBlueFlame.

the class CommonProxy method register.

/**
     * <h2>Server Register</h2>
     * Used for registering server only functions.
     * Also serves as a placeholder for the client function, which is actually used, so we don't get a missing function error.
     */
public void register() {
    //register fluids
    FluidRegistry.registerFluid(fluidOil);
    FluidRegistry.registerFluid(fluidDiesel);
    //register fluid blocks
    blockFluidOil = new BlockTrainFluid(fluidOil, new MaterialLiquid(MapColor.blackColor));
    blockFluidOil.setBlockName("block.oil");
    GameRegistry.registerBlock(blockFluidOil, "block.oil");
    blockFluidDiesel = new BlockTrainFluid(fluidDiesel, new MaterialLiquid(MapColor.dirtColor)).setFlammable(true, 1);
    blockFluidDiesel.setBlockName("block.diesel");
    GameRegistry.registerBlock(blockFluidDiesel, "block.diesel");
    //register the buckets
    bucketOil = new ItemBucket(blockFluidOil);
    bucketOil.setCreativeTab(TrainsInMotion.creativeTab).setUnlocalizedName("item.oilbucket").setContainerItem(Items.bucket);
    GameRegistry.registerItem(bucketOil, "fluid.oil.bucket");
    FluidContainerRegistry.registerFluidContainer(fluidOil, new ItemStack(bucketOil), new ItemStack(Items.bucket));
    bucketDiesel = new ItemBucket(blockFluidDiesel);
    bucketDiesel.setCreativeTab(TrainsInMotion.creativeTab).setUnlocalizedName("item.dieselbucket").setContainerItem(Items.bucket);
    GameRegistry.registerItem(bucketDiesel, "fluid.diesel.bucket");
    FluidContainerRegistry.registerFluidContainer(fluidDiesel, new ItemStack(bucketDiesel), new ItemStack(Items.bucket));
    //register the train crafting table
    GameRegistry.registerBlock(trainTable, "TrainTable");
    GameRegistry.registerTileEntity(TileEntityStorage.class, "StorageEntity");
    addRecipe(new ItemStack(trainTable, 1), "WWW", "WIW", "WWW", 'W', Blocks.planks, 'I', Items.iron_ingot);
    railBlock.setCreativeTab(TrainsInMotion.creativeTab);
    GameRegistry.registerBlock(railBlock, "TiMRail");
    addRecipe(new ItemStack(railBlock, 1), "I I", "IWI", "IWI", 'W', Blocks.planks, 'I', Items.iron_ingot);
}
Also used : MaterialLiquid(net.minecraft.block.material.MaterialLiquid) ItemStack(net.minecraft.item.ItemStack) ItemBucket(net.minecraft.item.ItemBucket) BlockTrainFluid(ebf.tim.blocks.BlockTrainFluid)

Example 8 with ItemBucket

use of net.minecraft.item.ItemBucket in project BuildCraft by BuildCraft.

the class StripesHandlerBucket method handle.

@Override
public boolean handle(World world, BlockPos pos, EnumFacing direction, ItemStack stack, EntityPlayer player, IStripesActivator activator) {
    if (world.isAirBlock(pos)) {
        BlockPos place = new BlockPos(pos.getX(), direction.ordinal() < 2 ? pos.getY() : (pos.getY() - 1), pos.getZ());
        if (((ItemBucket) stack.getItem()).tryPlaceContainedLiquid(world, place)) {
            activator.sendItem(emptyBucket, direction.getOpposite());
            stack.stackSize--;
            if (stack.stackSize > 0) {
                activator.sendItem(stack, direction.getOpposite());
            }
            return true;
        }
    }
    if (!FluidContainerRegistry.isEmptyContainer(stack)) {
        activator.sendItem(stack, direction.getOpposite());
        return true;
    }
    IBlockState targetBlock = world.getBlockState(pos);
    FluidStack fluidStack = BlockUtil.drainBlock(targetBlock, world, pos, true);
    if (fluidStack == null) {
        targetBlock = world.getBlockState(pos.down());
        fluidStack = BlockUtil.drainBlock(targetBlock, world, pos.down(), true);
    }
    ItemStack filledBucket = getFilledBucket(fluidStack, targetBlock.getBlock());
    if (fluidStack == null || filledBucket == null) {
        activator.sendItem(stack, direction.getOpposite());
        return true;
    }
    activator.sendItem(filledBucket, direction.getOpposite());
    stack.stackSize--;
    if (stack.stackSize > 0) {
        activator.sendItem(stack, direction.getOpposite());
    }
    return true;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) FluidStack(net.minecraftforge.fluids.FluidStack) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) ItemBucket(net.minecraft.item.ItemBucket)

Example 9 with ItemBucket

use of net.minecraft.item.ItemBucket in project PneumaticCraft by MineMaarten.

the class Fluids method initializeFluidBlocksAndBuckets.

private static void initializeFluidBlocksAndBuckets() {
    for (final Fluid fluid : fluids) {
        // FluidRegistry.registerFluid(fluid); (The constructor of FluidPneumaticCrafts registers the fluid.
        Block fluidBlock = fluid.getBlock();
        Blockss.registerBlock(fluidBlock);
        fluidToBlockMap.put(fluid.getName(), fluidBlock);
        Item fluidBucket = new ItemBucket(fluidBlock) {

            @Override
            public void addInformation(ItemStack p_77624_1_, net.minecraft.entity.player.EntityPlayer p_77624_2_, List p_77624_3_, boolean p_77624_4_) {
                super.addInformation(p_77624_1_, p_77624_2_, p_77624_3_, p_77624_4_);
                ItemPneumatic.addTooltip(p_77624_1_, p_77624_2_, p_77624_3_);
            }

            @Override
            @SideOnly(Side.CLIENT)
            public void getSubItems(Item item, CreativeTabs creativeTab, List items) {
                if (FluidRegistry.isFluidDefault(fluid))
                    super.getSubItems(item, creativeTab, items);
            }
        }.setContainerItem(Items.bucket).setCreativeTab(PneumaticCraft.tabPneumaticCraft).setTextureName(Textures.ICON_LOCATION + fluid.getName() + "Bucket").setUnlocalizedName(fluid.getName() + "Bucket");
        Itemss.registerItem(fluidBucket);
        fluidBlockToBucketMap.put(fluidBlock, fluidBucket);
        FluidContainerRegistry.registerFluidContainer(new FluidStack(fluid, 1000), new ItemStack(fluidBucket), new ItemStack(Items.bucket));
    }
}
Also used : Item(net.minecraft.item.Item) FluidStack(net.minecraftforge.fluids.FluidStack) Fluid(net.minecraftforge.fluids.Fluid) Block(net.minecraft.block.Block) ArrayList(java.util.ArrayList) List(java.util.List) CreativeTabs(net.minecraft.creativetab.CreativeTabs) ItemStack(net.minecraft.item.ItemStack) ItemBucket(net.minecraft.item.ItemBucket)

Example 10 with ItemBucket

use of net.minecraft.item.ItemBucket in project ForestryMC by ForestryMC.

the class LiquidHelper method injectLiquidContainer.

public static void injectLiquidContainer(Fluids fluid, ItemStack filled) {
    Item item = filled.getItem();
    if (item.getContainerItem() instanceof ItemBucket) {
        LiquidHelper.injectLiquidContainer(fluid, Defaults.BUCKET_VOLUME, filled, new ItemStack(Items.bucket));
        return;
    } else if (item instanceof ItemLiquidContainer) {
        ItemLiquidContainer liquidContainer = (ItemLiquidContainer) item;
        switch(liquidContainer.getType()) {
            case CAN:
                LiquidHelper.injectTinContainer(fluid, Defaults.BUCKET_VOLUME, filled, ForestryItem.canEmpty.getItemStack());
                return;
            case CAPSULE:
                LiquidHelper.injectWaxContainer(fluid, Defaults.BUCKET_VOLUME, filled, ForestryItem.waxCapsule.getItemStack());
                return;
            case REFRACTORY:
                LiquidHelper.injectRefractoryContainer(fluid, Defaults.BUCKET_VOLUME, filled, ForestryItem.refractoryEmpty.getItemStack());
                return;
        }
    }
    Proxies.log.warning("Unable to inject liquid container: " + filled);
}
Also used : Item(net.minecraft.item.Item) ForestryItem(forestry.core.config.ForestryItem) ItemLiquidContainer(forestry.core.items.ItemLiquidContainer) ItemStack(net.minecraft.item.ItemStack) ItemBucket(net.minecraft.item.ItemBucket)

Aggregations

ItemBucket (net.minecraft.item.ItemBucket)10 ItemStack (net.minecraft.item.ItemStack)6 Item (net.minecraft.item.Item)4 IBlockState (net.minecraft.block.state.IBlockState)3 FluidStack (net.minecraftforge.fluids.FluidStack)3 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)3 PhysicsWrapperEntity (ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Block (net.minecraft.block.Block)2 BlockPos (net.minecraft.util.math.BlockPos)2 BlockTrainFluid (ebf.tim.blocks.BlockTrainFluid)1 ForestryItem (forestry.core.config.ForestryItem)1 ItemLiquidContainer (forestry.core.items.ItemLiquidContainer)1 BlockLiquid (net.minecraft.block.BlockLiquid)1 MaterialLiquid (net.minecraft.block.material.MaterialLiquid)1 CreativeTabs (net.minecraft.creativetab.CreativeTabs)1 ItemDoor (net.minecraft.item.ItemDoor)1 ItemHoe (net.minecraft.item.ItemHoe)1 ItemSpade (net.minecraft.item.ItemSpade)1