/// <summary> /// Drops the block items with a specified chance of dropping the specified items /// </summary> public override void DropBlockAsItemWithChance(World par1World, int par2, int par3, int par4, int par5, float par6, int par7) { base.DropBlockAsItemWithChance(par1World, par2, par3, par4, par5, par6, 0); if (par1World.IsRemote) { return; } int i = 3 + par7; for (int j = 0; j < i; j++) { if (par1World.Rand.Next(15) <= par5) { float f = 0.7F; float f1 = par1World.Rand.NextFloat() * f + (1.0F - f) * 0.5F; float f2 = par1World.Rand.NextFloat() * f + (1.0F - f) * 0.5F; float f3 = par1World.Rand.NextFloat() * f + (1.0F - f) * 0.5F; EntityItem entityitem = new EntityItem(par1World, (float)par2 + f1, (float)par3 + f2, (float)par4 + f3, new ItemStack(Item.Seeds)); entityitem.DelayBeforeCanPickup = 10; par1World.SpawnEntityInWorld(entityitem); } } }
/// <summary> /// Drops the block items with a specified chance of dropping the specified items /// </summary> public override void DropBlockAsItemWithChance(World par1World, int par2, int par3, int par4, int par5, float par6, int par7) { base.DropBlockAsItemWithChance(par1World, par2, par3, par4, par5, par6, par7); if (par1World.IsRemote) { return; } Item item = null; if (FruitType == Block.Pumpkin) { item = Item.PumpkinSeeds; } if (FruitType == Block.Melon) { item = Item.MelonSeeds; } for (int i = 0; i < 3; i++) { if (par1World.Rand.Next(15) <= par5) { float f = 0.7F; float f1 = par1World.Rand.NextFloat() * f + (1.0F - f) * 0.5F; float f2 = par1World.Rand.NextFloat() * f + (1.0F - f) * 0.5F; float f3 = par1World.Rand.NextFloat() * f + (1.0F - f) * 0.5F; EntityItem entityitem = new EntityItem(par1World, (float)par2 + f1, (float)par3 + f2, (float)par4 + f3, new ItemStack(item)); entityitem.DelayBeforeCanPickup = 10; par1World.SpawnEntityInWorld(entityitem); } } }
/// <summary> /// Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig. /// </summary> public override bool Interact(EntityPlayer par1EntityPlayer) { ItemStack itemstack = par1EntityPlayer.Inventory.GetCurrentItem(); if (itemstack != null && itemstack.ItemID == Item.Shears.ShiftedIndex && !GetSheared() && !IsChild()) { if (!WorldObj.IsRemote) { SetSheared(true); int i = 1 + Rand.Next(3); for (int j = 0; j < i; j++) { EntityItem entityitem = EntityDropItem(new ItemStack(Block.Cloth.BlockID, 1, GetFleeceColor()), 1.0F); entityitem.MotionY += Rand.NextFloat() * 0.05F; entityitem.MotionX += (Rand.NextFloat() - Rand.NextFloat()) * 0.1F; entityitem.MotionZ += (Rand.NextFloat() - Rand.NextFloat()) * 0.1F; } } itemstack.DamageItem(1, par1EntityPlayer); } return(base.Interact(par1EntityPlayer)); }
/// <summary> /// Called whenever the block is removed. /// </summary> public override void OnBlockRemoval(World par1World, int par2, int par3, int par4) { if (!KeepFurnaceInventory) { TileEntityFurnace tileentityfurnace = (TileEntityFurnace)par1World.GetBlockTileEntity(par2, par3, par4); if (tileentityfurnace != null) { label0: for (int i = 0; i < tileentityfurnace.GetSizeInventory(); i++) { ItemStack itemstack = tileentityfurnace.GetStackInSlot(i); if (itemstack == null) { continue; } float f = FurnaceRand.NextFloat() * 0.8F + 0.1F; float f1 = FurnaceRand.NextFloat() * 0.8F + 0.1F; float f2 = FurnaceRand.NextFloat() * 0.8F + 0.1F; do { if (itemstack.StackSize <= 0) { goto label0; } int j = FurnaceRand.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)FurnaceRand.NextGaussian() * f3; entityitem.MotionY = (float)FurnaceRand.NextGaussian() * f3 + 0.2F; entityitem.MotionZ = (float)FurnaceRand.NextGaussian() * f3; par1World.SpawnEntityInWorld(entityitem); }while (true); } } } base.OnBlockRemoval(par1World, par2, par3, par4); }
public Packet21PickupSpawn(EntityItem par1EntityItem) { EntityId = par1EntityItem.EntityId; ItemID = par1EntityItem.ItemStack.ItemID; Count = par1EntityItem.ItemStack.StackSize; ItemDamage = par1EntityItem.ItemStack.GetItemDamage(); XPosition = MathHelper2.Floor_double(par1EntityItem.PosX * 32D); YPosition = MathHelper2.Floor_double(par1EntityItem.PosY * 32D); ZPosition = MathHelper2.Floor_double(par1EntityItem.PosZ * 32D); Rotation = (sbyte)(int)(par1EntityItem.MotionX * 128D); Pitch = (sbyte)(int)(par1EntityItem.MotionY * 128D); Roll = (sbyte)(int)(par1EntityItem.MotionZ * 128D); }
/// <summary> /// Called when the player destroys a block with an item that can harvest it. (i, j, k) are the coordinates of the /// block and l is the block's subtype/damage. /// </summary> public override void HarvestBlock(World par1World, EntityPlayer par2EntityPlayer, int par3, int par4, int par5, int par6) { int i = Item.Snowball.ShiftedIndex; float f = 0.7F; float d = (par1World.Rand.NextFloat() * f) + (1.0F - f) * 0.5F; float d1 = (par1World.Rand.NextFloat() * f) + (1.0F - f) * 0.5F; float d2 = (par1World.Rand.NextFloat() * f) + (1.0F - f) * 0.5F; EntityItem entityitem = new EntityItem(par1World, par3 + d, par4 + d1, par5 + d2, new ItemStack(i, 1, 0)); entityitem.DelayBeforeCanPickup = 10; par1World.SpawnEntityInWorld(entityitem); par1World.SetBlockWithNotify(par3, par4, par5, 0); par2EntityPlayer.AddStat(StatList.MineBlockStatArray[BlockID], 1); }
/// <summary> /// Called whenever the block is removed. /// </summary> public override void OnBlockRemoval(World par1World, int par2, int par3, int par4) { TileEntity tileentity = par1World.GetBlockTileEntity(par2, par3, par4); if (tileentity != null && (tileentity is TileEntityBrewingStand)) { TileEntityBrewingStand tileentitybrewingstand = (TileEntityBrewingStand)tileentity; label0: for (int i = 0; i < tileentitybrewingstand.GetSizeInventory(); i++) { ItemStack itemstack = tileentitybrewingstand.GetStackInSlot(i); if (itemstack == null) { continue; } float f = Rand.NextFloat() * 0.8F + 0.1F; float f1 = Rand.NextFloat() * 0.8F + 0.1F; float f2 = Rand.NextFloat() * 0.8F + 0.1F; do { if (itemstack.StackSize <= 0) { goto label0; } int j = Rand.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())); float f3 = 0.05F; entityitem.MotionX = (float)Rand.NextGaussian() * f3; entityitem.MotionY = (float)Rand.NextGaussian() * f3 + 0.2F; entityitem.MotionZ = (float)Rand.NextGaussian() * f3; par1World.SpawnEntityInWorld(entityitem); }while (true); } } base.OnBlockRemoval(par1World, par2, par3, par4); }
/// <summary> /// Will get destroyed next tick. /// </summary> public override void SetDead() { label0: for (int i = 0; i < GetSizeInventory(); i++) { ItemStack itemstack = GetStackInSlot(i); if (itemstack == null) { continue; } float f = Rand.NextFloat() * 0.8F + 0.1F; float f1 = Rand.NextFloat() * 0.8F + 0.1F; float f2 = Rand.NextFloat() * 0.8F + 0.1F; do { if (itemstack.StackSize <= 0) { goto label0; } int j = Rand.Next(21) + 10; if (j > itemstack.StackSize) { j = itemstack.StackSize; } itemstack.StackSize -= j; EntityItem entityitem = new EntityItem(WorldObj, PosX + f, PosY + f1, PosZ + 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)Rand.NextGaussian() * f3; entityitem.MotionY = (float)Rand.NextGaussian() * f3 + 0.2F; entityitem.MotionZ = (float)Rand.NextGaussian() * f3; WorldObj.SpawnEntityInWorld(entityitem); }while (true); } base.SetDead(); }
public override void HandlePickupSpawn(Packet21PickupSpawn par1Packet21PickupSpawn) { float d = par1Packet21PickupSpawn.XPosition / 32F; float d1 = par1Packet21PickupSpawn.YPosition / 3F; float d2 = par1Packet21PickupSpawn.ZPosition / 3F; EntityItem entityitem = new EntityItem(WorldClient, d, d1, d2, new ItemStack(par1Packet21PickupSpawn.ItemID, par1Packet21PickupSpawn.Count, par1Packet21PickupSpawn.ItemDamage)); entityitem.MotionX = par1Packet21PickupSpawn.Rotation / 128F; entityitem.MotionY = par1Packet21PickupSpawn.Pitch / 128F; entityitem.MotionZ = par1Packet21PickupSpawn.Roll / 128F; entityitem.ServerPosX = par1Packet21PickupSpawn.XPosition; entityitem.ServerPosY = par1Packet21PickupSpawn.YPosition; entityitem.ServerPosZ = par1Packet21PickupSpawn.ZPosition; WorldClient.AddEntityToWorld(par1Packet21PickupSpawn.EntityId, entityitem); }
/// <summary> /// Called whenever the block is removed. /// </summary> public override void OnBlockRemoval(World par1World, int par2, int par3, int par4) { TileEntityChest tileentitychest = (TileEntityChest)par1World.GetBlockTileEntity(par2, par3, par4); if (tileentitychest != null) { for (int i = 0; i < tileentitychest.GetSizeInventory(); i++) { ItemStack itemstack = tileentitychest.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; while (itemstack.StackSize > 0) { 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())); float f3 = 0.05F; entityitem.MotionX = (float)Random.NextGaussian() * f3; entityitem.MotionY = (float)Random.NextGaussian() * f3 + 0.2F; entityitem.MotionZ = (float)Random.NextGaussian() * f3; if (itemstack.HasTagCompound()) { entityitem.ItemStack.SetTagCompound((NBTTagCompound)itemstack.GetTagCompound().Copy()); } par1World.SpawnEntityInWorld(entityitem); } } } base.OnBlockRemoval(par1World, par2, par3, par4); }
public virtual int CatchFish() { byte byte0 = 0; if (Bobber != null) { float d = Angler.PosX - PosX; float d2 = Angler.PosY - PosY; float d4 = Angler.PosZ - PosZ; double d6 = MathHelper2.Sqrt_double(d * d + d2 * d2 + d4 * d4); float d8 = 0.10000000000000001F; Bobber.MotionX += d * d8; Bobber.MotionY += d2 * d8 + MathHelper2.Sqrt_double(d6) * 0.080000000000000002F; Bobber.MotionZ += d4 * d8; byte0 = 3; } else if (TicksCatchable > 0) { EntityItem entityitem = new EntityItem(WorldObj, PosX, PosY, PosZ, new ItemStack(Item.FishRaw)); float d1 = Angler.PosX - PosX; float d3 = Angler.PosY - PosY; float d5 = Angler.PosZ - PosZ; double d7 = MathHelper2.Sqrt_double(d1 * d1 + d3 * d3 + d5 * d5); float d9 = 0.10000000000000001F; entityitem.MotionX = d1 * d9; entityitem.MotionY = d3 * d9 + MathHelper2.Sqrt_double(d7) * 0.080000000000000002F; entityitem.MotionZ = d5 * d9; WorldObj.SpawnEntityInWorld(entityitem); Angler.AddStat(StatList.FishCaughtStat, 1); byte0 = 1; } if (InGround) { byte0 = 2; } SetDead(); Angler.FishEntity = null; return(byte0); }
/// <summary> /// Called when the entity is attacked. /// </summary> public override bool AttackEntityFrom(DamageSource par1DamageSource, int par2) { if (WorldObj.IsRemote || IsDead) { return(true); } Func_41029_h(-Func_41030_m()); Func_41028_c(10); SetBeenAttacked(); Func_41024_b(Func_41025_i() + par2 * 10); if (Func_41025_i() > 40) { if (RiddenByEntity != null) { RiddenByEntity.MountEntity(this); } SetDead(); DropItemWithOffset(Item.MinecartEmpty.ShiftedIndex, 1, 0.0F); if (MinecartType == 1) { EntityMinecart entityminecart = this; label0: for (int i = 0; i < entityminecart.GetSizeInventory(); i++) { ItemStack itemstack = entityminecart.GetStackInSlot(i); if (itemstack == null) { continue; } float f = Rand.NextFloat() * 0.8F + 0.1F; float f1 = Rand.NextFloat() * 0.8F + 0.1F; float f2 = Rand.NextFloat() * 0.8F + 0.1F; do { if (itemstack.StackSize <= 0) { goto label0; } int j = Rand.Next(21) + 10; if (j > itemstack.StackSize) { j = itemstack.StackSize; } itemstack.StackSize -= j; EntityItem entityitem = new EntityItem(WorldObj, PosX + f, PosY + f1, PosZ + f2, new ItemStack(itemstack.ItemID, j, itemstack.GetItemDamage())); float f3 = 0.05F; entityitem.MotionX = (float)Rand.NextGaussian() * f3; entityitem.MotionY = (float)Rand.NextGaussian() * f3 + 0.2F; entityitem.MotionZ = (float)Rand.NextGaussian() * f3; WorldObj.SpawnEntityInWorld(entityitem); }while (true); } DropItemWithOffset(Block.Chest.BlockID, 1, 0.0F); } else if (MinecartType == 2) { DropItemWithOffset(Block.StoneOvenIdle.BlockID, 1, 0.0F); } } return(true); }
/// <summary> /// Renders the item /// </summary> public virtual void DoRenderItem(EntityItem par1EntityItem, double par2, double par4, double par6, float par8, float par9) { Random.SetSeed(187); ItemStack itemstack = par1EntityItem.ItemStack; //GL.PushMatrix(); float f = MathHelper2.Sin(((float)par1EntityItem.Age + par9) / 10F + par1EntityItem.Field_804_d) * 0.1F + 0.1F; float f1 = (((float)par1EntityItem.Age + par9) / 20F + par1EntityItem.Field_804_d) * (180F / (float)Math.PI); sbyte byte0 = 1; if (par1EntityItem.ItemStack.StackSize > 1) { byte0 = 2; } if (par1EntityItem.ItemStack.StackSize > 5) { byte0 = 3; } if (par1EntityItem.ItemStack.StackSize > 20) { byte0 = 4; } //GL.Translate((float)par2, (float)par4 + f, (float)par6); //GL.Enable(EnableCap.RescaleNormal); if (itemstack.ItemID < 256 && RenderBlocks.RenderItemIn3d(Block.BlocksList[itemstack.ItemID].GetRenderType())) { //GL.Rotate(f1, 0.0F, 1.0F, 0.0F); LoadTexture("/terrain.png"); float f2 = 0.25F; int k = Block.BlocksList[itemstack.ItemID].GetRenderType(); if (k == 1 || k == 19 || k == 12 || k == 2) { f2 = 0.5F; } //GL.Scale(f2, f2, f2); for (int j1 = 0; j1 < byte0; j1++) { //GL.PushMatrix(); if (j1 > 0) { float f5 = ((Random.NextFloat() * 2.0F - 1.0F) * 0.2F) / f2; float f8 = ((Random.NextFloat() * 2.0F - 1.0F) * 0.2F) / f2; float f11 = ((Random.NextFloat() * 2.0F - 1.0F) * 0.2F) / f2; //GL.Translate(f5, f8, f11); } float f6 = 1.0F; RenderBlocks.RenderBlockAsItem(Block.BlocksList[itemstack.ItemID], itemstack.GetItemDamage(), f6); //GL.PopMatrix(); } } else if (itemstack.GetItem().Func_46058_c()) { //GL.Scale(0.5F, 0.5F, 0.5F); LoadTexture("/gui/items.png"); for (int i = 0; i <= 1; i++) { int l = itemstack.GetItem().Func_46057_a(itemstack.GetItemDamage(), i); float f3 = 1.0F; if (Field_27004_a) { int k1 = Item.ItemsList[itemstack.ItemID].GetColorFromDamage(itemstack.GetItemDamage(), i); float f9 = (float)(k1 >> 16 & 0xff) / 255F; float f12 = (float)(k1 >> 8 & 0xff) / 255F; float f14 = (float)(k1 & 0xff) / 255F; //GL.Color4(f9 * f3, f12 * f3, f14 * f3, 1.0F); } Func_40267_a(l, byte0); } } else { //GL.Scale(0.5F, 0.5F, 0.5F); int j = itemstack.GetIconIndex(); if (itemstack.ItemID < 256) { LoadTexture("/terrain.png"); } else { LoadTexture("/gui/items.png"); } if (Field_27004_a) { int i1 = Item.ItemsList[itemstack.ItemID].GetColorFromDamage(itemstack.GetItemDamage(), 0); float f4 = (float)(i1 >> 16 & 0xff) / 255F; float f7 = (float)(i1 >> 8 & 0xff) / 255F; float f10 = (float)(i1 & 0xff) / 255F; float f13 = 1.0F; //GL.Color4(f4 * f13, f7 * f13, f10 * f13, 1.0F); } Func_40267_a(j, byte0); } //GL.Disable(EnableCap.RescaleNormal); //GL.PopMatrix(); }
/// <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); } } }