hassansyyid

?

Jul 5th, 2015
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.09 KB | None | 0 0
  1. package com.arisux.avp.block;
  2.  
  3. import java.util.Random;
  4.  
  5. import com.arisux.avp.entities.tile.PoweredTileEntity;
  6. import com.arisux.avp.entities.tile.TileEntityBlastdoor;
  7.  
  8. import net.minecraft.block.Block;
  9. import net.minecraft.block.material.Material;
  10. import net.minecraft.entity.Entity;
  11. import net.minecraft.entity.player.EntityPlayer;
  12. import net.minecraft.util.AxisAlignedBB;
  13. import net.minecraft.world.World;
  14.  
  15. public class GhostBlock extends Block
  16.     {
  17.         private Block parentBlock;
  18.         private PoweredTileEntity parentTileEntity;
  19.         public boolean canCollide;
  20.        
  21.         public GhostBlock()
  22.         {
  23.             super(Material.iron);
  24.             setTickRandomly(true);
  25.         }
  26.  
  27.         @Override
  28.         public int getRenderType()
  29.         {
  30.             return -1;
  31.         }
  32.        
  33.         @Override
  34.         public void updateTick(World worldIn, int x, int y, int z, Random rand)
  35.         {
  36.             getParentBlock(worldIn, x, y, z);
  37.         }
  38.        
  39.         public Block getParentBlock(World world, int xPos, int yPos, int zPos)
  40.         {
  41.             for(int x = xPos + 1; x <= (3 + xPos); x++)
  42.             {
  43.                 if(world.getTileEntity(x, yPos, zPos) instanceof TileEntityBlastdoor)
  44.                 {
  45.                     parentTileEntity = (TileEntityBlastdoor) world.getTileEntity(x, yPos, zPos);
  46.                     parentBlock = (BlockBlastdoor) world.getBlock(x, yPos, zPos);
  47.                     return parentBlock;
  48.                 }
  49.                 for(int y = yPos + 1; y <= (3 + yPos); y++)
  50.                 {
  51.                     if(world.getTileEntity(x, y, zPos) instanceof TileEntityBlastdoor)
  52.                     {
  53.                         parentTileEntity = (TileEntityBlastdoor) world.getTileEntity(x, y, zPos);
  54.                         parentBlock = (BlockBlastdoor) world.getBlock(x, y, zPos);
  55.                         return parentBlock;
  56.                     }
  57.                     for(int z = zPos + 1; z <= (3 + zPos); z++)
  58.                     {
  59.                         if(world.getTileEntity(x, y, z) instanceof TileEntityBlastdoor)
  60.                         {
  61.                             parentTileEntity = (TileEntityBlastdoor) world.getTileEntity(x, y, z);
  62.                             parentBlock = (BlockBlastdoor) world.getBlock(x, y, z);
  63.                             return parentBlock;
  64.                         }
  65.                     }
  66.                 }
  67.             }
  68.            
  69.             for(int x = xPos - 1; x >= (xPos - 3); x--)
  70.             {
  71.                 if(world.getTileEntity(x, yPos, zPos) instanceof TileEntityBlastdoor)
  72.                 {
  73.                     parentTileEntity = (TileEntityBlastdoor) world.getTileEntity(x, yPos, zPos);
  74.                     parentBlock = (BlockBlastdoor) world.getBlock(x, yPos, zPos);
  75.                     return parentBlock;
  76.                 }
  77.                 for(int y = yPos - 1; y >= (yPos - 3); y--)
  78.                 {
  79.                     if(world.getTileEntity(x, y, zPos) instanceof TileEntityBlastdoor)
  80.                     {
  81.                         parentTileEntity = (TileEntityBlastdoor) world.getTileEntity(x, y, zPos);
  82.                         parentBlock = (BlockBlastdoor) world.getBlock(x, y, zPos);
  83.                         return parentBlock;
  84.                     }
  85.                     for(int z = zPos - 1; z >= (zPos - 3); z--)
  86.                     {
  87.                         if(world.getTileEntity(x, y, z) instanceof TileEntityBlastdoor)
  88.                         {
  89.                             parentTileEntity = (TileEntityBlastdoor) world.getTileEntity(x, y, z);
  90.                             parentBlock = (BlockBlastdoor) world.getBlock(x, y, z);
  91.                             return parentBlock;
  92.                         }
  93.                     }
  94.                 }
  95.             }
  96.             return parentBlock;
  97.         }
  98.  
  99.         @Override
  100.         public boolean onBlockActivated(World world, int posX, int posY, int posZ, EntityPlayer player, int side, float subX, float subY, float subZ)
  101.         {
  102.             getParentBlock(world, posX, posY, posZ);
  103.             try
  104.             {
  105.                 return parentBlock.onBlockActivated(world, parentTileEntity.xCoord, parentTileEntity.yCoord, parentTileEntity.zCoord, player, side, subX, subY, subZ);
  106.             }
  107.             catch(NullPointerException e)
  108.             {
  109.  
  110.             }
  111.             return true;
  112.         }
  113.         @Override
  114.         public AxisAlignedBB getCollisionBoundingBoxFromPool(World p_149668_1_, int p_149668_2_, int p_149668_3_, int p_149668_4_)
  115.         {
  116.             if(this.parentBlock != null && this.parentTileEntity != null)
  117.             {
  118.                 TileEntityBlastdoor te = (TileEntityBlastdoor) this.parentTileEntity;
  119.                 if(te.isDoorOpen())
  120.                 {
  121.                     return null;
  122.                 }
  123.                 else
  124.                 {
  125.                     return AxisAlignedBB.getBoundingBox((double)p_149668_2_ + this.minX, (double)p_149668_3_ + this.minY, (double)p_149668_4_ + this.minZ, (double)p_149668_2_ + this.maxX, (double)p_149668_3_ + this.maxY, (double)p_149668_4_ + this.maxZ);
  126.                 }
  127.             }
  128.             return AxisAlignedBB.getBoundingBox((double)p_149668_2_ + this.minX, (double)p_149668_3_ + this.minY, (double)p_149668_4_ + this.minZ, (double)p_149668_2_ + this.maxX, (double)p_149668_3_ + this.maxY, (double)p_149668_4_ + this.maxZ);
  129.         }
  130.        
  131.         @Override
  132.         public void breakBlock(World world, int posX, int posY, int posZ, Block blockBroken, int meta)
  133.         {
  134.             //getParentBlock(world, posX, posY, posZ);
  135.             if(parentBlock != null && parentTileEntity != null)
  136.             {
  137.             try
  138.             {
  139.                 TileEntityBlastdoor te = (TileEntityBlastdoor) parentTileEntity;
  140.                 if(!te.isDoorOpen())
  141.                 {
  142.                     parentBlock.breakBlock(world, parentTileEntity.xCoord, parentTileEntity.yCoord, parentTileEntity.zCoord, blockBroken, meta);
  143.                 }
  144.             }
  145.             catch(NullPointerException e)
  146.             {
  147.  
  148.             }
  149.             }
  150.             else
  151.             {
  152.                 getParentBlock(world, posX, posY, posZ);
  153.                 try
  154.                 {
  155.                     TileEntityBlastdoor te = (TileEntityBlastdoor) parentTileEntity;
  156.                     if(!te.isDoorOpen())
  157.                     {
  158.                         parentBlock.breakBlock(world, parentTileEntity.xCoord, parentTileEntity.yCoord, parentTileEntity.zCoord, blockBroken, meta);
  159.                     }
  160.                 }
  161.                 catch(NullPointerException e)
  162.                 {
  163.  
  164.                 }
  165.             }          
  166.         }
  167.     }
Advertisement
Add Comment
Please, Sign In to add comment