Advertisement
robin4002

Untitled

Mar 6th, 2014
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.11 KB | None | 0 0
  1. package fr.mcnanotech.privatizer.common;
  2.  
  3. import java.util.Random;
  4.  
  5. import net.minecraft.block.Block;
  6. import net.minecraft.block.material.Material;
  7. import net.minecraft.client.renderer.IconFlipped;
  8. import net.minecraft.client.renderer.texture.IIconRegister;
  9. import net.minecraft.creativetab.CreativeTabs;
  10. import net.minecraft.entity.player.EntityPlayer;
  11. import net.minecraft.init.Items;
  12. import net.minecraft.item.Item;
  13. import net.minecraft.util.AxisAlignedBB;
  14. import net.minecraft.util.IIcon;
  15. import net.minecraft.util.MovingObjectPosition;
  16. import net.minecraft.util.Vec3;
  17. import net.minecraft.world.IBlockAccess;
  18. import net.minecraft.world.World;
  19. import cpw.mods.fml.relauncher.Side;
  20. import cpw.mods.fml.relauncher.SideOnly;
  21.  
  22. public class BlockPrivateDoor extends Block
  23. {
  24.     @SideOnly(Side.CLIENT)
  25.     private IIcon[] upperIcon;
  26.     @SideOnly(Side.CLIENT)
  27.     private IIcon[] lowerIcon;
  28.  
  29.     protected BlockPrivateDoor(Material material)
  30.     {
  31.         super(material);
  32.         float f = 0.5F;
  33.         float f1 = 1.0F;
  34.         this.setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, f1, 0.5F + f);
  35.         this.setCreativeTab(CreativeTabs.tabBlock);
  36.     }
  37.  
  38.     @SideOnly(Side.CLIENT)
  39.     public IIcon getIcon(int side, int metadata)
  40.     {
  41.         return this.lowerIcon[0];
  42.     }
  43.  
  44.     @SideOnly(Side.CLIENT)
  45.     public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side)
  46.     {
  47.         if(side != 1 && side != 0)
  48.         {
  49.             int i1 = this.func_150012_g(world, x, y, z);
  50.             int j1 = i1 & 3;
  51.             boolean flag = (i1 & 4) != 0;
  52.             boolean flag1 = false;
  53.             boolean flag2 = (i1 & 8) != 0;
  54.  
  55.             if(flag)
  56.             {
  57.                 if(j1 == 0 && side == 2)
  58.                 {
  59.                     flag1 = !flag1;
  60.                 }
  61.                 else if(j1 == 1 && side == 5)
  62.                 {
  63.                     flag1 = !flag1;
  64.                 }
  65.                 else if(j1 == 2 && side == 3)
  66.                 {
  67.                     flag1 = !flag1;
  68.                 }
  69.                 else if(j1 == 3 && side == 4)
  70.                 {
  71.                     flag1 = !flag1;
  72.                 }
  73.             }
  74.             else
  75.             {
  76.                 if(j1 == 0 && side == 5)
  77.                 {
  78.                     flag1 = !flag1;
  79.                 }
  80.                 else if(j1 == 1 && side == 3)
  81.                 {
  82.                     flag1 = !flag1;
  83.                 }
  84.                 else if(j1 == 2 && side == 4)
  85.                 {
  86.                     flag1 = !flag1;
  87.                 }
  88.                 else if(j1 == 3 && side == 2)
  89.                 {
  90.                     flag1 = !flag1;
  91.                 }
  92.  
  93.                 if((i1 & 16) != 0)
  94.                 {
  95.                     flag1 = !flag1;
  96.                 }
  97.             }
  98.  
  99.             return flag2 ? this.upperIcon[flag1 ? 1 : 0] : this.lowerIcon[flag1 ? 1 : 0];
  100.         }
  101.         else
  102.         {
  103.             return this.lowerIcon[0];
  104.         }
  105.     }
  106.  
  107.     @SideOnly(Side.CLIENT)
  108.     public void registerBlockIcons(IIconRegister iiconRegister)
  109.     {
  110.         this.upperIcon = new IIcon[2];
  111.         this.lowerIcon = new IIcon[2];
  112.         this.upperIcon[0] = iiconRegister.registerIcon(PrivatizerMod.MODID + ":private_door_upper");
  113.         this.lowerIcon[0] = iiconRegister.registerIcon(PrivatizerMod.MODID + ":private_door_lower");
  114.         this.upperIcon[1] = new IconFlipped(this.upperIcon[0], true, false);
  115.         this.lowerIcon[1] = new IconFlipped(this.lowerIcon[0], true, false);
  116.     }
  117.  
  118.     public boolean isOpaqueCube()
  119.     {
  120.         return false;
  121.     }
  122.    
  123.     public boolean renderAsNormalBlock()
  124.     {
  125.         return false;
  126.     }
  127.  
  128.     public int getRenderType()
  129.     {
  130.         return 7;
  131.     }
  132.  
  133.     public boolean getBlocksMovement(IBlockAccess world, int x, int y, int z)
  134.     {
  135.         int l = this.func_150012_g(world, x, y, z);
  136.         return (l & 4) != 0;
  137.     }
  138.  
  139.     @SideOnly(Side.CLIENT)
  140.     public AxisAlignedBB getSelectedBoundingBoxFromPool(World world, int x, int y, int z)
  141.     {
  142.         this.setBlockBoundsBasedOnState(world, x, y, z);
  143.         return super.getSelectedBoundingBoxFromPool(world, x, y, z);
  144.     }
  145.  
  146.     public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z)
  147.     {
  148.         this.setBlockBoundsBasedOnState(world, x, y, z);
  149.         return super.getCollisionBoundingBoxFromPool(world, x, y, z);
  150.     }
  151.  
  152.     public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z)
  153.     {
  154.         this.func_150011_b(this.func_150012_g(world, x, y, z));
  155.     }
  156.  
  157.     public boolean func_150015_f(IBlockAccess world, int x, int y, int z)
  158.     {
  159.         return (this.func_150012_g(world, x, y, z) & 4) != 0;
  160.     }
  161.  
  162.     private void func_150011_b(int p_150011_1_)
  163.     {
  164.         float f = 0.1875F;
  165.         this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 2.0F, 1.0F);
  166.         int j = p_150011_1_ & 3;
  167.         boolean flag = (p_150011_1_ & 4) != 0;
  168.         boolean flag1 = (p_150011_1_ & 16) != 0;
  169.  
  170.         if(j == 0)
  171.         {
  172.             if(flag)
  173.             {
  174.                 if(!flag1)
  175.                 {
  176.                     this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f);
  177.                 }
  178.                 else
  179.                 {
  180.                     this.setBlockBounds(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F);
  181.                 }
  182.             }
  183.             else
  184.             {
  185.                 this.setBlockBounds(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F);
  186.             }
  187.         }
  188.         else if(j == 1)
  189.         {
  190.             if(flag)
  191.             {
  192.                 if(!flag1)
  193.                 {
  194.                     this.setBlockBounds(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
  195.                 }
  196.                 else
  197.                 {
  198.                     this.setBlockBounds(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F);
  199.                 }
  200.             }
  201.             else
  202.             {
  203.                 this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f);
  204.             }
  205.         }
  206.         else if(j == 2)
  207.         {
  208.             if(flag)
  209.             {
  210.                 if(!flag1)
  211.                 {
  212.                     this.setBlockBounds(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F);
  213.                 }
  214.                 else
  215.                 {
  216.                     this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f);
  217.                 }
  218.             }
  219.             else
  220.             {
  221.                 this.setBlockBounds(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
  222.             }
  223.         }
  224.         else if(j == 3)
  225.         {
  226.             if(flag)
  227.             {
  228.                 if(!flag1)
  229.                 {
  230.                     this.setBlockBounds(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F);
  231.                 }
  232.                 else
  233.                 {
  234.                     this.setBlockBounds(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
  235.                 }
  236.             }
  237.             else
  238.             {
  239.                 this.setBlockBounds(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F);
  240.             }
  241.         }
  242.     }
  243.  
  244.     public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ)
  245.     {
  246.         if(this.blockMaterial == Material.iron)
  247.         {
  248.             return false; // Allow items to interact with the door
  249.         }
  250.         else
  251.         {
  252.             int i1 = this.func_150012_g(world, x, y, z);
  253.             int j1 = i1 & 7;
  254.             j1 ^= 4;
  255.  
  256.             if((i1 & 8) == 0)
  257.             {
  258.                 world.setBlockMetadataWithNotify(x, y, z, j1, 2);
  259.                 world.markBlockRangeForRenderUpdate(x, y, z, x, y, z);
  260.             }
  261.             else
  262.             {
  263.                 world.setBlockMetadataWithNotify(x, y - 1, z, j1, 2);
  264.                 world.markBlockRangeForRenderUpdate(x, y - 1, z, x, y, z);
  265.             }
  266.  
  267.             world.playAuxSFXAtEntity(player, 1003, x, y, z, 0);
  268.             return true;
  269.         }
  270.     }
  271.  
  272.     public void func_150014_a(World world, int x, int y, int z, boolean powered)
  273.     {
  274.         int l = this.func_150012_g(world, x, y, z);
  275.         boolean flag1 = (l & 4) != 0;
  276.  
  277.         if(flag1 != powered)
  278.         {
  279.             int i1 = l & 7;
  280.             i1 ^= 4;
  281.  
  282.             if((l & 8) == 0)
  283.             {
  284.                 world.setBlockMetadataWithNotify(x, y, z, i1, 2);
  285.                 world.markBlockRangeForRenderUpdate(x, y, z, x, y, z);
  286.             }
  287.             else
  288.             {
  289.                 world.setBlockMetadataWithNotify(x, y - 1, z, i1, 2);
  290.                 world.markBlockRangeForRenderUpdate(x, y - 1, z, x, y, z);
  291.             }
  292.  
  293.             world.playAuxSFXAtEntity((EntityPlayer)null, 1003, x, y, z, 0);
  294.         }
  295.     }
  296.  
  297.     public void onNeighborBlockChange(World world, int x, int y, int z, Block block)
  298.     {
  299.         int l = world.getBlockMetadata(x, y, z);
  300.  
  301.         if((l & 8) == 0)
  302.         {
  303.             boolean flag = false;
  304.  
  305.             if(world.getBlock(x, y + 1, z) != this)
  306.             {
  307.                 world.setBlockToAir(x, y, z);
  308.                 flag = true;
  309.             }
  310.  
  311.             if(!World.doesBlockHaveSolidTopSurface(world, x, y - 1, z))
  312.             {
  313.                 world.setBlockToAir(x, y, z);
  314.                 flag = true;
  315.  
  316.                 if(world.getBlock(x, y + 1, z) == this)
  317.                 {
  318.                     world.setBlockToAir(x, y + 1, z);
  319.                 }
  320.             }
  321.  
  322.             if(flag)
  323.             {
  324.                 if(!world.isRemote)
  325.                 {
  326.                     this.dropBlockAsItem(world, x, y, z, l, 0);
  327.                 }
  328.             }
  329.             else
  330.             {
  331.                 boolean powered = world.isBlockIndirectlyGettingPowered(x, y, z) || world.isBlockIndirectlyGettingPowered(x, y + 1, z);
  332.  
  333.                 if((powered || block.canProvidePower()) && block != this)
  334.                 {
  335.                     this.func_150014_a(world, x, y, z, powered);
  336.                 }
  337.             }
  338.         }
  339.         else
  340.         {
  341.             if(world.getBlock(x, y - 1, z) != this)
  342.             {
  343.                 world.setBlockToAir(x, y, z);
  344.             }
  345.  
  346.             if(block != this)
  347.             {
  348.                 this.onNeighborBlockChange(world, x, y - 1, z, block);
  349.             }
  350.         }
  351.     }
  352.  
  353.     public Item getItemDropped(int metadata, Random rand, int fortune)
  354.     {
  355.         return (metadata & 8) != 0 ? null : Item.getItemFromBlock(this);
  356.     }
  357.  
  358.     public MovingObjectPosition collisionRayTrace(World world, int x, int y, int z, Vec3 vec3, Vec3 vec32)
  359.     {
  360.         this.setBlockBoundsBasedOnState(world, x, y, z);
  361.         return super.collisionRayTrace(world, x, y, z, vec3, vec32);
  362.     }
  363.  
  364.     public boolean canPlaceBlockAt(World world, int x, int y, int z)
  365.     {
  366.         return y >= 255 ? false : World.doesBlockHaveSolidTopSurface(world, x, y - 1, z) && super.canPlaceBlockAt(world, x, y, z) && super.canPlaceBlockAt(world, x, y + 1, z);
  367.     }
  368.  
  369.     public int getMobilityFlag()
  370.     {
  371.         return 1;
  372.     }
  373.  
  374.     public int func_150012_g(IBlockAccess world, int x, int y, int z)
  375.     {
  376.         int meta = world.getBlockMetadata(x, y, z);
  377.         boolean topBlock = (meta & 8) != 0;
  378.         int i1;
  379.         int j1;
  380.  
  381.         if(topBlock)
  382.         {
  383.             i1 = world.getBlockMetadata(x, y - 1, z);
  384.             j1 = meta;
  385.         }
  386.         else
  387.         {
  388.             i1 = meta;
  389.             j1 = world.getBlockMetadata(x, y + 1, z);
  390.         }
  391.  
  392.         boolean flag1 = (j1 & 1) != 0;
  393.         return i1 & 7 | (topBlock ? 8 : 0) | (flag1 ? 16 : 0);
  394.     }
  395.  
  396.     public void onBlockHarvested(World world, int x, int y, int z, int metadata, EntityPlayer player)
  397.     {
  398.         if(player.capabilities.isCreativeMode && (metadata & 8) != 0 && world.getBlock(x, y - 1, z) == this)
  399.         {
  400.             world.setBlockToAir(x, y - 1, z);
  401.         }
  402.     }
  403. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement