SHARE
TWEET

BlockChest

a guest Apr 20th, 2019 125 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package net.minecraft.block;
  2. import java.util.Iterator;
  3. import java.util.Random;
  4.  
  5. import net.minecraft.block.Block;
  6. import net.minecraft.block.BlockContainer;
  7. import net.minecraft.block.material.Material;
  8. import net.minecraft.client.renderer.texture.IIconRegister;
  9. import net.minecraft.creativetab.CreativeTabs;
  10. import net.minecraft.entity.EntityLivingBase;
  11. import net.minecraft.entity.item.EntityItem;
  12. import net.minecraft.entity.passive.EntityOcelot;
  13. import net.minecraft.entity.player.EntityPlayer;
  14. import net.minecraft.inventory.Container;
  15. import net.minecraft.inventory.IInventory;
  16. import net.minecraft.inventory.InventoryLargeChest;
  17. import net.minecraft.item.ItemStack;
  18. import net.minecraft.nbt.NBTTagCompound;
  19. import net.minecraft.render.tileentity.TileEntityIstriumChest;
  20. import net.minecraft.tileentity.TileEntity;
  21. import net.minecraft.render.tileentity.TileEntityIstriumChest;
  22. import net.minecraft.util.AxisAlignedBB;
  23. import net.minecraft.util.MathHelper;
  24. import net.minecraft.world.IBlockAccess;
  25. import net.minecraft.world.World;
  26.  
  27. public class BlockIstriumChest extends BlockContainer
  28. {
  29.     private final Random field_149955_b = new Random();
  30.     public final int field_149956_a;
  31.  
  32.     public BlockIstriumChest(int p_i45397_1_)
  33.     {
  34.         super(Material.wood);
  35.         this.field_149956_a = p_i45397_1_;
  36.         this.setCreativeTab(CreativeTabs.tabDecorations);
  37.         this.setBlockBounds(0.0625F, 0.0F, 0.0625F, 0.9375F, 0.875F, 0.9375F);
  38.     }
  39.  
  40.     public boolean isOpaqueCube()
  41.     {
  42.         return false;
  43.     }
  44.  
  45.     public boolean renderAsNormalBlock()
  46.     {
  47.         return false;
  48.     }
  49.  
  50.     /**
  51.      * The type of render function that is called for this block
  52.      */
  53.     public int getRenderType()
  54.     {
  55.         return 22;
  56.     }
  57.  
  58.     public void setBlockBoundsBasedOnState(IBlockAccess p_149719_1_, int p_149719_2_, int p_149719_3_, int p_149719_4_)
  59.     {
  60.         if (p_149719_1_.getBlock(p_149719_2_, p_149719_3_, p_149719_4_ - 1) == this)
  61.         {
  62.             this.setBlockBounds(0.0625F, 0.0F, 0.0F, 0.9375F, 0.875F, 0.9375F);
  63.         }
  64.         else if (p_149719_1_.getBlock(p_149719_2_, p_149719_3_, p_149719_4_ + 1) == this)
  65.         {
  66.             this.setBlockBounds(0.0625F, 0.0F, 0.0625F, 0.9375F, 0.875F, 1.0F);
  67.         }
  68.         else if (p_149719_1_.getBlock(p_149719_2_ - 1, p_149719_3_, p_149719_4_) == this)
  69.         {
  70.             this.setBlockBounds(0.0F, 0.0F, 0.0625F, 0.9375F, 0.875F, 0.9375F);
  71.         }
  72.         else if (p_149719_1_.getBlock(p_149719_2_ + 1, p_149719_3_, p_149719_4_) == this)
  73.         {
  74.             this.setBlockBounds(0.0625F, 0.0F, 0.0625F, 1.0F, 0.875F, 0.9375F);
  75.         }
  76.         else
  77.         {
  78.             this.setBlockBounds(0.0625F, 0.0F, 0.0625F, 0.9375F, 0.875F, 0.9375F);
  79.         }
  80.     }
  81.  
  82.    
  83.     /**
  84.      * Called when the block is placed in the world.
  85.      */
  86.     public void onBlockPlacedBy(World p_149689_1_, int p_149689_2_, int p_149689_3_, int p_149689_4_, EntityLivingBase p_149689_5_, ItemStack p_149689_6_)
  87.     {
  88.         Block var7 = p_149689_1_.getBlock(p_149689_2_, p_149689_3_, p_149689_4_ - 1);
  89.         Block var8 = p_149689_1_.getBlock(p_149689_2_, p_149689_3_, p_149689_4_ + 1);
  90.         Block var9 = p_149689_1_.getBlock(p_149689_2_ - 1, p_149689_3_, p_149689_4_);
  91.         Block var10 = p_149689_1_.getBlock(p_149689_2_ + 1, p_149689_3_, p_149689_4_);
  92.         byte var11 = 0;
  93.         int var12 = MathHelper.floor_double((double)(p_149689_5_.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
  94.  
  95.         if (var12 == 0)
  96.         {
  97.             var11 = 2;
  98.         }
  99.  
  100.         if (var12 == 1)
  101.         {
  102.             var11 = 5;
  103.         }
  104.  
  105.         if (var12 == 2)
  106.         {
  107.             var11 = 3;
  108.         }
  109.  
  110.         if (var12 == 3)
  111.         {
  112.             var11 = 4;
  113.         }
  114.  
  115.         p_149689_1_.setBlockMetadataWithNotify(p_149689_2_, p_149689_3_, p_149689_4_, var11, 0);
  116.     }
  117.  
  118.  
  119.     public void onNeighborBlockChange(World p_149695_1_, int p_149695_2_, int p_149695_3_, int p_149695_4_, Block p_149695_5_)
  120.     {
  121.         super.onNeighborBlockChange(p_149695_1_, p_149695_2_, p_149695_3_, p_149695_4_, p_149695_5_);
  122.         TileEntityIstriumChest var6 = (TileEntityIstriumChest)p_149695_1_.getTileEntity(p_149695_2_, p_149695_3_, p_149695_4_);
  123.  
  124.         if (var6 != null)
  125.         {
  126.             var6.updateContainingBlockInfo();
  127.         }
  128.     }
  129.  
  130.     public void breakBlock(World p_149749_1_, int p_149749_2_, int p_149749_3_, int p_149749_4_, Block p_149749_5_, int p_149749_6_)
  131.     {
  132.         TileEntityIstriumChest var7 = (TileEntityIstriumChest)p_149749_1_.getTileEntity(p_149749_2_, p_149749_3_, p_149749_4_);
  133.  
  134.         if (var7 != null)
  135.         {
  136.             for (int var8 = 0; var8 < var7.getSizeInventory(); ++var8)
  137.             {
  138.                 ItemStack var9 = var7.getStackInSlot(var8);
  139.  
  140.                 if (var9 != null)
  141.                 {
  142.                     float var10 = this.field_149955_b.nextFloat() * 0.8F + 0.1F;
  143.                     float var11 = this.field_149955_b.nextFloat() * 0.8F + 0.1F;
  144.                     EntityItem var14;
  145.  
  146.                     for (float var12 = this.field_149955_b.nextFloat() * 0.8F + 0.1F; var9.stackSize > 0; p_149749_1_.spawnEntityInWorld(var14))
  147.                     {
  148.                         int var13 = this.field_149955_b.nextInt(21) + 10;
  149.  
  150.                         if (var13 > var9.stackSize)
  151.                         {
  152.                             var13 = var9.stackSize;
  153.                         }
  154.  
  155.                         var9.stackSize -= var13;
  156.                         var14 = new EntityItem(p_149749_1_, (double)((float)p_149749_2_ + var10), (double)((float)p_149749_3_ + var11), (double)((float)p_149749_4_ + var12), new ItemStack(var9.getItem(), var13, var9.getItemDamage()));
  157.                         float var15 = 0.05F;
  158.                         var14.motionX = (double)((float)this.field_149955_b.nextGaussian() * var15);
  159.                         var14.motionY = (double)((float)this.field_149955_b.nextGaussian() * var15 + 0.2F);
  160.                         var14.motionZ = (double)((float)this.field_149955_b.nextGaussian() * var15);
  161.  
  162.                         if (var9.hasTagCompound())
  163.                         {
  164.                             var14.getEntityItem().setTagCompound((NBTTagCompound)var9.getTagCompound().copy());
  165.                         }
  166.                     }
  167.                 }
  168.             }
  169.  
  170.             p_149749_1_.func_147453_f(p_149749_2_, p_149749_3_, p_149749_4_, p_149749_5_);
  171.         }
  172.  
  173.         super.breakBlock(p_149749_1_, p_149749_2_, p_149749_3_, p_149749_4_, p_149749_5_, p_149749_6_);
  174.     }
  175.  
  176.     /**
  177.      * Called upon block activation (right click on the block.)
  178.      */
  179.     public boolean onBlockActivated(World p_149727_1_, int p_149727_2_, int p_149727_3_, int p_149727_4_, EntityPlayer p_149727_5_, int p_149727_6_, float p_149727_7_, float p_149727_8_, float p_149727_9_)
  180.     {
  181.         if (p_149727_1_.isClient)
  182.         {
  183.             return true;
  184.         }
  185.         else
  186.         {
  187.             IInventory var10 = this.func_149951_m(p_149727_1_, p_149727_2_, p_149727_3_, p_149727_4_);
  188.  
  189.             if (var10 != null)
  190.             {
  191.                 p_149727_5_.displayGUIChest(var10);
  192.             }
  193.  
  194.             return true;
  195.         }
  196.     }
  197.  
  198.     public IInventory func_149951_m(World p_149951_1_, int p_149951_2_, int p_149951_3_, int p_149951_4_)
  199.     {
  200.         Object var5 = (TileEntityIstriumChest)p_149951_1_.getTileEntity(p_149951_2_, p_149951_3_, p_149951_4_);
  201.  
  202.         if (var5 == null)
  203.         {
  204.             return null;
  205.         }
  206.         else if (p_149951_1_.getBlock(p_149951_2_, p_149951_3_ + 1, p_149951_4_).isNormalCube())
  207.         {
  208.             return null;
  209.         }
  210.         else if (func_149953_o(p_149951_1_, p_149951_2_, p_149951_3_, p_149951_4_))
  211.         {
  212.             return null;
  213.         }
  214.         else if (p_149951_1_.getBlock(p_149951_2_ - 1, p_149951_3_, p_149951_4_) == this && (p_149951_1_.getBlock(p_149951_2_ - 1, p_149951_3_ + 1, p_149951_4_).isNormalCube() || func_149953_o(p_149951_1_, p_149951_2_ - 1, p_149951_3_, p_149951_4_)))
  215.         {
  216.             return null;
  217.         }
  218.         else if (p_149951_1_.getBlock(p_149951_2_ + 1, p_149951_3_, p_149951_4_) == this && (p_149951_1_.getBlock(p_149951_2_ + 1, p_149951_3_ + 1, p_149951_4_).isNormalCube() || func_149953_o(p_149951_1_, p_149951_2_ + 1, p_149951_3_, p_149951_4_)))
  219.         {
  220.             return null;
  221.         }
  222.         else if (p_149951_1_.getBlock(p_149951_2_, p_149951_3_, p_149951_4_ - 1) == this && (p_149951_1_.getBlock(p_149951_2_, p_149951_3_ + 1, p_149951_4_ - 1).isNormalCube() || func_149953_o(p_149951_1_, p_149951_2_, p_149951_3_, p_149951_4_ - 1)))
  223.         {
  224.             return null;
  225.         }
  226.         else if (p_149951_1_.getBlock(p_149951_2_, p_149951_3_, p_149951_4_ + 1) == this && (p_149951_1_.getBlock(p_149951_2_, p_149951_3_ + 1, p_149951_4_ + 1).isNormalCube() || func_149953_o(p_149951_1_, p_149951_2_, p_149951_3_, p_149951_4_ + 1)))
  227.         {
  228.             return null;
  229.         }
  230.        
  231.         return (IInventory)var5;
  232.        
  233.     }
  234.  
  235.     /**
  236.      * Returns a new instance of a block's tile entity class. Called on placing the block.
  237.      */
  238.     public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_)
  239.     {
  240.         TileEntityIstriumChest var3 = new TileEntityIstriumChest();
  241.         return var3;
  242.     }
  243.  
  244.     /**
  245.      * Can this block provide power. Only wire currently seems to have this change based on its state.
  246.      */
  247.     public boolean canProvidePower()
  248.     {
  249.         return this.field_149956_a == 1;
  250.     }
  251.  
  252.     public int isProvidingWeakPower(IBlockAccess p_149709_1_, int p_149709_2_, int p_149709_3_, int p_149709_4_, int p_149709_5_)
  253.     {
  254.         if (!this.canProvidePower())
  255.         {
  256.             return 0;
  257.         }
  258.         else
  259.         {
  260.             int var6 = ((TileEntityIstriumChest)p_149709_1_.getTileEntity(p_149709_2_, p_149709_3_, p_149709_4_)).field_145987_o;
  261.             return MathHelper.clamp_int(var6, 0, 15);
  262.         }
  263.     }
  264.  
  265.     public int isProvidingStrongPower(IBlockAccess p_149748_1_, int p_149748_2_, int p_149748_3_, int p_149748_4_, int p_149748_5_)
  266.     {
  267.         return p_149748_5_ == 1 ? this.isProvidingWeakPower(p_149748_1_, p_149748_2_, p_149748_3_, p_149748_4_, p_149748_5_) : 0;
  268.     }
  269.  
  270.     private static boolean func_149953_o(World p_149953_0_, int p_149953_1_, int p_149953_2_, int p_149953_3_)
  271.     {
  272.         Iterator var4 = p_149953_0_.getEntitiesWithinAABB(EntityOcelot.class, AxisAlignedBB.getBoundingBox((double)p_149953_1_, (double)(p_149953_2_ + 1), (double)p_149953_3_, (double)(p_149953_1_ + 1), (double)(p_149953_2_ + 2), (double)(p_149953_3_ + 1))).iterator();
  273.         EntityOcelot var6;
  274.  
  275.         do
  276.         {
  277.             if (!var4.hasNext())
  278.             {
  279.                 return false;
  280.             }
  281.  
  282.             EntityOcelot var5 = (EntityOcelot)var4.next();
  283.             var6 = (EntityOcelot)var5;
  284.         }
  285.         while (!var6.isSitting());
  286.  
  287.         return true;
  288.     }
  289.  
  290.     public boolean hasComparatorInputOverride()
  291.     {
  292.         return true;
  293.     }
  294.  
  295.     public int getComparatorInputOverride(World p_149736_1_, int p_149736_2_, int p_149736_3_, int p_149736_4_, int p_149736_5_)
  296.     {
  297.         return Container.calcRedstoneFromInventory(this.func_149951_m(p_149736_1_, p_149736_2_, p_149736_3_, p_149736_4_));
  298.     }
  299.  
  300.     public void registerBlockIcons(IIconRegister p_149651_1_)
  301.     {
  302.         this.blockIcon = p_149651_1_.registerIcon("planks_oak");
  303.     }
  304. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top