Search in sources :

Example 1 with IBlockSource

use of net.minecraft.dispenser.IBlockSource in project ICBM-Classic by BuiltBrokenModding.

the class ICBMClassic method init.

@EventHandler
public void init(FMLInitializationEvent event) {
    super.init(event);
    Settings.setModMetadata(ICBMClassic.DOMAIN, "ICBM-Classic", metadata);
    OreDictionary.registerOre("dustSulfur", new ItemStack(itemSulfurDust, 1, 0));
    OreDictionary.registerOre("dustSaltpeter", new ItemStack(itemSulfurDust, 1, 1));
    /** Check for existence of radioactive block. If it does not exist, then create it. */
    if (OreDictionary.getOres("blockRadioactive").size() > 0) {
        ArrayList<ItemStack> stacks = OreDictionary.getOres("blockRadioactive");
        for (ItemStack stack : stacks) {
            if (stack != null && stack.getItem() instanceof ItemBlock) {
                //TODO add code to handle this from the ItemStack or test if this block is valid
                //      As assuming the metadata is valid may not be a good idea, and the block may not be valid as well
                //TODO add config to force block that is used
                //TODO add error checking
                blockRadioactive = ((ItemBlock) stack.getItem()).field_150939_a;
                blockRadioactiveMeta = ((ItemBlock) stack.getItem()).getMetadata(stack.getItemDamage());
                logger().info("Detected radioative block from another mod.");
                logger().info("Radioactive explosives will use: " + blockRadioactive);
            }
        }
    }
    if (blockRadioactive == null) {
        blockRadioactive = Blocks.mycelium;
    }
    /** Potion Effects */
    PoisonToxin.INSTANCE = new PoisonToxin(true, 5149489, "toxin");
    PoisonContagion.INSTANCE = new PoisonContagion(false, 5149489, "virus");
    PoisonFrostBite.INSTANCE = new PoisonFrostBite(false, 5149489, "frostBite");
    /** Dispenser Handler */
    BlockDispenser.dispenseBehaviorRegistry.putObject(itemGrenade, new IBehaviorDispenseItem() {

        @Override
        public ItemStack dispense(IBlockSource blockSource, ItemStack itemStack) {
            World world = blockSource.getWorld();
            if (!world.isRemote) {
                int x = blockSource.getXInt();
                int y = blockSource.getYInt();
                int z = blockSource.getZInt();
                EnumFacing enumFacing = EnumFacing.getFront(blockSource.getBlockMetadata());
                EntityGrenade entity = new EntityGrenade(world, new Pos(x, y, z), Explosives.get(itemStack.getItemDamage()));
                entity.setThrowableHeading(enumFacing.getFrontOffsetX(), 0.10000000149011612D, enumFacing.getFrontOffsetZ(), 0.5F, 1.0F);
                world.spawnEntityInWorld(entity);
            }
            itemStack.stackSize--;
            return itemStack;
        }
    });
    BlockDispenser.dispenseBehaviorRegistry.putObject(itemBombCart, new IBehaviorDispenseItem() {

        private final BehaviorDefaultDispenseItem defaultItemDispenseBehavior = new BehaviorDefaultDispenseItem();

        @Override
        public ItemStack dispense(IBlockSource blockSource, ItemStack itemStack) {
            World world = blockSource.getWorld();
            if (!world.isRemote) {
                int x = blockSource.getXInt();
                int y = blockSource.getYInt();
                int z = blockSource.getZInt();
                EnumFacing var3 = EnumFacing.getFront(blockSource.getBlockMetadata());
                World var4 = blockSource.getWorld();
                double var5 = blockSource.getX() + var3.getFrontOffsetX() * 1.125F;
                double var7 = blockSource.getY();
                double var9 = blockSource.getZ() + var3.getFrontOffsetZ() * 1.125F;
                int var11 = blockSource.getXInt() + var3.getFrontOffsetX();
                int var12 = blockSource.getYInt();
                int var13 = blockSource.getZInt() + var3.getFrontOffsetZ();
                Block var14 = var4.getBlock(var11, var12, var13);
                double var15;
                if (BlockRailBase.func_150051_a(var14)) {
                    var15 = 0.0D;
                } else {
                    if (var14 == Blocks.air || !BlockRailBase.func_150051_a(var4.getBlock(var11, var12 - 1, var13))) {
                        return this.defaultItemDispenseBehavior.dispense(blockSource, itemStack);
                    }
                    var15 = -1.0D;
                }
                EntityBombCart var22 = new EntityBombCart(world, var5, var7 + var15, var9, Explosives.get(itemStack.getItemDamage()));
                world.spawnEntityInWorld(var22);
                world.playAuxSFX(1000, x, y, z, 0);
            }
            itemStack.stackSize--;
            return itemStack;
        }
    });
    proxy.init();
}
Also used : IBehaviorDispenseItem(net.minecraft.dispenser.IBehaviorDispenseItem) EnumFacing(net.minecraft.util.EnumFacing) ItemBlock(net.minecraft.item.ItemBlock) World(net.minecraft.world.World) BehaviorDefaultDispenseItem(net.minecraft.dispenser.BehaviorDefaultDispenseItem) IBlockSource(net.minecraft.dispenser.IBlockSource) Pos(com.builtbroken.mc.imp.transform.vector.Pos) PoisonContagion(icbm.classic.content.potion.PoisonContagion) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) PoisonFrostBite(icbm.classic.content.potion.PoisonFrostBite) ItemStack(net.minecraft.item.ItemStack) PoisonToxin(icbm.classic.content.potion.PoisonToxin) EventHandler(cpw.mods.fml.common.Mod.EventHandler)

Aggregations

Pos (com.builtbroken.mc.imp.transform.vector.Pos)1 EventHandler (cpw.mods.fml.common.Mod.EventHandler)1 PoisonContagion (icbm.classic.content.potion.PoisonContagion)1 PoisonFrostBite (icbm.classic.content.potion.PoisonFrostBite)1 PoisonToxin (icbm.classic.content.potion.PoisonToxin)1 Block (net.minecraft.block.Block)1 BehaviorDefaultDispenseItem (net.minecraft.dispenser.BehaviorDefaultDispenseItem)1 IBehaviorDispenseItem (net.minecraft.dispenser.IBehaviorDispenseItem)1 IBlockSource (net.minecraft.dispenser.IBlockSource)1 ItemBlock (net.minecraft.item.ItemBlock)1 ItemStack (net.minecraft.item.ItemStack)1 EnumFacing (net.minecraft.util.EnumFacing)1 World (net.minecraft.world.World)1