Advertisement
Guest User

BlockCatwalk

a guest
Aug 10th, 2015
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 20.33 KB | None | 0 0
  1. package com.thecodewarrior.catwalks;
  2.  
  3.  
  4. import java.util.ArrayList;
  5. import java.util.LinkedList;
  6. import java.util.List;
  7. import java.util.Set;
  8.  
  9. import net.minecraft.block.Block;
  10. import net.minecraft.block.material.Material;
  11. import net.minecraft.client.renderer.texture.IIconRegister;
  12. import net.minecraft.creativetab.CreativeTabs;
  13. import net.minecraft.entity.Entity;
  14. import net.minecraft.entity.EntityLivingBase;
  15. import net.minecraft.entity.item.EntityItem;
  16. import net.minecraft.entity.player.EntityPlayer;
  17. import net.minecraft.item.Item;
  18. import net.minecraft.item.ItemStack;
  19. import net.minecraft.util.AxisAlignedBB;
  20. import net.minecraft.util.IIcon;
  21. import net.minecraft.util.MovingObjectPosition;
  22. import net.minecraft.util.MovingObjectPosition.MovingObjectType;
  23. import net.minecraft.util.Vec3;
  24. import net.minecraft.world.Explosion;
  25. import net.minecraft.world.IBlockAccess;
  26. import net.minecraft.world.World;
  27. import net.minecraftforge.client.event.DrawBlockHighlightEvent;
  28. import net.minecraftforge.common.ForgeHooks;
  29. import net.minecraftforge.common.util.ForgeDirection;
  30. import net.minecraftforge.event.ForgeEventFactory;
  31. import buildcraft.api.tools.IToolWrench;
  32. import codechicken.lib.raytracer.ExtendedMOP;
  33. import codechicken.lib.raytracer.IndexedCuboid6;
  34. import codechicken.lib.raytracer.RayTracer;
  35. import codechicken.lib.vec.BlockCoord;
  36. import codechicken.lib.vec.Cuboid6;
  37. import codechicken.lib.vec.Vector3;
  38. import cpw.mods.fml.common.FMLCommonHandler;
  39. import cpw.mods.fml.common.eventhandler.SubscribeEvent;
  40. import cpw.mods.fml.relauncher.Side;
  41. import cpw.mods.fml.relauncher.SideOnly;
  42.  
  43. public class BlockCatwalk extends Block implements ICagedLadderConnectable {
  44.     public boolean lights;
  45.     public boolean bottom;
  46.    
  47.     private RayTracer rayTracer = new RayTracer();
  48.    
  49.    
  50.     public IIcon transparent;
  51.  
  52.     public IIcon sideTexture;
  53.     public IIcon bottomTexture;
  54.    
  55.     public IIcon bottomTextureWithLights;
  56.     public IIcon sideTextureWithLights;
  57.    
  58.     public IIcon bottomLights;
  59.     public IIcon sideLights;
  60.        
  61.     public BlockCatwalk(boolean lights, boolean bottom) {
  62.         super(Material.iron);
  63.         setHardness(1.0F);
  64.         setStepSound(Block.soundTypeMetal);
  65.         setBlockName("catwalk");
  66.         if(lights && !bottom)
  67.             setCreativeTab(CreativeTabs.tabTransport);
  68. //      setHarvestLevel("wrench", 0);
  69. //      setHarvestLevel("pickaxe", 0);
  70.         this.lights = lights;
  71.         this.bottom = bottom;
  72.     }
  73.    
  74.     //==============================================================================
  75.     // Clicking methods
  76.     //==============================================================================
  77.    
  78.     public float getPlayerRelativeBlockHardness(EntityPlayer player, World world, int x, int y, int z){
  79.         int metadata = world.getBlockMetadata(x, y, z);
  80.         float hardness = blockHardness;
  81.        
  82.         if(player.getHeldItem() != null ) {
  83.             boolean shouldBeSoft = false;
  84.             if(player.getHeldItem().getItem() instanceof IToolWrench)
  85.                 shouldBeSoft = true;
  86.             Set<String> toolClasses = player.getHeldItem().getItem().getToolClasses(player.getHeldItem());
  87.             if(toolClasses.contains("wrench"))
  88.                 shouldBeSoft = true;
  89.            
  90.             if(shouldBeSoft)
  91.                 hardness = blockHardness/10;
  92.         }
  93.  
  94.         return player.getBreakSpeed(this, false, metadata, x, y, z) / hardness / 30F;
  95.     }
  96.    
  97.     @Override
  98.     public void onBlockClicked(World world, int x, int y, int z, EntityPlayer player) {
  99.         MovingObjectPosition hit = RayTracer.retraceBlock(world, player, x, y, z);
  100.        
  101.         ForgeDirection side = ForgeDirection.UP;
  102.         if (hit != null) {
  103.             side = (ForgeDirection) ( (ExtendedMOP) hit ).data;
  104.         }
  105.        
  106.         if(player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() instanceof IToolWrench) {
  107.             if(player.isSneaking()) {
  108.  
  109.                 this.dropBlockAsItem(world, x, y, z, 0, 0);
  110.                 world.setBlockToAir(x,y,z);
  111.                 this.updateNeighborSides(world, x, y, z, false);
  112.             }
  113.         }
  114.     }
  115.  
  116.    
  117.     @Override
  118.     public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int blockSide, float hitX, float hitY, float hitZ) {
  119.         MovingObjectPosition hit = RayTracer.retraceBlock(world, player, x, y, z);
  120.        
  121.         ForgeDirection side = ForgeDirection.UP;
  122.         if (hit != null) {
  123.             side = (ForgeDirection) ( (ExtendedMOP) hit ).data;
  124.         }
  125.        
  126.         if(player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() instanceof IToolWrench) {
  127.             if(player.isSneaking()) {
  128.                 if(this.lights) {
  129.                     if(!world.isRemote) {
  130.                         world.spawnEntityInWorld(new EntityItem(world, x+0.5, y+0.5, z+0.5, new ItemStack(CatwalkMod.itemRopeLight, 1)));
  131.                         updateData(world, x, y, z, ForgeDirection.UP, false, false);
  132.                     }
  133.                 }
  134.             } else {
  135.                 if(side != ForgeDirection.UP) {
  136.                     updateData(world,x,y,z, side, !getOpenState(world,x,y,z, side), this.lights);
  137.                 }
  138.             }
  139.         }
  140.        
  141.         if(player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() instanceof ItemRopeLight && this.lights == false) {
  142.             updateData(world, x, y, z, ForgeDirection.UP, false, true);
  143.             if(!player.capabilities.isCreativeMode)
  144.                 player.getCurrentEquippedItem().stackSize--;
  145.         }
  146. //     
  147. //      if()
  148.        
  149.         return false;
  150.     }
  151.    
  152.     //==============================================================================
  153.     // Place/Destroy methods
  154.     //==============================================================================
  155.    
  156.     @Override
  157.     public void onBlockPlacedBy(World w, int x, int y, int z, EntityLivingBase e, ItemStack s) {
  158.         updateNeighborSides(w,x,y,z,true);
  159.     }
  160.  
  161.     public void onBlockDestroyedByPlayer(World w, int x, int y, int z, int meta) {
  162.         updateNeighborSides(w,x,y,z,false);
  163.     }
  164.  
  165.     public void onBlockDestroyedByExplosion(World w, int x, int y, int z, Explosion e) {
  166.         updateNeighborSides(w,x,y,z,false);
  167.     }
  168.  
  169.     //==============================================================================
  170.     // Drop methods
  171.     //==============================================================================
  172.    
  173.     public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune)
  174.     {
  175.         ArrayList<ItemStack> ret = new ArrayList<ItemStack>();
  176.    
  177.         ret.add(new ItemStack(
  178.                 Item.getItemFromBlock(CatwalkMod.catwalkUnlitBottom),
  179.                 1));
  180.         if(this.lights) {
  181.             ret.add(new ItemStack(
  182.                     CatwalkMod.itemRopeLight,
  183.                     1
  184.                 ));
  185.         }
  186.         return ret;
  187.     }
  188.  
  189.     public boolean canHarvestBlock(EntityPlayer player, int meta)
  190.     {
  191.         return true;
  192.     }
  193.    
  194.     //==============================================================================
  195.     // Block highlight raytrace methods
  196.     //==============================================================================
  197.    
  198.     @Override
  199.     public MovingObjectPosition collisionRayTrace(World world, int x, int y, int z, Vec3 start, Vec3 end) {
  200.         List<IndexedCuboid6> cuboids = new LinkedList<IndexedCuboid6>();
  201.        
  202.         float px = 1/16F;
  203.         int meta = world.getBlockMetadata(x, y, z);
  204. //      System.out.println("META: " + (meta & 8));
  205.         boolean ovr = false;
  206.         double d = 0;
  207.         float smallHeight = 0.25f;
  208.         if(bottom) {
  209.             d = 0.125;
  210.             //cuboids.add(new IndexedCuboid6(Hitboxes.BOTTOM, new Cuboid6(x+ px, y+ 0, z+ px, x+ 1-px, y+ px, z+ 1-px)));
  211.         } else {
  212.             d = 0.25;
  213.         }
  214.         cuboids.add(new IndexedCuboid6(ForgeDirection.DOWN, new Cuboid6(x+ d, y+ 0, z+ d, x+ 1-d, y+ px, z+ 1-d)));
  215.         float ym = 1;
  216.        
  217.         if((meta & 8) == 0 || ovr) { ym = 1; } else { ym = smallHeight; }
  218.         cuboids.add(new IndexedCuboid6(ForgeDirection.NORTH, new Cuboid6(
  219.                 x+ 0,   y+ 0,   z+ 0,
  220.                 x+ 1,   y+ ym,  z+ px
  221.             )));
  222.        
  223.        
  224.         if((meta & 4) == 0 || ovr) { ym = 1; } else { ym = smallHeight; }
  225.         cuboids.add(new IndexedCuboid6(ForgeDirection.SOUTH, new Cuboid6(
  226.                 x+ 0,   y+ 0,   z+ 1-px,
  227.                 x+ 1,   y+ ym,  z+ 1
  228.             )));
  229.        
  230.        
  231.         if((meta & 2) == 0 || ovr) { ym = 1; } else { ym = smallHeight; }
  232.         cuboids.add(new IndexedCuboid6(ForgeDirection.WEST, new Cuboid6(
  233.                 x+ 0,   y+ 0,   z+ 0,
  234.                 x+ px,  y+ ym,  z+ 1
  235.             )));
  236.        
  237.        
  238.         if((meta & 1) == 0 || ovr) { ym = 1; } else { ym = smallHeight; }
  239.         cuboids.add(new IndexedCuboid6(ForgeDirection.EAST, new Cuboid6(
  240.                 x+ 1-px, y+ 0,  z+ 0,
  241.                 x+ 1,    y+ ym,     z+ 1
  242.             )));
  243.         //new BlockCoord(x, y, z), this
  244.         ExtendedMOP mop = (ExtendedMOP) rayTracer.rayTraceCuboids(new Vector3(start), new Vector3(end), cuboids, new BlockCoord(x, y, z), this);
  245.         if(mop != null) {
  246.             if(mop.sideHit == ((ForgeDirection)mop.data).getOpposite().ordinal()) {
  247.                 mop.sideHit = ((ForgeDirection)mop.data).ordinal();
  248.            
  249.             }
  250.         }
  251.         //        System.out.println(mop.data);
  252.         return mop;
  253.     }
  254.    
  255.     @SideOnly(Side.CLIENT)
  256.     @SubscribeEvent
  257.     public void onBlockHighlight(DrawBlockHighlightEvent event) {
  258.         if (event.target.typeOfHit == MovingObjectType.BLOCK && event.player.worldObj.getBlock(event.target.blockX, event.target.blockY, event.target.blockZ) == this)
  259.             RayTracer.retraceBlock(event.player.worldObj, event.player, event.target.blockX, event.target.blockY, event.target.blockZ);
  260.     }
  261.    
  262.     //==============================================================================
  263.     // Collision methods
  264.     //==============================================================================
  265.        
  266.     @Override
  267.     public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity) {
  268.         if (FMLCommonHandler.instance().getEffectiveSide() != Side.CLIENT)
  269.             return;
  270.         double mul = 1.315;
  271.         if(entity instanceof EntityPlayer && ( (EntityPlayer)entity).isSneaking() ) {
  272.             mul = 2.860578;
  273.         }
  274.         CatwalkMod.proxy.speedupPlayer(world, entity, mul);
  275.     }
  276.  
  277.     @Override
  278.     public void addCollisionBoxesToList(World world, int x, int y, int z, AxisAlignedBB blockBounds, List list, Entity collidingEntity) {
  279.        
  280.         if(collidingEntity == null)
  281.             return;
  282.    
  283.         float px = 1/16F;
  284.         int meta = world.getBlockMetadata(x, y, z);
  285.         float top = 1.5F;
  286.         if(collidingEntity.isSneaking())
  287.             top = 1.0F;
  288.        
  289.         boolean ovr = false;
  290.         Cuboid6 oldBounds = new Cuboid6(
  291.                 this.getBlockBoundsMinX(), this.getBlockBoundsMinY(), this.getBlockBoundsMinZ(),
  292.                 this.getBlockBoundsMaxX(), this.getBlockBoundsMaxY(), this.getBlockBoundsMaxZ()
  293.             );
  294.         if(bottom) {
  295.             this.setBlockBounds(0, 0, 0, 1, px, 1);
  296.             super.addCollisionBoxesToList(world, x, y, z, blockBounds, list, collidingEntity);
  297.         }
  298.         if((meta & 8) == 0 || ovr) {
  299.             if(getStepConnect(world,x,y,z,ForgeDirection.NORTH)) {
  300.                 this.setBlockBounds(0, 0, 0, 1, 1, px);
  301.             } else {
  302.                 this.setBlockBounds(0, 0, 0, 1, top, px);
  303.             }
  304.             super.addCollisionBoxesToList(world, x, y, z, blockBounds, list, collidingEntity);
  305.         }
  306.         if((meta & 4) == 0 || ovr) {
  307.             if(getStepConnect(world,x,y,z,ForgeDirection.SOUTH)) {
  308.                 this.setBlockBounds(0, 0, 1-px, 1, 1, 1);
  309.             } else {
  310.                 this.setBlockBounds(0, 0, 1-px, 1, top, 1);
  311.             }
  312.             super.addCollisionBoxesToList(world, x, y, z, blockBounds, list, collidingEntity);
  313.         }
  314.         if((meta & 2) == 0 || ovr) {
  315.             if(getStepConnect(world,x,y,z,ForgeDirection.WEST)) {
  316.                 this.setBlockBounds(0, 0, 0, px, 1, 1);
  317.             } else {
  318.                 this.setBlockBounds(0, 0, 0, px, top, 1);
  319.             }
  320.             super.addCollisionBoxesToList(world, x, y, z, blockBounds, list, collidingEntity);
  321.         }
  322.         if((meta & 1) == 0 || ovr) {
  323.             if(getStepConnect(world,x,y,z,ForgeDirection.EAST)) {
  324.                 this.setBlockBounds(1-px, 0, 0, 1, 1, 1);
  325.             } else {
  326.                 this.setBlockBounds(1-px, 0, 0, 1, top, 1);            
  327.             }
  328.             super.addCollisionBoxesToList(world, x, y, z, blockBounds, list, collidingEntity);
  329.         }
  330.        
  331.         oldBounds.setBlockBounds(this);
  332. //      this.setBlockBounds(0, 0, 0, 1, 1, 1);
  333.     }
  334.  
  335.     public boolean getStepConnect(World w, int x, int y, int z, ForgeDirection direction) {
  336.         int newX = x+direction.offsetX,
  337.             newY = y+1,
  338.             newZ = z+direction.offsetZ;
  339.        
  340.         Block rawBlock = w.getBlock(newX, newY, newZ);
  341.         int meta = w.getBlockMetadata(newX, newY, newZ);
  342.         if(rawBlock instanceof BlockCatwalk) {
  343.             BlockCatwalk b = (BlockCatwalk) rawBlock;
  344.             return b.getOpenState(w, newX, newY, newZ, direction.getOpposite());
  345.         }
  346.        
  347.         return false;
  348.     }
  349.  
  350.     public boolean getBlocksMovement(IBlockAccess p_149655_1_, int p_149655_2_, int p_149655_3_, int p_149655_4_)
  351.     {
  352.         return false;
  353.     }
  354.  
  355.     //==============================================================================
  356.     // Texture methods
  357.     //==============================================================================
  358.    
  359.     @Override
  360.     public void registerBlockIcons(IIconRegister reg) {
  361.         transparent             = reg.registerIcon("catwalks:transparent");
  362.        
  363.         sideTexture             = reg.registerIcon("catwalks:side");
  364.         bottomTexture           = reg.registerIcon("catwalks:bottom");
  365.        
  366.         sideTextureWithLights   = reg.registerIcon("catwalks:side_with_lights");
  367.         bottomTextureWithLights = reg.registerIcon("catwalks:bottom_with_lights");
  368.        
  369.         sideLights              = reg.registerIcon("catwalks:side_lights");
  370.         bottomLights            = reg.registerIcon("catwalks:bottom_lights");
  371.     }
  372.  
  373.     @Override
  374.     public IIcon getIcon(int _side, int meta) {
  375.         ForgeDirection dir = ForgeDirection.VALID_DIRECTIONS[_side];
  376.         /**/
  377.         if(dir == ForgeDirection.DOWN) {
  378.             if(bottom) {
  379.                 return lights ? bottomTextureWithLights : bottomTexture;
  380.             }
  381.         }
  382.         if(dir == ForgeDirection.NORTH && (meta & 8) < 1) {
  383.             return lights ? sideTextureWithLights : sideTexture;
  384.         }
  385.         if(dir == ForgeDirection.SOUTH && (meta & 4) < 1) {
  386.             return lights ? sideTextureWithLights : sideTexture;
  387.         }
  388.         if(dir == ForgeDirection.WEST && (meta & 2) < 1) {
  389.             return lights ? sideTextureWithLights : sideTexture;
  390.         }
  391.         if(dir == ForgeDirection.EAST && (meta & 1) < 1) {
  392.             return lights ? sideTextureWithLights : sideTexture;
  393.         }
  394.         return transparent; /**/
  395.     }
  396.    
  397.     @Override
  398.     public boolean isSideSolid(IBlockAccess w, int x, int y, int z, ForgeDirection side) {
  399.         return !getOpenState(w,x,y,z,side);//getOpenState(w, x-side.offsetX, y-side.offsetY, z-side.offsetZ, side.getOpposite());
  400.     }
  401.  
  402.     @SideOnly(Side.CLIENT)
  403.     public boolean shouldSideBeRendered(IBlockAccess w, int x, int y, int z, int _side)
  404.     {
  405.         ForgeDirection dir = ForgeDirection.getOrientation(_side);
  406.         int meta = w.getBlockMetadata(x-dir.offsetX, y-dir.offsetY, z-dir.offsetZ);
  407.    
  408.         if(dir == ForgeDirection.DOWN && (
  409.                 bottom == false ||
  410.                 ( w.isSideSolid(x, y, z, ForgeDirection.UP, false) && !(w.getBlock(x,y,z) instanceof BlockCatwalk) )
  411.             )) {
  412.             return false;
  413.         }
  414.         if(dir == ForgeDirection.NORTH && (
  415.                 (meta & 8) > 0 ||
  416.                 ( w.isSideSolid(x, y, z, ForgeDirection.SOUTH, false) && !(w.getBlock(x,y,z) instanceof BlockCatwalk) )
  417.             )) {
  418.             return false;
  419.         }
  420.         if(dir == ForgeDirection.SOUTH && (
  421.                 (meta & 4) > 0 ||
  422.                 ( w.isSideSolid(x, y, z, ForgeDirection.NORTH, false) )// && !(w.getBlock(x,y,z) instanceof BlockCatwalk) )
  423.             )) {
  424.             return false;
  425.         }
  426.         if(dir == ForgeDirection.WEST && (
  427.                 (meta & 2) > 0 ||
  428.                 ( w.isSideSolid(x, y, z, ForgeDirection.EAST, false) && !(w.getBlock(x,y,z) instanceof BlockCatwalk) )
  429.             )) {
  430.             return false;
  431.         }
  432.         if(dir == ForgeDirection.EAST && (
  433.                 (meta & 1) > 0 ||
  434.                 ( w.isSideSolid(x, y, z, ForgeDirection.WEST, false) )// && !(w.getBlock(x,y,z) instanceof BlockCatwalk) )
  435.             )) {
  436.             return false;
  437.         }
  438.         return true;
  439.     }
  440.    
  441.    
  442.  
  443.     /**
  444.      * Gets the light value of the specified block coords. Args: x, y, z
  445.      */
  446.     public int getLightValue()
  447.     {
  448.         return this.lights ? 15 : 0;
  449.     }
  450.  
  451.     //==============================================================================
  452.     // Data update methods
  453.     //==============================================================================
  454.    
  455.     public void updateNeighborSides(World w, int x, int y, int z, boolean updateSelf) {
  456.         for (int i = 0; i < ForgeDirection.VALID_DIRECTIONS.length; i++) {
  457.             ForgeDirection dir = ForgeDirection.VALID_DIRECTIONS[i];
  458.             int newX = x + dir.offsetX;
  459.             int newY = y + dir.offsetY;
  460.             int newZ = z + dir.offsetZ;
  461.             Block b  = w.getBlock(newX,newY,newZ);
  462.             if(b instanceof BlockCatwalk)
  463.                 ((BlockCatwalk) b).updateOpenStatus(w,newX,newY,newZ, dir.getOpposite());
  464.            
  465.         }
  466.         if(updateSelf) {
  467.             for (int i = 0; i < ForgeDirection.VALID_DIRECTIONS.length; i++) {
  468.                 ForgeDirection dir = ForgeDirection.VALID_DIRECTIONS[i];
  469.                 this.updateOpenStatus(w, x, y, z, dir);
  470.             }
  471.             this.updateOpenStatus(w, x, y, z, ForgeDirection.DOWN);
  472.         }
  473.     }
  474.    
  475.     public void updateOpenStatus(World w, int x, int y, int z, ForgeDirection side) {
  476.         updateData(w,x,y,z,side, shouldBeOpen(w,x,y,z,side), this.lights);
  477.     }
  478.  
  479.     public void updateData(World w, int x, int y, int z, ForgeDirection side, boolean state, boolean lights) {
  480.         int meta = w.getBlockMetadata(x, y, z);
  481.         if(side == ForgeDirection.NORTH) {
  482.             if(state) {
  483.                 meta = meta | 8;  // 0b1000
  484.             } else {
  485.                 meta = meta & 7; // 0b0111
  486.             }
  487.         }
  488.         if(side == ForgeDirection.SOUTH) {
  489.             if(state) {
  490.                 meta = meta | 4;  // 0b0100
  491.             } else {
  492.                 meta = meta & 11; // 0b1011
  493.             }
  494.         }
  495.         if(side == ForgeDirection.WEST) {
  496.             if(state) {
  497.                 meta = meta | 2;  // 0b0010
  498.             } else {
  499.                 meta = meta & 13; // 0b1101
  500.             }
  501.         }
  502.         if(side == ForgeDirection.EAST) {
  503.             if(state) {
  504.                 meta = meta | 1;  // 0b0001
  505.             } else {
  506.                 meta = meta & 14; // 0b1110
  507.             }
  508.         }
  509.         Block block = this;
  510.         if(side == ForgeDirection.DOWN) {
  511.             if(state) {
  512.                 if(lights) {
  513.                     block = CatwalkMod.catwalkLitNoBottom;
  514.                 } else {
  515.                     block = CatwalkMod.catwalkUnlitNoBottom;
  516.                 }
  517.             } else {
  518.                 if(lights) {
  519.                     block = CatwalkMod.catwalkLitBottom;
  520.                 } else {
  521.                     block = CatwalkMod.catwalkUnlitBottom;
  522.                 }
  523.             }
  524.         } else {
  525.             if(!bottom) {
  526.                 if(lights) {
  527.                     block = CatwalkMod.catwalkLitNoBottom;
  528.                 } else {
  529.                     block = CatwalkMod.catwalkUnlitNoBottom;
  530.                 }
  531.             } else {
  532.                 if(lights) {
  533.                     block = CatwalkMod.catwalkLitBottom;
  534.                 } else {
  535.                     block = CatwalkMod.catwalkUnlitBottom;
  536.                 }
  537.             }
  538.         }
  539.         w.setBlock(x, y, z, block, meta, 3);
  540.     }
  541.  
  542.     public boolean shouldBeOpen(World w, int x, int y, int z, ForgeDirection direction) {
  543.         int newX = x + direction.offsetX;
  544.         int newY = y + direction.offsetY;
  545.         int newZ = z + direction.offsetZ;
  546.         if(w.getBlock(newX,newY,newZ) instanceof BlockCatwalk)
  547.             return true;
  548.         return false;
  549.     }
  550.  
  551.     public boolean getOpenState(IBlockAccess w, int x, int y, int z, ForgeDirection side) {
  552.         int meta = w.getBlockMetadata(x, y, z);
  553.    
  554.         if(side == ForgeDirection.DOWN && bottom == false) {
  555.             return true;
  556.         }
  557.         if(side == ForgeDirection.NORTH && (meta & 8) > 0) {
  558.             return true;
  559.         }
  560.         if(side == ForgeDirection.SOUTH && (meta & 4) > 0) {
  561.             return true;
  562.         }
  563.         if(side == ForgeDirection.WEST && (meta & 2) > 0) {
  564.             return true;
  565.         }
  566.         if(side == ForgeDirection.EAST && (meta & 1) > 0) {
  567.             return true;
  568.         }
  569.         return false;
  570.     }
  571.  
  572.     //==============================================================================
  573.     // Render type methods
  574.     //==============================================================================
  575.    
  576.     public int getRenderType(){
  577.         return CatwalkMod.catwalkRenderType;
  578.     }
  579.  
  580.     @SideOnly(Side.CLIENT)
  581.     public int getRenderBlockPass()
  582.     {
  583.         return 0;
  584.     }
  585.  
  586.     public boolean isOpaqueCube()
  587.     {
  588.         return false;
  589.     }
  590.    
  591.    
  592.  
  593.     //==============================================================================
  594.     // ICagedLadderConnectable
  595.     //==============================================================================
  596.    
  597.     @Override
  598.     public boolean shouldConnectToSide(IBlockAccess w, int x, int y, int z,
  599.             ForgeDirection side) {
  600.         return getOpenState(w, x, y, z, side);
  601.     }
  602.  
  603.     @Override
  604.     public boolean shouldHaveBottom(IBlockAccess w, int x, int y, int z,
  605.             ForgeDirection side) {
  606.         if(bottom)
  607.             return true;
  608.         Block b = w.getBlock(x,y-1,z);
  609.         if( b instanceof ICagedLadderConnectable) {
  610.             if( ((ICagedLadderConnectable)b).doesSideHaveWall(w, x, y, z, side) )
  611.                 return true;
  612.         }
  613.         return false;
  614.     }
  615.    
  616.     @Override
  617.     public boolean doesSideHaveWall(IBlockAccess w, int x, int y, int z,
  618.             ForgeDirection side) {
  619.         return !getOpenState(w, x, y, z, side);
  620.     }
  621.    
  622.     @Override
  623.     public boolean isThin(IBlockAccess w, int x, int y, int z, ForgeDirection side) {
  624.         return false;
  625.     }
  626. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement