Advertisement
Guest User

BlockCagedLadder

a guest
Aug 10th, 2015
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 24.67 KB | None | 0 0
  1. package com.thecodewarrior.catwalks;
  2.  
  3. import java.util.HashMap;
  4. import java.util.LinkedList;
  5. import java.util.List;
  6. import java.util.Map;
  7. import java.util.Set;
  8.  
  9. import buildcraft.api.tools.IToolWrench;
  10. import net.minecraft.block.Block;
  11. import net.minecraft.block.material.Material;
  12. import net.minecraft.client.renderer.texture.IIconRegister;
  13. import net.minecraft.creativetab.CreativeTabs;
  14. import net.minecraft.entity.Entity;
  15. import net.minecraft.entity.EntityLivingBase;
  16. import net.minecraft.entity.item.EntityItem;
  17. import net.minecraft.entity.player.EntityPlayer;
  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.util.ForgeDirection;
  29. import codechicken.lib.raytracer.ExtendedMOP;
  30. import codechicken.lib.raytracer.IndexedCuboid6;
  31. import codechicken.lib.raytracer.RayTracer;
  32. import codechicken.lib.vec.BlockCoord;
  33. import codechicken.lib.vec.Cuboid6;
  34. import codechicken.lib.vec.Vector3;
  35. import cpw.mods.fml.common.eventhandler.SubscribeEvent;
  36. import cpw.mods.fml.relauncher.Side;
  37. import cpw.mods.fml.relauncher.SideOnly;
  38.  
  39. public class BlockCagedLadder extends Block implements ICustomLadderVelocity, ICagedLadderConnectable {
  40.  
  41.     RayTracer rayTracer = new RayTracer();
  42.    
  43.     public ForgeDirection direction;
  44.     public boolean lights;
  45.    
  46.     public IIcon bottom;
  47.     public IIcon bottom_with_lights;
  48.     public IIcon bottom_lights;
  49.    
  50.     public IIcon ladder;
  51.     public IIcon ladder_with_lights;
  52.     public IIcon ladder_lights;
  53.    
  54.     public IIcon front;
  55.     public IIcon front_with_lights;
  56.     public IIcon front_lights;
  57.    
  58.     public IIcon side;
  59.     public IIcon side_with_lights;
  60.     public IIcon side_lights;
  61.    
  62.     public IIcon landing;
  63.     public IIcon landing_side;
  64.    
  65.     public IIcon transparent;
  66.    
  67.     public Map<RelativeSide, Cuboid6> closed = new HashMap<RelativeSide, Cuboid6>();
  68.     public Map<RelativeSide, Cuboid6>   open = new HashMap<RelativeSide, Cuboid6>();
  69.    
  70.     // meta: bottom, front, left, right
  71.    
  72.     public BlockCagedLadder(ForgeDirection direction, boolean lights) {
  73.         super(Material.iron);
  74.         setHardness(1.0F);
  75.         setStepSound(Block.soundTypeMetal);
  76.         float px = 1/16F;
  77.         setBlockBounds(px, 0, px, 1-px, 1, 1-px);
  78.         setBlockName("cagedladder");
  79.         setStepSound(soundTypeLadder);
  80.         if(direction == ForgeDirection.NORTH && !lights)
  81.             setCreativeTab(CreativeTabs.tabTransport);
  82.         setHarvestLevel("wrench", 0);
  83.         setHarvestLevel("pickaxe", 0);
  84.         this.lights = lights;
  85.         this.direction = direction;
  86.         initHitBoxes();
  87.     }
  88.    
  89.     //==============================================================================
  90.     // Place/Destroy methods
  91.     //==============================================================================
  92.    
  93.     @Override
  94.     public void onBlockPlacedBy(World w, int x, int y, int z, EntityLivingBase e, ItemStack s) {
  95.         updateNeighborSides(w,x,y,z,true);
  96.     }
  97.  
  98.     public void onBlockDestroyedByPlayer(World w, int x, int y, int z, int meta) {
  99.         updateNeighborSides(w,x,y,z,false);
  100.     }
  101.  
  102.     public void onBlockDestroyedByExplosion(World w, int x, int y, int z, Explosion e) {
  103.         updateNeighborSides(w,x,y,z,false);
  104.     }
  105.    
  106.     public void updateNeighborSides(World world, int x, int y, int z, boolean self) {
  107.         Block b = world.getBlock(x, y+1, z);
  108.         if(b instanceof BlockCagedLadder) {
  109. //          this.updateOpenData(world, x, y+1, z, RelativeSide.BOTTOM, false);
  110. //          System.out.println("---");
  111.             ( (BlockCagedLadder)b ).updateBottom(world, x, y+1, z);
  112. //          System.out.println("---");
  113.         }
  114.         if(self)
  115.             this.updateBottom(world, x, y, z);
  116.     }
  117.    
  118.     public void updateBottom(World world, int x, int y, int z) {
  119. //      System.out.println("UPD");
  120.         if(world.getBlock(x, y-1, z) instanceof BlockCagedLadder) {
  121.             updateOpenData(world, x, y, z, RelativeSide.BOTTOM, true);
  122.         } else {
  123.             updateOpenData(world, x, y, z, RelativeSide.BOTTOM, false);
  124.         }
  125.     }
  126.  
  127.     //==============================================================================
  128.     // Clicking methods
  129.     //==============================================================================
  130.    
  131.     public float getPlayerRelativeBlockHardness(EntityPlayer player, World world, int x, int y, int z){
  132.         int metadata = world.getBlockMetadata(x, y, z);
  133.         float hardness = blockHardness;
  134.        
  135.         if(player.getHeldItem() != null ) {
  136.             boolean shouldBeSoft = false;
  137.             if(player.getHeldItem().getItem() instanceof IToolWrench)
  138.                 shouldBeSoft = true;
  139.             Set<String> toolClasses = player.getHeldItem().getItem().getToolClasses(player.getHeldItem());
  140.             if(toolClasses.contains("wrench"))
  141.                 shouldBeSoft = true;
  142.            
  143.             if(shouldBeSoft)
  144.                 hardness = blockHardness/10;
  145.         }
  146.  
  147.         return player.getBreakSpeed(this, false, metadata, x, y, z) / hardness / 30F;
  148.     }
  149.    
  150.     @Override
  151.     public void onBlockClicked(World world, int x, int y, int z, EntityPlayer player) {
  152.         MovingObjectPosition hit = RayTracer.retraceBlock(world, player, x, y, z);
  153.        
  154.         RelativeSide side = RelativeSide.TOP;
  155.         if (hit != null) {
  156.             side = (RelativeSide) ( (ExtendedMOP) hit ).data;
  157.         }
  158.        
  159. //      if(player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() instanceof IToolWrench) {
  160. //          if(player.isSneaking()) {
  161. //
  162. //              this.dropBlockAsItem(world, x, y, z, 0, 0);
  163. //              world.setBlockToAir(x,y,z);
  164. //              this.updateNeighborSides(world, x, y, z, false);
  165. //          }
  166. //      }
  167.     }
  168.  
  169.     @Override
  170.     public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int blockSide, float hitX, float hitY, float hitZ) {
  171.         MovingObjectPosition hit = RayTracer.retraceBlock(world, player, x, y, z);
  172.        
  173.         RelativeSide side = RelativeSide.TOP;
  174.         if (hit != null) {
  175.             side = (RelativeSide) ( (ExtendedMOP) hit ).data;
  176.         }
  177. //      System.out.println(side);
  178.        
  179.         ItemStack handStack = player.getCurrentEquippedItem();
  180.         if(handStack != null && handStack.getItem() instanceof IToolWrench) {
  181.             if(player.isSneaking()) {
  182.                 if(this.lights) {
  183.                     if(!world.isRemote) {
  184.                         world.spawnEntityInWorld(new EntityItem(world, x+0.5, y+0.5, z+0.5, new ItemStack(CatwalkMod.itemRopeLight, 1)));
  185.                         updateIdData(world, x, y, z, direction, false);
  186.                     }
  187.                 }
  188.             } else {
  189. //              System.out.println("META:  " + world.getBlockMetadata(x,y,z));
  190.                 updateOpenData(world, x, y, z, side, !isOpen(side, world.getBlockMetadata(x, y, z)));
  191. //              System.out.println("META2: " + world.getBlockMetadata(x,y,z));
  192.             }
  193.         }
  194.        
  195.         if(player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() instanceof ItemRopeLight && this.lights == false) {
  196.             updateIdData(world, x, y, z, direction, true);
  197.             if(!player.capabilities.isCreativeMode)
  198.                 player.getCurrentEquippedItem().stackSize--;
  199.         }
  200.        
  201.         return false;
  202.     }
  203.    
  204.     //==============================================================================
  205.     // Ladder methods
  206.     //==============================================================================
  207.    
  208.     @Override
  209.     public boolean isOnLadder(IBlockAccess world, int x, int y, int z, EntityLivingBase entity)
  210.     {
  211.         float px = 1/16F;
  212.         float px2 = 2*px;
  213.         float d = px*3;
  214.         return CatwalkMod.options.fullBlockLadder || entity.boundingBox.intersectsWith(AxisAlignedBB.getBoundingBox(x+d, y, z+d, x+1-d, y+1, z+1-d));
  215.     }
  216.    
  217.     public double getLadderVelocity(IBlockAccess world, int x, int y, int z, EntityLivingBase entity) {
  218.         return entity.isSneaking() ? 0.15D : 0.25D;
  219.     }
  220.    
  221.     public double getLadderFallVelocity(IBlockAccess world, int x, int y, int z, EntityLivingBase entity) {
  222.         return 0.25D;
  223.     }
  224.    
  225.  
  226.     //==============================================================================
  227.     // Block highlight raytrace methods
  228.     //==============================================================================
  229.    
  230.     public void initHitBoxes() {       
  231.         double in = 1/32D;
  232.         double out  = 3/32D;
  233.        
  234.         closed.put(RelativeSide.FDtoRS(ForgeDirection.NORTH, direction), new Cuboid6(
  235.                 in,   0, in,
  236.                 1-in, 1, out
  237.                 )
  238.         );
  239.        
  240.         closed.put(RelativeSide.FDtoRS(ForgeDirection.SOUTH, direction), new Cuboid6(
  241.                 in,   0, 1-out,
  242.                 1-in, 1, 1-in
  243.                 )
  244.         );
  245.        
  246.         closed.put(RelativeSide.FDtoRS(ForgeDirection.WEST, direction), new Cuboid6(
  247.                 in,  0, in,
  248.                 out, 1, 1-in
  249.                 )
  250.         );
  251.        
  252.         closed.put(RelativeSide.FDtoRS(ForgeDirection.EAST, direction), new Cuboid6(
  253.                 1-in,  0, in,
  254.                 1-out, 1, 1-in
  255.                 )
  256.         );
  257.        
  258.         closed.put(RelativeSide.FDtoRS(ForgeDirection.DOWN, direction), new Cuboid6(
  259.                 in,   0,   in,
  260.                 1-in, out, 1-in
  261.                 )
  262.         );
  263.        
  264.         closed.put(RelativeSide.FDtoRS(ForgeDirection.UP, direction), new Cuboid6(
  265.                 in,   1-out,   in,
  266.                 1-in, 1, 1-in
  267.                 )
  268.         );
  269.        
  270.         open.put(RelativeSide.FRONT, getOpenHighlightCuboid(open, RelativeSide.FRONT, direction) );
  271.         open.put(RelativeSide.LEFT, getOpenHighlightCuboid(open, RelativeSide.LEFT, direction) );
  272.         open.put(RelativeSide.RIGHT, getOpenHighlightCuboid(open, RelativeSide.RIGHT, direction) );
  273.         open.put(RelativeSide.BOTTOM, getOpenHighlightCuboid(open, RelativeSide.BOTTOM, direction) );
  274.         open.put(RelativeSide.TOP, getOpenHighlightCuboid(open, RelativeSide.TOP, direction) );
  275.     }
  276.  
  277.     public Cuboid6 getOpenHighlightCuboid(Map<RelativeSide, Cuboid6> map, RelativeSide side, ForgeDirection facing) {
  278. //      double width = 0.25D;
  279.         double sub = 11/16D;//1-(1/16D)-width;
  280.         double frontSub = sub/2;
  281.        
  282.         Cuboid6 cuboid = closed.get(side).copy();
  283.         if(side == RelativeSide.LADDER)
  284.             return cuboid;
  285.            
  286.         if(side == RelativeSide.TOP) {
  287.             cuboid.min.x += frontSub;
  288.             cuboid.min.z += frontSub;
  289.  
  290.             cuboid.max.x -= frontSub;
  291.             cuboid.max.z -= frontSub;
  292.         } else if(side != RelativeSide.FRONT) {
  293.             if(facing.offsetX < 0) {
  294.                 cuboid.min.x += sub;
  295.             }
  296.             if(facing.offsetX > 0) {
  297.                 cuboid.max.x -= sub;
  298.             }
  299.            
  300.             if(facing.offsetZ < 0) {
  301.                 cuboid.max.z -= sub;
  302.             }
  303.             if(facing.offsetZ > 0) {
  304.                 cuboid.min.z += sub;
  305.             }
  306.         } else {
  307.             if(facing.offsetX != 0) {
  308.                 cuboid.min.z += frontSub;
  309.                 cuboid.max.z -= frontSub;
  310.             }
  311.             if(facing.offsetZ != 0) {
  312.                 cuboid.min.x += frontSub;
  313.                 cuboid.max.x -= frontSub;
  314.             }
  315.         }
  316.         return cuboid;
  317.     }
  318.  
  319.     @Override
  320.     public MovingObjectPosition collisionRayTrace(World world, int x, int y, int z, Vec3 start, Vec3 end) {
  321.         List<IndexedCuboid6> cuboids = new LinkedList<IndexedCuboid6>();
  322.        
  323.         float ym = 1;
  324.        
  325.         float px = 1/16F;
  326.         float px2 = 2*px;
  327.  
  328.         float outsideDistance = 1/32F;
  329.         float insideDistance  = 3/32F;
  330.        
  331.         float out = px/2;
  332.         float in = out+px;
  333.        
  334.         int meta = world.getBlockMetadata(x, y, z);
  335.        
  336.         if(!(world.getBlock(x, y+1, z) instanceof BlockCagedLadder)) {
  337.             addToList(x, y, z, cuboids, RelativeSide.TOP, open.get(RelativeSide.TOP));
  338.         }
  339.        
  340.         for (RelativeSide rs : RelativeSide.values()) {
  341.             if(rs == RelativeSide.LADDER) {
  342.                 addToList(x, y, z, cuboids, rs, closed.get(rs));
  343.                 continue;
  344.             }
  345.             if(rs == RelativeSide.TOP) {
  346.                 continue;
  347.             }
  348.             if(isOpen(rs, meta)) {
  349.                 addToList(x, y, z, cuboids, rs, open.get(rs));
  350.             } else {
  351.                 addToList(x, y, z, cuboids, rs, closed.get(rs));
  352.             }
  353.         }
  354.        
  355.         ExtendedMOP mop = (ExtendedMOP) rayTracer.rayTraceCuboids(new Vector3(start), new Vector3(end), cuboids, new BlockCoord(x, y, z), this);
  356.         if(mop != null) {
  357.             if(mop.sideHit == RelativeSide.RStoFD( (RelativeSide)mop.data, direction).getOpposite().ordinal()) {
  358.                 mop.sideHit = ForgeDirection.getOrientation(mop.sideHit).getOpposite().ordinal();
  359.             }
  360.         }
  361.         //        System.out.println(mop.data);
  362.         return mop;
  363.     }
  364.    
  365.     public void addToList(int x, int y, int z, List<IndexedCuboid6> list, Object data, Cuboid6 cuboid) {
  366.  
  367.         list.add( new IndexedCuboid6(data, new Cuboid6(
  368.                 x+cuboid.min.x, y+cuboid.min.y, z+cuboid.min.z,
  369.                 x+cuboid.max.x, y+cuboid.max.y, z+cuboid.max.z
  370.                 )) );
  371.     }
  372.    
  373.     @SideOnly(Side.CLIENT)
  374.     @SubscribeEvent
  375.     public void onBlockHighlight(DrawBlockHighlightEvent event) {
  376.         if (event.target.typeOfHit == MovingObjectType.BLOCK && event.player.worldObj.getBlock(event.target.blockX, event.target.blockY, event.target.blockZ) == this)
  377.             RayTracer.retraceBlock(event.player.worldObj, event.player, event.target.blockX, event.target.blockY, event.target.blockZ);
  378.     }
  379.    
  380.     //==============================================================================
  381.     // Texture methods
  382.     //==============================================================================
  383.    
  384.     @Override
  385.     public void registerBlockIcons(IIconRegister reg) {
  386.         transparent         = reg.registerIcon("catwalks:transparent");
  387.        
  388.         bottom              = reg.registerIcon("catwalks:ladder/bottom");
  389.         bottom_with_lights  = reg.registerIcon("catwalks:ladder/bottom_with_lights");
  390.         bottom_lights       = reg.registerIcon("catwalks:ladder/bottom_lights");
  391.        
  392.         ladder              = reg.registerIcon("catwalks:ladder/ladder");
  393.         ladder_with_lights  = reg.registerIcon("catwalks:ladder/ladder_with_lights");
  394.         ladder_lights       = reg.registerIcon("catwalks:ladder/ladder_lights");
  395.        
  396.         front               = reg.registerIcon("catwalks:ladder/front");
  397.         front_with_lights   = reg.registerIcon("catwalks:ladder/front_with_lights");
  398.         front_lights        = reg.registerIcon("catwalks:ladder/front_lights");
  399.        
  400.         side                = reg.registerIcon("catwalks:ladder/side");
  401.         side_with_lights    = reg.registerIcon("catwalks:ladder/side_with_lights");
  402.         side_lights         = reg.registerIcon("catwalks:ladder/side_lights");
  403.        
  404.         landing             = reg.registerIcon("catwalks:ladder/landing");
  405.         landing_side        = reg.registerIcon("catwalks:ladder/landing_side");
  406.     }
  407.    
  408.     @Override
  409.     public IIcon getIcon(int _side, int meta) {
  410.         RelativeSide dir = RelativeSide.FDtoRS( ForgeDirection.getOrientation(_side), direction );
  411.        
  412.         switch(dir) {
  413.         case LADDER:
  414.             if(lights)
  415.                 return ladder_with_lights;
  416.             else
  417.                 return ladder;
  418.         case FRONT:
  419.             if(lights)
  420.                 return front_with_lights;
  421.             else
  422.                 return front;
  423.         case LEFT:
  424.         case RIGHT:
  425.             if(lights)
  426.                 return side_with_lights;
  427.             else
  428.                 return side;
  429.         case BOTTOM:
  430.             if(lights)
  431.                 return bottom_with_lights;
  432.             else
  433.                 return bottom;
  434.         }
  435.        
  436.         return transparent;
  437.     }
  438.    
  439.     public IIcon getLightIcon(int _side, int meta) {
  440.         RelativeSide dir = RelativeSide.FDtoRS( ForgeDirection.getOrientation(_side) , direction);
  441.        
  442.         switch(dir) {
  443.         case LADDER:
  444.             return ladder_lights;
  445.         case FRONT:
  446.             return front_lights;
  447.         case LEFT:
  448.         case RIGHT:
  449.             return side_lights;
  450.         case BOTTOM:
  451.             return transparent;//bottom_lights;
  452.         }
  453.        
  454.         return transparent;
  455.     }
  456.  
  457.     @Override
  458.     public boolean isSideSolid(IBlockAccess w, int x, int y, int z, ForgeDirection side) {
  459.         if(side == ForgeDirection.UP)
  460.             return false;
  461.         return !isOpen(RelativeSide.FDtoRS(side, direction), w.getBlockMetadata(x,y,z));
  462.     }
  463.  
  464.     @SideOnly(Side.CLIENT)
  465.     public boolean shouldSideBeRendered(IBlockAccess w, int x, int y, int z, int _side)
  466.     {
  467.         ForgeDirection dir = ForgeDirection.getOrientation(_side);
  468.         if(dir == ForgeDirection.DOWN) {
  469.             if(w.isSideSolid(x, y, z, ForgeDirection.DOWN, false))
  470.                 return false;
  471.         }
  472.         int meta = w.getBlockMetadata(x-dir.offsetX, y-dir.offsetY, z-dir.offsetZ);
  473.    
  474.         if(isOpen(RelativeSide.FDtoRS(dir, direction), meta)) {
  475.             return false;
  476.         }
  477.        
  478.         return true;
  479.     }
  480.    
  481.    
  482.     //==============================================================================
  483.     // Collision methods
  484.     //==============================================================================
  485.    
  486.     @Override
  487.     public void addCollisionBoxesToList(World world, int x, int y, int z, AxisAlignedBB blockBounds, List list, Entity collidingEntity) {
  488.         if(collidingEntity == null)
  489.             return;
  490.    
  491.         float px = 1/16F;
  492.        
  493.         float out = px;///2;
  494.         float in = out+px;
  495.        
  496.         int meta = world.getBlockMetadata(x, y, z);
  497.        
  498.         if(!isOpen(RelativeSide.FDtoRS(ForgeDirection.NORTH, direction), meta)) {
  499.             addToList(world, x, y, z, blockBounds, list, out, 0, out, 1-out, 1, in);
  500.         }
  501.        
  502.         if(!isOpen(RelativeSide.FDtoRS(ForgeDirection.SOUTH, direction), meta)) {
  503.             addToList(world, x, y, z, blockBounds, list, out, 0, 1-out, 1-out, 1, 1-in);
  504.         }
  505.        
  506.         if(!isOpen(RelativeSide.FDtoRS(ForgeDirection.EAST, direction), meta)) {
  507.             addToList(world, x, y, z, blockBounds, list, 1-in, 0, out, 1-out, 1, 1-out);
  508.         }
  509.        
  510.         if(!isOpen(RelativeSide.FDtoRS(ForgeDirection.WEST, direction), meta)) {
  511.             addToList(world, x, y, z, blockBounds, list, out, 0, out, in, 1, 1-out);
  512.         }
  513.     }
  514.    
  515.     public void addToList(World world, int x, int y, int z, AxisAlignedBB blockBounds, List list, double minX, double minY, double minZ, double maxX, double maxY, double maxZ) {
  516.         AxisAlignedBB axisalignedbb1 = AxisAlignedBB.getBoundingBox(
  517.                 (double)x + minX, (double)y + minY, (double)z + minZ,
  518.                 (double)x + maxX, (double)y + maxY, (double)z + maxZ
  519.                 );
  520.                
  521.         if (axisalignedbb1 != null && blockBounds.intersectsWith(axisalignedbb1))
  522.         {
  523.             list.add(axisalignedbb1);
  524.         }
  525.     }
  526.    
  527.     @Override
  528.     public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity) {
  529.        
  530. //      System.out.println("COLLIDE!");
  531.     }
  532.    
  533.     //==============================================================================
  534.     // Data manipulation methods
  535.     //==============================================================================
  536.    
  537.     public int setBit(int val, int pos, boolean value) {
  538.         if(value)
  539.             return val |  (1 << pos);
  540.         else
  541.             return val & ~(1 << pos);
  542.     }
  543.  
  544.     public boolean getBit(int val, int pos) {
  545.         return ( val & (1 << pos) ) > 0;
  546.     }
  547.  
  548.     public boolean isOpen(RelativeSide side, int meta) {
  549.         switch(side) {
  550.         case BOTTOM:
  551.             return getBit(meta, 3);
  552.         case FRONT:
  553.             return getBit(meta, 2);
  554.         case LEFT:
  555.             return getBit(meta, 1);
  556.         case RIGHT:
  557.             return getBit(meta, 0);
  558.         default:
  559.             return false;
  560.         }
  561.     }
  562.    
  563.     public boolean isOpen(ForgeDirection side, int meta) {
  564.         return isOpen(RelativeSide.FDtoRS(side, direction), meta);
  565.     }
  566.    
  567.     public void updateOpenData(World world, int x, int y, int z, RelativeSide side, boolean value) {
  568.         int meta = world.getBlockMetadata(x, y, z);
  569.         switch(side) {
  570.         case BOTTOM:
  571.             meta = setBit(meta, 3, value);
  572.             break;
  573.         case FRONT:
  574.             meta = setBit(meta, 2, value);
  575.             break;
  576.         case LEFT:
  577.             meta = setBit(meta, 1, value);
  578.             break;
  579.         case RIGHT:
  580.             meta = setBit(meta, 0, value);
  581.             break;
  582.         }
  583.         world.setBlock(x, y, z, this, meta, 3);
  584.     }
  585.  
  586.     public void updateIdData(World world, int x, int y, int z, ForgeDirection facing, boolean lights) {
  587.         int meta = world.getBlockMetadata(x,y,z);
  588.         Block b = this;
  589.         switch(facing) {
  590.         case NORTH:
  591.             if(lights)
  592.                 b = CatwalkMod.ladderNorthLit;
  593.             else
  594.                 b = CatwalkMod.ladderNorthUnlit;
  595.             break;
  596.         case SOUTH:
  597.             if(lights)
  598.                 b = CatwalkMod.ladderSouthLit;
  599.             else
  600.                 b = CatwalkMod.ladderSouthUnlit;
  601.             break;
  602.         case EAST:
  603.             if(lights)
  604.                 b = CatwalkMod.ladderEastLit;
  605.             else
  606.                 b = CatwalkMod.ladderEastUnlit;
  607.             break;
  608.         case WEST:
  609.             if(lights)
  610.                 b = CatwalkMod.ladderWestLit;
  611.             else
  612.                 b = CatwalkMod.ladderWestUnlit;
  613.             break;
  614.         default:
  615.         }
  616.        
  617.         world.setBlock(x, y, z, b, meta, 3);
  618.     }
  619.    
  620.     //==============================================================================
  621.     // Render type methods
  622.     //==============================================================================
  623.  
  624.     public int getRenderType(){
  625.         return CatwalkMod.ladderRenderType;
  626.     }
  627.    
  628.     @SideOnly(Side.CLIENT)
  629.     public int getRenderBlockPass()
  630.     {
  631.         return 0;
  632.     }
  633.  
  634.     public boolean isOpaqueCube()
  635.     {
  636.         return false;
  637.     }
  638.  
  639.     @SideOnly(Side.CLIENT)
  640.     public boolean isBlockNormalCube()
  641.     {
  642.         return super.isBlockNormalCube();
  643.     }
  644.  
  645.     public boolean isNormalCube()
  646.     {
  647.         return false;
  648.     }
  649.  
  650.     public static enum RelativeSide {
  651.         LADDER, FRONT, LEFT, RIGHT, TOP, BOTTOM;
  652.        
  653.         public static RelativeSide FDtoRS(ForgeDirection side, ForgeDirection facing) {
  654.             switch(facing) {
  655.             case NORTH:
  656.                 switch(side) {
  657.                 case NORTH:
  658.                     return RelativeSide.LADDER;
  659.                 case SOUTH:
  660.                     return RelativeSide.FRONT;
  661.                 case EAST:
  662.                     return RelativeSide.RIGHT;
  663.                 case WEST:
  664.                     return RelativeSide.LEFT;
  665.                 case UP:
  666.                     return RelativeSide.TOP;
  667.                 case DOWN:
  668.                     return RelativeSide.BOTTOM;
  669.                 }
  670.             case SOUTH:
  671.                 switch(side) {
  672.                 case NORTH:
  673.                     return RelativeSide.FRONT;
  674.                 case SOUTH:
  675.                     return RelativeSide.LADDER;
  676.                 case EAST:
  677.                     return RelativeSide.LEFT;
  678.                 case WEST:
  679.                     return RelativeSide.RIGHT;
  680.                 case UP:
  681.                     return RelativeSide.TOP;
  682.                 case DOWN:
  683.                     return RelativeSide.BOTTOM;
  684.                 }
  685.             case EAST:
  686.                 switch(side) {
  687.                 case NORTH:
  688.                     return RelativeSide.RIGHT;
  689.                 case SOUTH:
  690.                     return RelativeSide.LEFT;
  691.                 case EAST:
  692.                     return RelativeSide.FRONT;
  693.                 case WEST:
  694.                     return RelativeSide.LADDER;
  695.                 case UP:
  696.                     return RelativeSide.TOP;
  697.                 case DOWN:
  698.                     return RelativeSide.BOTTOM;
  699.                 }
  700.             case WEST:
  701.                 switch(side) {
  702.                 case NORTH:
  703.                     return RelativeSide.LEFT;
  704.                 case SOUTH:
  705.                     return RelativeSide.RIGHT;
  706.                 case EAST:
  707.                     return RelativeSide.LADDER;
  708.                 case WEST:
  709.                     return RelativeSide.FRONT;
  710.                 case UP:
  711.                     return RelativeSide.TOP;
  712.                 case DOWN:
  713.                     return RelativeSide.BOTTOM;
  714.                 }
  715.             default:
  716.                 switch(side) {
  717.                 case NORTH:
  718.                     return RelativeSide.LADDER;
  719.                 case SOUTH:
  720.                     return RelativeSide.FRONT;
  721.                 case EAST:
  722.                     return RelativeSide.RIGHT;
  723.                 case WEST:
  724.                     return RelativeSide.LEFT;
  725.                 case UP:
  726.                     return RelativeSide.TOP;
  727.                 case DOWN:
  728.                     return RelativeSide.BOTTOM;
  729.                 }
  730.             }
  731.             return RelativeSide.BOTTOM;
  732.         }
  733.    
  734.         public static ForgeDirection RStoFD(RelativeSide side, ForgeDirection facing) {
  735.             switch(facing) {
  736.             case NORTH:
  737.                 switch(side) {
  738.                 case LADDER:
  739.                     return ForgeDirection.NORTH;
  740.                 case FRONT:
  741.                     return ForgeDirection.SOUTH;
  742.                 case RIGHT:
  743.                     return ForgeDirection.EAST;
  744.                 case LEFT:
  745.                     return ForgeDirection.WEST;
  746.                 case TOP:
  747.                     return ForgeDirection.UP;
  748.                 case BOTTOM:
  749.                     return ForgeDirection.DOWN;
  750.                 }
  751.             case SOUTH:
  752.                 switch(side) {
  753.                 case FRONT:
  754.                     return ForgeDirection.NORTH;
  755.                 case LADDER:
  756.                     return ForgeDirection.SOUTH;
  757.                 case LEFT:
  758.                     return ForgeDirection.EAST;
  759.                 case RIGHT:
  760.                     return ForgeDirection.WEST;
  761.                 case TOP:
  762.                     return ForgeDirection.UP;
  763.                 case BOTTOM:
  764.                     return ForgeDirection.DOWN;
  765.                 }
  766.             case EAST:
  767.                 switch(side) {
  768.                 case RIGHT:
  769.                     return ForgeDirection.NORTH;
  770.                 case LEFT:
  771.                     return ForgeDirection.SOUTH;
  772.                 case FRONT:
  773.                     return ForgeDirection.EAST;
  774.                 case LADDER:
  775.                     return ForgeDirection.WEST;
  776.                 case TOP:
  777.                     return ForgeDirection.UP;
  778.                 case BOTTOM:
  779.                     return ForgeDirection.DOWN;
  780.                 }
  781.             case WEST:
  782.                 switch(side) {
  783.                 case LEFT:
  784.                     return ForgeDirection.NORTH;
  785.                 case RIGHT:
  786.                     return ForgeDirection.SOUTH;
  787.                 case LADDER:
  788.                     return ForgeDirection.EAST;
  789.                 case FRONT:
  790.                     return ForgeDirection.WEST;
  791.                 case TOP:
  792.                     return ForgeDirection.UP;
  793.                 case BOTTOM:
  794.                     return ForgeDirection.DOWN;
  795.                 }
  796.             default:
  797.                 switch(side) {
  798.                 case LADDER:
  799.                     return ForgeDirection.NORTH;
  800.                 case FRONT:
  801.                     return ForgeDirection.SOUTH;
  802.                 case RIGHT:
  803.                     return ForgeDirection.EAST;
  804.                 case LEFT:
  805.                     return ForgeDirection.WEST;
  806.                 case TOP:
  807.                     return ForgeDirection.UP;
  808.                 case BOTTOM:
  809.                     return ForgeDirection.DOWN;
  810.                 }
  811.             }
  812.             return ForgeDirection.DOWN;
  813.         }
  814.     }
  815.    
  816.     //==============================================================================
  817.     // ICagedLadderConnectable
  818.     //==============================================================================
  819.    
  820.     @Override
  821.     public boolean shouldConnectToSide(IBlockAccess w, int x, int y, int z,
  822.             ForgeDirection side) {
  823.         return isOpen(RelativeSide.FDtoRS(side, direction), w.getBlockMetadata(x,y,z));
  824.     }
  825.  
  826.     @Override
  827.     public boolean shouldHaveBottom(IBlockAccess w, int x, int y, int z,
  828.             ForgeDirection side) {
  829.         if( !isOpen(RelativeSide.BOTTOM, w.getBlockMetadata(x,y,z)) )
  830.             return true;
  831.         Block b = w.getBlock(x,y-1,z);
  832.         if( b instanceof ICagedLadderConnectable) {
  833.             System.out.println(side);
  834.             if( ((ICagedLadderConnectable)b).doesSideHaveWall(w, x, y-1, z, side) ) {
  835.                 return true;
  836.             }
  837.         }
  838.         return false;
  839.     }
  840.    
  841.     @Override
  842.     public boolean doesSideHaveWall(IBlockAccess w, int x, int y, int z,
  843.             ForgeDirection side) {
  844.         return !isOpen(RelativeSide.FDtoRS(side, direction), w.getBlockMetadata(x,y,z));
  845.     }
  846.    
  847.     @Override
  848.     public boolean isThin(IBlockAccess w, int x, int y, int z, ForgeDirection side) {
  849.         return true;
  850.     }
  851. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement