コード例 #1
0
        /// <summary>
        /// Called whenever the block is removed.
        /// </summary>
        public override void OnBlockRemoval(World par1World, int par2, int par3, int par4)
        {
            TileEntityDispenser tileentitydispenser = (TileEntityDispenser)par1World.GetBlockTileEntity(par2, par3, par4);

            if (tileentitydispenser != null)
            {
label0:

                for (int i = 0; i < tileentitydispenser.GetSizeInventory(); i++)
                {
                    ItemStack itemstack = tileentitydispenser.GetStackInSlot(i);

                    if (itemstack == null)
                    {
                        continue;
                    }

                    float f  = Random.NextFloat() * 0.8F + 0.1F;
                    float f1 = Random.NextFloat() * 0.8F + 0.1F;
                    float f2 = Random.NextFloat() * 0.8F + 0.1F;

                    do
                    {
                        if (itemstack.StackSize <= 0)
                        {
                            goto label0;
                        }

                        int j = Random.Next(21) + 10;

                        if (j > itemstack.StackSize)
                        {
                            j = itemstack.StackSize;
                        }

                        itemstack.StackSize -= j;
                        EntityItem entityitem = new EntityItem(par1World, (float)par2 + f, (float)par3 + f1, (float)par4 + f2, new ItemStack(itemstack.ItemID, j, itemstack.GetItemDamage()));

                        if (itemstack.HasTagCompound())
                        {
                            entityitem.ItemStack.SetTagCompound((NBTTagCompound)itemstack.GetTagCompound().Copy());
                        }

                        float f3 = 0.05F;
                        entityitem.MotionX = (float)Random.NextGaussian() * f3;
                        entityitem.MotionY = (float)Random.NextGaussian() * f3 + 0.2F;
                        entityitem.MotionZ = (float)Random.NextGaussian() * f3;
                        par1World.SpawnEntityInWorld(entityitem);
                    }while (true);
                }
            }

            base.OnBlockRemoval(par1World, par2, par3, par4);
        }
コード例 #2
0
        /// <summary>
        /// Called upon block activation (left or right click on the block.). The three integers represent x,y,z of the
        /// block.
        /// </summary>
        public override bool BlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer)
        {
            if (par1World.IsRemote)
            {
                return(true);
            }

            TileEntityDispenser tileentitydispenser = (TileEntityDispenser)par1World.GetBlockTileEntity(par2, par3, par4);

            if (tileentitydispenser != null)
            {
                par5EntityPlayer.DisplayGUIDispenser(tileentitydispenser);
            }

            return(true);
        }
コード例 #3
0
 /// <summary>
 /// Displays the dipsenser GUI for the passed in dispenser entity. Args: TileEntityDispenser
 /// </summary>
 public override void DisplayGUIDispenser(TileEntityDispenser par1TileEntityDispenser)
 {
     Mc.DisplayGuiScreen(new GuiDispenser(Inventory, par1TileEntityDispenser));
 }
コード例 #4
0
 public GuiDispenser(InventoryPlayer par1InventoryPlayer, TileEntityDispenser par2TileEntityDispenser) : base(new ContainerDispenser(par1InventoryPlayer, par2TileEntityDispenser))
 {
 }
コード例 #5
0
        /// <summary>
        /// dispenses an item from a randomly selected item stack from the blocks inventory into the game world.
        /// </summary>
        private void DispenseItem(World par1World, int par2, int par3, int par4, Random par5Random)
        {
            int i = par1World.GetBlockMetadata(par2, par3, par4);
            int j = 0;
            int k = 0;

            if (i == 3)
            {
                k = 1;
            }
            else if (i == 2)
            {
                k = -1;
            }
            else if (i == 5)
            {
                j = 1;
            }
            else
            {
                j = -1;
            }

            TileEntityDispenser tileentitydispenser = (TileEntityDispenser)par1World.GetBlockTileEntity(par2, par3, par4);

            if (tileentitydispenser != null)
            {
                ItemStack itemstack = tileentitydispenser.GetRandomStackFromInventory();
                float     d         = par2 + j * 0.59999999999999998F + 0.5F;
                float     d1        = par3 + 0.5F;
                float     d2        = par4 + k * 0.59999999999999998F + 0.5F;

                if (itemstack == null)
                {
                    par1World.PlayAuxSFX(1001, par2, par3, par4, 0);
                }
                else
                {
                    if (itemstack.ItemID == Item.Arrow.ShiftedIndex)
                    {
                        EntityArrow entityarrow = new EntityArrow(par1World, d, d1, d2);
                        entityarrow.SetArrowHeading(j, 0.10000000149011612F, k, 1.1F, 6F);
                        entityarrow.DoesArrowBelongToPlayer = true;
                        par1World.SpawnEntityInWorld(entityarrow);
                        par1World.PlayAuxSFX(1002, par2, par3, par4, 0);
                    }
                    else if (itemstack.ItemID == Item.Egg.ShiftedIndex)
                    {
                        EntityEgg entityegg = new EntityEgg(par1World, d, d1, d2);
                        entityegg.SetThrowableHeading(j, 0.10000000149011612F, k, 1.1F, 6F);
                        par1World.SpawnEntityInWorld(entityegg);
                        par1World.PlayAuxSFX(1002, par2, par3, par4, 0);
                    }
                    else if (itemstack.ItemID == Item.Snowball.ShiftedIndex)
                    {
                        EntitySnowball entitysnowball = new EntitySnowball(par1World, d, d1, d2);
                        entitysnowball.SetThrowableHeading(j, 0.10000000149011612F, k, 1.1F, 6F);
                        par1World.SpawnEntityInWorld(entitysnowball);
                        par1World.PlayAuxSFX(1002, par2, par3, par4, 0);
                    }
                    else if (itemstack.ItemID == Item.Potion.ShiftedIndex && ItemPotion.IsSplash(itemstack.GetItemDamage()))
                    {
                        EntityPotion entitypotion = new EntityPotion(par1World, d, d1, d2, itemstack.GetItemDamage());
                        entitypotion.SetThrowableHeading(j, 0.10000000149011612F, k, 1.375F, 3F);
                        par1World.SpawnEntityInWorld(entitypotion);
                        par1World.PlayAuxSFX(1002, par2, par3, par4, 0);
                    }
                    else if (itemstack.ItemID == Item.ExpBottle.ShiftedIndex)
                    {
                        EntityExpBottle entityexpbottle = new EntityExpBottle(par1World, d, d1, d2);
                        entityexpbottle.SetThrowableHeading(j, 0.10000000149011612F, k, 1.375F, 3F);
                        par1World.SpawnEntityInWorld(entityexpbottle);
                        par1World.PlayAuxSFX(1002, par2, par3, par4, 0);
                    }
                    else if (itemstack.ItemID == Item.MonsterPlacer.ShiftedIndex)
                    {
                        ItemMonsterPlacer.Func_48440_a(par1World, itemstack.GetItemDamage(), d + j * 0.29999999999999999F, d1 - 0.29999999999999999F, d2 + k * 0.29999999999999999F);
                        par1World.PlayAuxSFX(1002, par2, par3, par4, 0);
                    }
                    else if (itemstack.ItemID == Item.FireballCharge.ShiftedIndex)
                    {
                        EntitySmallFireball entitysmallfireball = new EntitySmallFireball(par1World, d + j * 0.29999999999999999F, d1, d2 + k * 0.29999999999999999F, j + par5Random.NextGaussian() * 0.050000000000000003F, par5Random.NextGaussian() * 0.050000000000000003F, k + par5Random.NextGaussian() * 0.050000000000000003F);
                        par1World.SpawnEntityInWorld(entitysmallfireball);
                        par1World.PlayAuxSFX(1009, par2, par3, par4, 0);
                    }
                    else
                    {
                        EntityItem entityitem = new EntityItem(par1World, d, d1 - 0.29999999999999999F, d2, itemstack);
                        float      d3         = par5Random.NextFloat() * 0.10000000000000001F + 0.20000000000000001F;
                        entityitem.MotionX  = j * d3;
                        entityitem.MotionY  = 0.20000000298023224F;
                        entityitem.MotionZ  = k * d3;
                        entityitem.MotionX += par5Random.NextGaussian() * 0.0074999998323619366F * 6;
                        entityitem.MotionY += par5Random.NextGaussian() * 0.0074999998323619366F * 6;
                        entityitem.MotionZ += par5Random.NextGaussian() * 0.0074999998323619366F * 6;
                        par1World.SpawnEntityInWorld(entityitem);
                        par1World.PlayAuxSFX(1000, par2, par3, par4, 0);
                    }

                    par1World.PlayAuxSFX(2000, par2, par3, par4, j + 1 + (k + 1) * 3);
                }
            }
        }