Reygok

ItemTinyDirt

Jun 29th, 2015
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.38 KB | None | 0 0
  1. package com.reygok.octablocks.items;
  2.  
  3. import scala.collection.mutable.SetBuilder;
  4.  
  5. import com.reygok.octablocks.OctablocksMod;
  6. import com.reygok.octablocks.blocks.TileEntityTinyDirt;
  7.  
  8. import net.minecraft.block.Block;
  9. import net.minecraft.block.BlockSnow;
  10. import net.minecraft.block.state.IBlockState;
  11. import net.minecraft.entity.Entity;
  12. import net.minecraft.entity.player.EntityPlayer;
  13. import net.minecraft.init.Blocks;
  14. import net.minecraft.item.ItemBlock;
  15. import net.minecraft.item.ItemStack;
  16. import net.minecraft.nbt.NBTTagCompound;
  17. import net.minecraft.tileentity.TileEntity;
  18. import net.minecraft.util.AxisAlignedBB;
  19. import net.minecraft.util.BlockPos;
  20. import net.minecraft.util.EnumFacing;
  21. import net.minecraft.world.World;
  22.  
  23. public class ItemTinyDirt extends ItemBlock{
  24.  
  25.  
  26.     public ItemTinyDirt(Block block) {
  27.         super(block);
  28.     }
  29.  
  30.  
  31.     @Override
  32.     public boolean onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ)
  33.     {
  34.         IBlockState iblockstate = worldIn.getBlockState(pos);
  35.         Block block = iblockstate.getBlock();
  36.         if (block == Blocks.snow_layer && ((Integer)iblockstate.getValue(BlockSnow.LAYERS)).intValue() < 1)
  37.         {
  38.             side = EnumFacing.UP;
  39.         }
  40.         else if (!block.isReplaceable(worldIn, pos))
  41.         {
  42.             if(!(worldIn.getTileEntity(pos) instanceof TileEntityTinyDirt))
  43.             {
  44.                 pos = pos.offset(side);
  45.             }
  46.             else if(hitX == 1.0 || hitX == 0.0 || hitY == 1.0 || hitY == 0.0 || hitZ == 1.0 || hitZ == 0.0)
  47.             {
  48.                 pos = pos.offset(side);
  49.             }
  50.  
  51.         }
  52.  
  53.         if (stack.stackSize == 0)
  54.         {
  55.             return false;
  56.         }
  57.         else if (!playerIn.canPlayerEdit(pos, side, stack))
  58.         {
  59.             return false;
  60.         }
  61.         else if (pos.getY() == 255 && this.block.getMaterial().isSolid())
  62.         {
  63.             return false;
  64.         }
  65.         else if(worldIn.getTileEntity(pos) instanceof TileEntityTinyDirt)
  66.         {
  67.             TileEntityTinyDirt tileEntity = (TileEntityTinyDirt) worldIn.getTileEntity(pos);
  68.             if(setBlockBits(worldIn, pos, tileEntity, hitX, hitY, hitZ))
  69.             {
  70.                 System.out.println("set new bit");
  71.                 worldIn.playSoundEffect((double)((float)pos.getX() + 0.5F), (double)((float)pos.getY() + 0.5F), (double)((float)pos.getZ() + 0.5F), this.block.stepSound.getPlaceSound(), (this.block.stepSound.getVolume() + 1.0F) / 2.0F, this.block.stepSound.getFrequency() * 0.8F);
  72.                 --stack.stackSize;
  73.                 if(tileEntity.isFull())
  74.                 {
  75.                     // TO FILL IN
  76.                 }
  77.                 return true;
  78.             }
  79.             else
  80.                 return false;
  81.         }
  82.         else if (worldIn.canBlockBePlaced(this.block, pos, false, side, (Entity)null, stack))
  83.         {
  84.             int i = this.getMetadata(stack.getMetadata());
  85.             IBlockState iblockstate1 = this.block.onBlockPlaced(worldIn, pos, side, hitX, hitY, hitZ, i, playerIn);
  86.  
  87.             if (placeBlockAt(stack, playerIn, worldIn, pos, side, hitX, hitY, hitZ, iblockstate1))
  88.             {
  89.                 worldIn.playSoundEffect((double)((float)pos.getX() + 0.5F), (double)((float)pos.getY() + 0.5F), (double)((float)pos.getZ() + 0.5F), this.block.stepSound.getPlaceSound(), (this.block.stepSound.getVolume() + 1.0F) / 2.0F, this.block.stepSound.getFrequency() * 0.8F);
  90.                 --stack.stackSize;
  91.             }
  92.  
  93.             return true;
  94.         }
  95.         else
  96.         {
  97.             return false;
  98.         }        
  99.     }
  100.    
  101.     public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, IBlockState newState)
  102.     {
  103.         if (!world.setBlockState(pos, newState, 3)) return false;
  104.         setTileEntityNBT(world, pos, stack, player, hitX, hitY, hitZ);
  105.         return true;
  106.     }
  107.  
  108.  
  109.     public static boolean setTileEntityNBT(World worldIn, BlockPos pos, ItemStack stack, EntityPlayer player, float hitX, float hitY, float hitZ)
  110.     {
  111.         TileEntityTinyDirt tileEntity = (TileEntityTinyDirt) worldIn.getTileEntity(pos);
  112.  
  113.         setBlockBits(worldIn, pos,tileEntity, hitX, hitY, hitZ);
  114.         return false;
  115.     }
  116.  
  117.     public static boolean setBlockBits(World world, BlockPos pos, TileEntityTinyDirt tileEntity, float hitX, float hitY, float hitZ)
  118.     {
  119.         boolean xAxis = (hitX == 1.0 || hitX < 0.5) && hitX != 0.0 ? true : false;
  120.         boolean yAxis = (hitY == 1.0 || hitY < 0.5) && hitY != 0.0 ? true : false;
  121.         boolean zAxis = (hitZ == 1.0 || hitZ < 0.5) && hitZ != 0.0 ? true : false;
  122.  
  123.         if(xAxis)
  124.         {
  125.             if(yAxis)
  126.             {
  127.                 if(zAxis)
  128.                 { // botNW
  129.                     if(tileEntity.isBot_nw())
  130.                         return false;
  131.                     else
  132.                         tileEntity.setBot_nw(true);
  133.                 }
  134.                 else
  135.                 { // botSW
  136.                     if(tileEntity.isBot_sw())
  137.                         return false;
  138.                     else
  139.                         tileEntity.setBot_sw(true);
  140.                 }
  141.             }
  142.             else
  143.             {
  144.                 if(zAxis)
  145.                 { // topNW
  146.                     if(tileEntity.isTop_nw())
  147.                         return false;
  148.                     else
  149.                         tileEntity.setTop_nw(true);
  150.                 }
  151.                 else
  152.                 { // topSW
  153.                     if(tileEntity.isTop_sw())
  154.                         return false;
  155.                     else
  156.                         tileEntity.setTop_sw(true);
  157.                 }
  158.             }
  159.         }
  160.         else
  161.         {
  162.             if(yAxis)
  163.             {
  164.                 if(zAxis)
  165.                 { // botNE
  166.                     if(tileEntity.isBot_ne())
  167.                         return false;
  168.                     else
  169.                         tileEntity.setBot_ne(true);
  170.                 }
  171.                 else
  172.                 { // botSE
  173.                     if(tileEntity.isBot_se())
  174.                         return false;
  175.                     else
  176.                         tileEntity.setBot_se(true);
  177.                 }
  178.             }
  179.             else
  180.             {
  181.                 if(zAxis)
  182.                 { // topNE
  183.                     if(tileEntity.isTop_ne())
  184.                         return false;
  185.                     else
  186.                         tileEntity.setTop_ne(true);
  187.                 }
  188.                 else
  189.                 { // topSE
  190.                     if(tileEntity.isTop_se())
  191.                         return false;
  192.                     else
  193.                         tileEntity.setTop_se(true);
  194.                 }
  195.             }
  196.         }
  197.         world.markBlockForUpdate(pos);
  198.         return true;
  199.     }
  200. }
Advertisement
Add Comment
Please, Sign In to add comment