Advertisement
Guest User

Wool Dyer Block

a guest
Nov 3rd, 2013
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.77 KB | None | 0 0
  1. package phnxflms.unidye;
  2.  
  3. import java.util.Random;
  4.  
  5. import net.minecraft.block.BlockContainer;
  6. import net.minecraft.block.material.Material;
  7. import net.minecraft.client.renderer.texture.IconRegister;
  8. import net.minecraft.creativetab.CreativeTabs;
  9. import net.minecraft.entity.item.EntityItem;
  10. import net.minecraft.entity.player.EntityPlayer;
  11. import net.minecraft.inventory.IInventory;
  12. import net.minecraft.item.ItemStack;
  13. import net.minecraft.nbt.NBTTagCompound;
  14. import net.minecraft.tileentity.TileEntity;
  15. import net.minecraft.world.World;
  16. import cpw.mods.fml.relauncher.Side;
  17. import cpw.mods.fml.relauncher.SideOnly;
  18. import ic2.api.energy.prefab.BasicSink;
  19. import ic2.api.tile.IWrenchable;
  20. import phnxflms.unidye.TileEntityWoolDyer;
  21.  
  22. public class BlockWoolDyer extends BlockContainer {
  23.  
  24. public BlockWoolDyer(int id, Material material) {
  25. super(id, material);
  26. this.setCreativeTab(CreativeTabs.tabBlock);
  27. }
  28.  
  29. @Override
  30. public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9){
  31. if(world.isRemote) return true;
  32.  
  33. TileEntityWoolDyer te = (TileEntityWoolDyer) world.getBlockTileEntity(x, y , z);
  34. if (te != null){
  35. if (player.isSneaking()) {
  36. te.ic2EnergySink.setEnergyStored(0.0D);
  37. te.woolCount++;
  38. }
  39. player.addChatMessage("Current Energy: " + te.ic2EnergySink.getEnergyStored());
  40. player.addChatMessage("WoolCount: " + te.woolCount);
  41. player.openGui(Unidye.instance, 0, world, x, y, z);
  42. }
  43. return true;
  44. }
  45.  
  46. @SideOnly(Side.CLIENT) //Only done client-side
  47. public void registerIcons(IconRegister par1IconRegister)//Assigns a texture
  48. {
  49. this.blockIcon = par1IconRegister.registerIcon(Unidye.modid + ":" + (this.getUnlocalizedName().substring(5)));
  50.  
  51. }
  52.  
  53. @Override
  54. public TileEntity createNewTileEntity(World world) {
  55. return null;
  56. }
  57.  
  58. @Override
  59. public TileEntity createTileEntity(World world, int meta) {
  60. return new TileEntityWoolDyer();
  61. }
  62.  
  63. @Override
  64. public void breakBlock(World world, int x, int y, int z, int par5, int par6) {
  65. dropItems(world, x, y, z);
  66. super.breakBlock(world, x, y, z, par5, par6);
  67. }
  68.  
  69. private void dropItems(World world, int x, int y, int z){
  70. Random rand = new Random();
  71.  
  72. TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
  73. if (!(tileEntity instanceof IInventory)) {
  74. return;
  75. }
  76. IInventory inventory = (IInventory) tileEntity;
  77.  
  78. for (int i = 0; i < inventory.getSizeInventory(); i++) {
  79. ItemStack item = inventory.getStackInSlot(i);
  80.  
  81. if (item != null && item.stackSize > 0) {
  82. float rx = rand.nextFloat() * 0.8F + 0.1F;
  83. float ry = rand.nextFloat() * 0.8F + 0.1F;
  84. float rz = rand.nextFloat() * 0.8F + 0.1F;
  85.  
  86. EntityItem entityItem = new EntityItem(world,
  87. x + rx, y + ry, z + rz,
  88. new ItemStack(item.itemID, item.stackSize, item.getItemDamage()));
  89.  
  90. if (item.hasTagCompound()) {
  91. entityItem.getEntityItem().setTagCompound((NBTTagCompound) item.getTagCompound().copy());
  92. }
  93.  
  94. float factor = 0.05F;
  95. entityItem.motionX = rand.nextGaussian() * factor;
  96. entityItem.motionY = rand.nextGaussian() * factor + 0.2F;
  97. entityItem.motionZ = rand.nextGaussian() * factor;
  98. world.spawnEntityInWorld(entityItem);
  99. item.stackSize = 0;
  100. }
  101. }
  102. }
  103.  
  104.  
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement