Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pirate.common;
- import java.util.List;
- import net.minecraft.block.Block;
- import net.minecraft.block.BlockContainer;
- import net.minecraft.block.material.Material;
- import net.minecraft.client.renderer.texture.IconRegister;
- import net.minecraft.creativetab.CreativeTabs;
- import net.minecraft.entity.EntityLivingBase;
- import net.minecraft.entity.item.EntityItem;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.item.ItemStack;
- import net.minecraft.tileentity.TileEntity;
- import net.minecraft.util.Icon;
- import net.minecraft.util.MathHelper;
- import net.minecraft.world.IBlockAccess;
- import net.minecraft.world.World;
- import cpw.mods.fml.common.network.FMLNetworkHandler;
- import cpw.mods.fml.relauncher.Side;
- import cpw.mods.fml.relauncher.SideOnly;
- import net.minecraft.entity.item.EntityItem;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.tileentity.TileEntityChest;
- import cpw.mods.fml.common.network.FMLNetworkHandler;
- public class Baril extends BlockContainer{
- private Icon icontop, iconbottom, iconfront;
- public Baril(int id)
- {
- super(id, Material.wood);
- this.setCreativeTab(CreativeTabs.tabDecorations);
- }
- public void registerIcons(IconRegister iconRegister)
- {
- blockIcon = iconRegister.registerIcon("modpirate:Baril");
- iconfront = iconRegister.registerIcon("modpirate:Baril");
- icontop = iconRegister.registerIcon("modpirate:Baril_Top");
- iconbottom = iconRegister.registerIcon("modpirate:Baril_Bottom");
- }
- @SideOnly(Side.CLIENT)
- public Icon getIcon(int side, int metadata)
- {
- return side == 1 ? this.icontop : (side == 0 ? this.iconbottom : (metadata == 2 && side == 2 ? this.iconfront : (metadata == 3 && side == 5 ? this.iconfront : (metadata == 0 && side == 3 ? this.iconfront : (metadata == 1 && side == 4 ? this.iconfront : this.blockIcon)))));
- }
- @@ -117,17 121,22 @@ public TileEntity createNewTileEntity(World world)
- @Override
- public TileEntity createTileEntity(World world, int metadata)
- {
- switch(metadata)
- {
- case 0:
- case 2:
- return new TileEntityTutorial2();
- case 3:
- return new TileEntityBigChest();
- default:
- return null;
- }
- }
- public boolean hasTileEntity(int metadata)
- {
- if(metadata == 0 || metadata == 2 || metadata == 3)
- return true;
- else
- return false;
- @@ -160,10 169,13 @@ public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer p
- }
- return true;
- }
- if(world.getBlockMetadata(x, y, z) == 3)
- {
- FMLNetworkHandler.openGui(player, ModPirate.instance, 0, world, x, y, z);
- return true;
- }
- return false;
- }
- public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase living, ItemStack stack)
- @@ -175,5 187,60 @@ public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase l
- }
- if(te != null && stack.getItemDamage() == 3 && te instanceof TileEntityBigChest && stack.hasDisplayName())
- {
- ((TileEntityBigChest)te).setCustomGuiName(stack.getDisplayName());
- }
- }
- public void breakBlock(World world, int x, int y, int z, int side, int metadata)
- {
- if(metadata == 3)
- {
- dropContainerItem(world, x, y, z);
- }
- super.breakBlock(world, x, y, z, side, metadata);
- }
- protected void dropContainerItem(World world, int x, int y, int z)
- {
- TileEntityBigChest bigchest = (TileEntityBigChest)world.getBlockTileEntity(x, y, z);
- if (bigchest != null)
- {
- for (int slotId = 0; slotId < bigchest.getSizeInventory(); slotId)
- {
- ItemStack stack = bigchest.getStackInSlot(slotId);
- if (stack != null)
- {
- float f = world.rand.nextFloat() * 0.8F ;
- float f1 = world.rand.nextFloat() * 0.8F ;
- EntityItem entityitem;
- for (float f2 = world.rand.nextFloat() * 0.8F ; stack.stackSize > 0; world.spawnEntityInWorld(entityitem))
- {
- int k1 = world.rand.nextInt(21) ;
- if (k1 > stack.stackSize)
- {
- k1 = stack.stackSize;
- }
- stack.stackSize -= k1;
- entityitem = new EntityItem(world, (double)((float)x ), (double)((float)y ), (double)((float)z ), new ItemStack(stack.itemID, k1, stack.getItemDamage()));
- float f3 = 0.05F;
- entityitem.motionX = (double)((float)world.rand.nextGaussian() * f3);
- entityitem.motionY = (double)((float)world.rand.nextGaussian() * f3 );
- entityitem.motionZ = (double)((float)world.rand.nextGaussian() * f3);
- if (stack.hasTagCompound())
- {
- entityitem.getEntityItem().setTagCompound((NBTTagCompound)stack.getTagCompound().copy());
- }
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement