Don't like ads? PRO users don't see any ads ;-)
Guest

Portal

By: TheInstitutions on May 1st, 2012  |  syntax: None  |  size: 9.47 KB  |  hits: 921  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. AntarticaPortal:
  2.  
  3. //Change ForbiddenPortal to AntarticaPortal or whatever you called it
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10. package net.minecraft.src;
  11.  
  12. import java.util.Random;
  13.  
  14. public class ForbiddenPortal extends BlockBreakable
  15. {
  16.     public ForbiddenPortal(int par1, int par2)
  17.     {
  18.         super(par1, par2, Material.portal, false);
  19.     }
  20.  
  21.     /**
  22.      * Returns a bounding box from the pool of bounding boxes (this means this box can change after the pool has been
  23.      * cleared to be reused)
  24.      */
  25.     public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int i)
  26.     {
  27.         return null;
  28.     }
  29.  
  30.     /**
  31.      * Updates the blocks bounds based on its current state. Args: world, x, y, z
  32.      */
  33.     public void setBlockBoundsBasedOnState(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
  34.     {
  35.         if (par1IBlockAccess.getBlockId(par2 - 1, par3, par4) == blockID || par1IBlockAccess.getBlockId(par2 + 1, par3, par4) == blockID)
  36.         {
  37.             float f = 0.5F;
  38.             float f2 = 0.125F;
  39.             setBlockBounds(0.5F - f, 0.0F, 0.5F - f2, 0.5F + f, 1.0F, 0.5F + f2);
  40.         }
  41.         else
  42.         {
  43.             float f1 = 0.125F;
  44.             float f3 = 0.5F;
  45.             setBlockBounds(0.5F - f1, 0.0F, 0.5F - f3, 0.5F + f1, 1.0F, 0.5F + f3);
  46.         }
  47.     }
  48.  
  49.     /**
  50.      * Is this block (a) opaque and (b) a full 1m cube?  This determines whether or not to render the shared face of two
  51.      * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
  52.      */
  53.     public boolean isOpaqueCube()
  54.     {
  55.         return false;
  56.     }
  57.  
  58.     /**
  59.      * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
  60.      */
  61.     public boolean renderAsNormalBlock()
  62.     {
  63.         return false;
  64.     }
  65.  
  66.     /**
  67.      * Checks to see if this location is valid to create a portal and will return True if it does. Args: world, x, y, z
  68.      */
  69.     public boolean tryToCreatePortal(World par1World, int par2, int par3, int par4)
  70.     {
  71.         int i = 0;
  72.         int j = 0;
  73.  
  74.         if (par1World.getBlockId(par2 - 1, par3, par4) == Block.obsidian.blockID || par1World.getBlockId(par2 + 1, par3, par4) == Block.obsidian.blockID)
  75.         {
  76.             i = 1;
  77.         }
  78.  
  79.         if (par1World.getBlockId(par2, par3, par4 - 1) == Block.obsidian.blockID || par1World.getBlockId(par2, par3, par4 + 1) == Block.obsidian.blockID)
  80.         {
  81.             j = 1;
  82.         }
  83.  
  84.         if (i == j)
  85.         {
  86.             return false;
  87.         }
  88.  
  89.         if (par1World.getBlockId(par2 - i, par3, par4 - j) == 0)
  90.         {
  91.             par2 -= i;
  92.             par4 -= j;
  93.         }
  94.  
  95.         for (int k = -1; k <= 2; k++)
  96.         {
  97.             for (int i1 = -1; i1 <= 3; i1++)
  98.             {
  99.                 boolean flag = k == -1 || k == 2 || i1 == -1 || i1 == 3;
  100.  
  101.                 if ((k == -1 || k == 2) && (i1 == -1 || i1 == 3))
  102.                 {
  103.                     continue;
  104.                 }
  105.  
  106.                 int k1 = par1World.getBlockId(par2 + i * k, par3 + i1, par4 + j * k);
  107.  
  108.                 if (flag)
  109.                 {
  110.                     if (k1 != Block.obsidian.blockID)
  111.                     {
  112.                         return false;
  113.                     }
  114.  
  115.                     continue;
  116.                 }
  117.  
  118.                 if (k1 != 0 && k1 != Block.fire.blockID)
  119.                 {
  120.                     return false;
  121.                 }
  122.             }
  123.         }
  124.  
  125.         par1World.editingBlocks = true;
  126.  
  127.         for (int l = 0; l < 2; l++)
  128.         {
  129.             for (int j1 = 0; j1 < 3; j1++)
  130.             {
  131.                 par1World.setBlockWithNotify(par2 + i * l, par3 + j1, par4 + j * l, Block.portal.blockID);
  132.             }
  133.         }
  134.  
  135.         par1World.editingBlocks = false;
  136.         return true;
  137.     }
  138.  
  139.     /**
  140.      * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
  141.      * their own) Args: x, y, z, neighbor blockID
  142.      */
  143.     public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5)
  144.     {
  145.         int i = 0;
  146.         int j = 1;
  147.  
  148.         if (par1World.getBlockId(par2 - 1, par3, par4) == blockID || par1World.getBlockId(par2 + 1, par3, par4) == blockID)
  149.         {
  150.             i = 1;
  151.             j = 0;
  152.         }
  153.  
  154.         int k;
  155.  
  156.         for (k = par3; par1World.getBlockId(par2, k - 1, par4) == blockID; k--) { }
  157.  
  158.         if (par1World.getBlockId(par2, k - 1, par4) != Block.obsidian.blockID)
  159.         {
  160.             par1World.setBlockWithNotify(par2, par3, par4, 0);
  161.             return;
  162.         }
  163.  
  164.         int l;
  165.  
  166.         for (l = 1; l < 4 && par1World.getBlockId(par2, k + l, par4) == blockID; l++) { }
  167.  
  168.         if (l != 3 || par1World.getBlockId(par2, k + l, par4) != Block.obsidian.blockID)
  169.         {
  170.             par1World.setBlockWithNotify(par2, par3, par4, 0);
  171.             return;
  172.         }
  173.  
  174.         boolean flag = par1World.getBlockId(par2 - 1, par3, par4) == blockID || par1World.getBlockId(par2 + 1, par3, par4) == blockID;
  175.         boolean flag1 = par1World.getBlockId(par2, par3, par4 - 1) == blockID || par1World.getBlockId(par2, par3, par4 + 1) == blockID;
  176.  
  177.         if (flag && flag1)
  178.         {
  179.             par1World.setBlockWithNotify(par2, par3, par4, 0);
  180.             return;
  181.         }
  182.  
  183.         if ((par1World.getBlockId(par2 + i, par3, par4 + j) != Block.obsidian.blockID || par1World.getBlockId(par2 - i, par3, par4 - j) != blockID) && (par1World.getBlockId(par2 - i, par3, par4 - j) != Block.obsidian.blockID || par1World.getBlockId(par2 + i, par3, par4 + j) != blockID))
  184.         {
  185.             par1World.setBlockWithNotify(par2, par3, par4, 0);
  186.             return;
  187.         }
  188.         else
  189.         {
  190.             return;
  191.         }
  192.     }
  193.  
  194.     /**
  195.      * Returns true if the given side of this block type should be rendered, if the adjacent block is at the given
  196.      * coordinates.  Args: blockAccess, x, y, z, side
  197.      */
  198.     public boolean shouldSideBeRendered(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5)
  199.     {
  200.         if (par1IBlockAccess.getBlockId(par2, par3, par4) == blockID)
  201.         {
  202.             return false;
  203.         }
  204.  
  205.         boolean flag = par1IBlockAccess.getBlockId(par2 - 1, par3, par4) == blockID && par1IBlockAccess.getBlockId(par2 - 2, par3, par4) != blockID;
  206.         boolean flag1 = par1IBlockAccess.getBlockId(par2 + 1, par3, par4) == blockID && par1IBlockAccess.getBlockId(par2 + 2, par3, par4) != blockID;
  207.         boolean flag2 = par1IBlockAccess.getBlockId(par2, par3, par4 - 1) == blockID && par1IBlockAccess.getBlockId(par2, par3, par4 - 2) != blockID;
  208.         boolean flag3 = par1IBlockAccess.getBlockId(par2, par3, par4 + 1) == blockID && par1IBlockAccess.getBlockId(par2, par3, par4 + 2) != blockID;
  209.         boolean flag4 = flag || flag1;
  210.         boolean flag5 = flag2 || flag3;
  211.  
  212.         if (flag4 && par5 == 4)
  213.         {
  214.             return true;
  215.         }
  216.  
  217.         if (flag4 && par5 == 5)
  218.         {
  219.             return true;
  220.         }
  221.  
  222.         if (flag5 && par5 == 2)
  223.         {
  224.             return true;
  225.         }
  226.  
  227.         return flag5 && par5 == 3;
  228.     }
  229.  
  230.     /**
  231.      * Returns the quantity of items to drop on block destruction.
  232.      */
  233.     public int quantityDropped(Random par1Random)
  234.     {
  235.         return 0;
  236.     }
  237.  
  238.     /**
  239.      * Returns which pass should this block be rendered on. 0 for solids and 1 for alpha
  240.      */
  241.     public int getRenderBlockPass()
  242.     {
  243.         return 1;
  244.     }
  245.  
  246.     /**
  247.      * Triggered whenever an entity collides with this block (enters into the block). Args: world, x, y, z, entity
  248.      */
  249.     public void onEntityCollidedWithBlock(World par1World, int par2, int par3, int par4, Entity par5Entity)
  250.     {
  251.         if (par5Entity.ridingEntity == null && par5Entity.riddenByEntity == null)
  252.         {
  253.             par5Entity.setInPortal();
  254.         }
  255.     }
  256.  
  257.     /**
  258.      * A randomly called display update to be able to add particles or other items for display
  259.      */
  260.     public void randomDisplayTick(World par1World, int par2, int par3, int par4, Random par5Random)
  261.     {
  262.         if (par5Random.nextInt(100) == 0)
  263.         {
  264.             par1World.playSoundEffect((double)par2 + 0.5D, (double)par3 + 0.5D, (double)par4 + 0.5D, "portal.portal", 0.5F, par5Random.nextFloat() * 0.4F + 0.8F);
  265.         }
  266.  
  267.         for (int i = 0; i < 4; i++)
  268.         {
  269.             double d = (float)par2 + par5Random.nextFloat();
  270.             double d1 = (float)par3 + par5Random.nextFloat();
  271.             double d2 = (float)par4 + par5Random.nextFloat();
  272.             double d3 = 0.0D;
  273.             double d4 = 0.0D;
  274.             double d5 = 0.0D;
  275.             int j = par5Random.nextInt(2) * 2 - 1;
  276.             d3 = ((double)par5Random.nextFloat() - 0.5D) * 0.5D;
  277.             d4 = ((double)par5Random.nextFloat() - 0.5D) * 0.5D;
  278.             d5 = ((double)par5Random.nextFloat() - 0.5D) * 0.5D;
  279.  
  280.             if (par1World.getBlockId(par2 - 1, par3, par4) == blockID || par1World.getBlockId(par2 + 1, par3, par4) == blockID)
  281.             {
  282.                 d2 = (double)par4 + 0.5D + 0.25D * (double)j;
  283.                 d5 = par5Random.nextFloat() * 2.0F * (float)j;
  284.             }
  285.             else
  286.             {
  287.                 d = (double)par2 + 0.5D + 0.25D * (double)j;
  288.                 d3 = par5Random.nextFloat() * 2.0F * (float)j;
  289.             }
  290.  
  291.             par1World.spawnParticle("portal", d, d1, d2, d3, d4, d5);
  292.         }
  293.     }
  294. }