Advertisement
hassansyyid

waaat

Jul 5th, 2015
265
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.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.             if(this.parentBlock != null && this.parentTileEntity != null)
  38.             {
  39.                 TileEntityBlastdoor te = (TileEntityBlastdoor) this.parentTileEntity;
  40.                 if(te.isDoorOpen())
  41.                 {
  42.                     this.canCollide = false;
  43.                 }
  44.                 if(!te.isDoorOpen())
  45.                 {
  46.                     this.canCollide = true;
  47.                 }
  48.             }
  49.         }
  50.        
  51.         public Block getParentBlock(World world, int xPos, int yPos, int zPos)
  52.         {
  53.             for(int x = xPos + 1; x <= (3 + xPos); x++)
  54.             {
  55.                 if(world.getTileEntity(x, yPos, zPos) instanceof TileEntityBlastdoor)
  56.                 {
  57.                     TileEntityBlastdoor te = (TileEntityBlastdoor) world.getTileEntity(x, yPos, zPos);
  58.                     parentTileEntity = te;
  59.                     BlockBlastdoor b = (BlockBlastdoor) world.getBlock(x, yPos, zPos);
  60.                     parentBlock = b;
  61.                     return parentBlock;
  62.                 }
  63.                 for(int y = yPos + 1; y <= (3 + yPos); y++)
  64.                 {
  65.                     if(world.getTileEntity(x, y, zPos) instanceof TileEntityBlastdoor)
  66.                     {
  67.                         TileEntityBlastdoor te = (TileEntityBlastdoor) world.getTileEntity(x, y, zPos);
  68.                         parentTileEntity = te;
  69.                         BlockBlastdoor b = (BlockBlastdoor) world.getBlock(x, y, zPos);
  70.                         parentBlock = b;
  71.                         return parentBlock;
  72.                     }
  73.                     for(int z = zPos + 1; z <= (3 + zPos); z++)
  74.                     {
  75.                         if(world.getTileEntity(x, y, z) instanceof TileEntityBlastdoor)
  76.                         {
  77.                             TileEntityBlastdoor te = (TileEntityBlastdoor) world.getTileEntity(x, y, z);
  78.                             parentTileEntity = te;
  79.                             BlockBlastdoor b = (BlockBlastdoor) world.getBlock(x, y, z);
  80.                             parentBlock = b;
  81.                             return parentBlock;
  82.                         }
  83.                     }
  84.                 }
  85.             }
  86.            
  87.             for(int x = xPos - 1; x >= (xPos - 3); x--)
  88.             {
  89.                 if(world.getTileEntity(x, yPos, zPos) instanceof TileEntityBlastdoor)
  90.                 {
  91.                     TileEntityBlastdoor te = (TileEntityBlastdoor) world.getTileEntity(x, yPos, zPos);
  92.                     parentTileEntity = te;
  93.                         BlockBlastdoor b = (BlockBlastdoor) world.getBlock(x, yPos, zPos);
  94.                         parentBlock = b;
  95.                         return parentBlock;
  96.                 }
  97.                 for(int y = yPos - 1; y >= (yPos - 3); y--)
  98.                 {
  99.                     if(world.getTileEntity(x, y, zPos) instanceof TileEntityBlastdoor)
  100.                     {
  101.                         TileEntityBlastdoor te = (TileEntityBlastdoor) world.getTileEntity(x, y, zPos);
  102.                         parentTileEntity = te;
  103.                             BlockBlastdoor b = (BlockBlastdoor) world.getBlock(x, y, zPos);
  104.                             parentBlock = b;
  105.                             return parentBlock;
  106.                     }
  107.                     for(int z = zPos - 1; z >= (zPos - 3); z--)
  108.                     {
  109.                         if(world.getTileEntity(x, y, z) instanceof TileEntityBlastdoor)
  110.                         {
  111.                             TileEntityBlastdoor te = (TileEntityBlastdoor) world.getTileEntity(x, y, z);
  112.                             parentTileEntity = te;
  113.                                 BlockBlastdoor b = (BlockBlastdoor) world.getBlock(x, y, z);
  114.                                 parentBlock = b;
  115.                                 return parentBlock;
  116.                         }
  117.                     }
  118.                 }
  119.             }
  120.             return parentBlock;
  121.         }
  122.  
  123.         @Override
  124.         public boolean onBlockActivated(World world, int posX, int posY, int posZ, EntityPlayer player, int side, float subX, float subY, float subZ)
  125.         {
  126.             getParentBlock(world, posX, posY, posZ);
  127.             try
  128.             {
  129.                 return parentBlock.onBlockActivated(world, parentTileEntity.xCoord, parentTileEntity.yCoord, parentTileEntity.zCoord, player, side, subX, subY, subZ);
  130.             }
  131.             catch(NullPointerException e)
  132.             {
  133.  
  134.             }
  135.             return true;
  136.         }
  137.         @Override
  138.         public AxisAlignedBB getCollisionBoundingBoxFromPool(World p_149668_1_, int p_149668_2_, int p_149668_3_, int p_149668_4_)
  139.         {
  140.             if(!this.canCollide)
  141.             {
  142.                 return null;
  143.             }
  144.             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);
  145.         }
  146.        
  147.         @Override
  148.         public void breakBlock(World world, int posX, int posY, int posZ, Block blockBroken, int meta)
  149.         {
  150.             getParentBlock(world, posX, posY, posZ);
  151.             if(parentBlock != null && parentTileEntity != null)
  152.             {
  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.             else
  167.             {
  168.                 getParentBlock(world, posX, posY, posZ);
  169.                 try
  170.                 {
  171.                     TileEntityBlastdoor te = (TileEntityBlastdoor) parentTileEntity;
  172.                     if(!te.isDoorOpen())
  173.                     {
  174.                         parentBlock.breakBlock(world, parentTileEntity.xCoord, parentTileEntity.yCoord, parentTileEntity.zCoord, blockBroken, meta);
  175.                     }
  176.                 }
  177.                 catch(NullPointerException e)
  178.                 {
  179.  
  180.                 }
  181.             }          
  182.         }
  183.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement