Advertisement
Guest User

Desire Path code

a guest
Feb 21st, 2015
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.89 KB | None | 0 0
  1. package roadblock.block;
  2.  
  3. import java.util.List;
  4.  
  5. import net.minecraft.block.Block;
  6. import net.minecraft.block.material.Material;
  7. import net.minecraft.client.renderer.texture.IIconRegister;
  8. import net.minecraft.entity.Entity;
  9. import net.minecraft.entity.EntityLivingBase;
  10. import net.minecraft.entity.player.EntityPlayer;
  11. import net.minecraft.init.Blocks;
  12. import net.minecraft.item.ItemStack;
  13. import net.minecraft.potion.Potion;
  14. import net.minecraft.potion.PotionEffect;
  15. import net.minecraft.util.AxisAlignedBB;
  16. import net.minecraft.util.IIcon;
  17. import net.minecraft.world.ColorizerGrass;
  18. import net.minecraft.world.IBlockAccess;
  19. import net.minecraft.world.World;
  20. import roadblock.utils.Config;
  21. import roadblock.utils.Register;
  22. import cpw.mods.fml.common.registry.GameRegistry;
  23. import cpw.mods.fml.relauncher.Side;
  24. import cpw.mods.fml.relauncher.SideOnly;
  25.  
  26. public class Grassroad extends Block {
  27.  
  28.     private int speed;
  29.     private final String name = "Grassroad";
  30.     @SideOnly(Side.CLIENT)
  31.     private IIcon top;
  32.     @SideOnly(Side.CLIENT)
  33.     private IIcon top_overlay;
  34.     @SideOnly(Side.CLIENT)
  35.     private IIcon field_149993_M;
  36.     @SideOnly(Side.CLIENT)
  37.     public IIcon side_overlay;
  38.  
  39.     public Grassroad() {
  40.         super(Material.grass);
  41.  
  42.         GameRegistry.registerBlock(this, name).setStepSound(
  43.                 Block.soundTypeGrass);
  44.         setBlockName(name);
  45.         setCreativeTab(Register.tabRoadBlock);
  46.         setLightOpacity(255);
  47.         useNeighborBrightness = true;
  48.         setHardness(1.5F);
  49.     }
  50.  
  51.     private boolean isFullRoad(IBlockAccess type, int x, int y, int z) {
  52.         Block block = type.getBlock(x, y, z);
  53.         // add blocks here that wont make a road a full block
  54.         return block == Blocks.fence_gate || block == Blocks.air
  55.                 || block == Blocks.torch;
  56.     }
  57.  
  58.     @Override
  59.     public int damageDropped(int meta) {
  60.         return meta;
  61.     }
  62.  
  63.     public void setBlockBoundsBasedOnState(IBlockAccess block, int x, int y,
  64.             int z) {
  65.         int meta = block.getBlockMetadata(x, y, z);
  66.         boolean airabove = this.isFullRoad(block, x, y + 1, z);
  67.         float f4;
  68.  
  69.         if (!airabove) {
  70.             f4 = 1.0F;
  71.         } else {
  72.             if (meta == 0) {
  73.                 f4 = 0.9375F;
  74.             } else {
  75.                 f4 = 0.4375F;
  76.             }
  77.         }
  78.         this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, f4, 1.0F);
  79.     }
  80.  
  81.     @SuppressWarnings({ "rawtypes" })
  82.     public void addCollisionBoxesToList(World world, int x, int y, int z,
  83.             AxisAlignedBB axisAlignedBB, List list, Entity entity) {
  84.         setBlockBoundsBasedOnState(world, x, y, z);
  85.         super.addCollisionBoxesToList(world, x, y, z, axisAlignedBB, list,
  86.                 entity);
  87.     }
  88.  
  89.     @Override
  90.     public boolean onBlockActivated(World world, int xCoord, int yCoord,
  91.             int zCoord, EntityPlayer player, int p_149727_6, float p_149727_7,
  92.             float p_149727_8, float p_149727_9) {
  93.         Block block1 = world.getBlock(xCoord, yCoord, zCoord);
  94.  
  95.         if (!world.isRemote) {
  96.             ItemStack stack = player.getHeldItem();
  97.             if (stack != null && stack.getItem() == Register.ironMallet
  98.                     || stack.getItem() == Register.goldMallet
  99.                     || stack.getItem() == Register.diamondMallet) {
  100.                 int meta = world.getBlockMetadata(xCoord, yCoord, zCoord);
  101.  
  102.                 switch (meta) {
  103.  
  104.                 case 0:
  105.                     // System.out.println("Metadata Value: " + meta);
  106.                     world.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 1,
  107.                             2);
  108.                     world.markBlockForUpdate(xCoord, yCoord, zCoord);
  109.                     world.playSoundEffect((double) ((float) xCoord + 0.5F),
  110.                             (double) ((float) yCoord + 0.5F),
  111.                             (double) ((float) zCoord + 0.5F),
  112.                             block1.stepSound.getStepResourcePath(),
  113.                             (block1.stepSound.getVolume() + 1.0F) / 2.0F,
  114.                             block1.stepSound.getPitch() * 0.8F);
  115.                     stack.damageItem(1, player);
  116.                     break;
  117.                 case 1:
  118.                     // System.out.println("Metadata Value: " + meta);
  119.                     world.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 0,
  120.                             2);
  121.                     world.markBlockForUpdate(xCoord, yCoord, zCoord);
  122.                     world.playSoundEffect((double) ((float) xCoord + 0.5F),
  123.                             (double) ((float) yCoord + 0.5F),
  124.                             (double) ((float) zCoord + 0.5F),
  125.                             block1.stepSound.getStepResourcePath(),
  126.                             (block1.stepSound.getVolume() + 1.0F) / 2.0F,
  127.                             block1.stepSound.getPitch() * 0.8F);
  128.                     stack.damageItem(1, player);
  129.                     break;
  130.                 case 2:
  131.                     // System.out.println("Metadata Value: " + meta);
  132.                     break;
  133.  
  134.                 }
  135.             }
  136.         }
  137.  
  138.         return true;
  139.     }
  140.  
  141.     public boolean isOpaqueCube() {
  142.         return false;
  143.     }
  144.  
  145.     public boolean renderAsNormalBlock() {
  146.         return false;
  147.     }
  148.  
  149.     public void onEntityCollidedWithBlock(World world, int xCoord, int yCoord,
  150.             int zCoord, Entity entity) {
  151.         if (Config.speedOn) {
  152.             if (entity instanceof EntityLivingBase) {
  153.                 if (Config.speed > 9) {
  154.                     speed = 9;
  155.                 } else {
  156.                     speed = Config.speed;
  157.                 }
  158.                 ((EntityLivingBase) entity).addPotionEffect(new PotionEffect(
  159.                         Potion.moveSpeed.id, 0, speed));
  160.             }
  161.         }
  162.     }
  163.  
  164.     @SideOnly(Side.CLIENT)
  165.     public void setBlockBoundsForItemRender() {
  166.         setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.9375F, 1.0F);
  167.     }
  168.  
  169.     @SideOnly(Side.CLIENT)
  170.     public IIcon getIcon(int side, int meta) {
  171.         return side == 1 ? this.top : (side == 0 ? Blocks.dirt
  172.                 .getBlockTextureFromSide(side) : this.blockIcon);
  173.     }
  174.  
  175.     @SideOnly(Side.CLIENT)
  176.     public IIcon getIcon(IBlockAccess world, int xCoord, int yCoord,
  177.             int zCoord, int par5) {
  178.         if (par5 == 1) {
  179.             return this.top;
  180.         } else if (par5 == 0) {
  181.             return Blocks.dirt.getBlockTextureFromSide(par5);
  182.  
  183.         }
  184.         return blockIcon;
  185.     }
  186.  
  187.     @SideOnly(Side.CLIENT)
  188.     public void registerBlockIcons(IIconRegister regIcon) {
  189.         this.blockIcon = regIcon.registerIcon("grass_side");
  190.         this.top = regIcon.registerIcon("roadblock:grassroad_top");
  191.         this.top_overlay = regIcon.registerIcon("roadblock:grassroad_top_overlay");
  192.         this.side_overlay = regIcon.registerIcon("grass_side_overlay");
  193.     }
  194.  
  195.     @SideOnly(Side.CLIENT)
  196.     public int getBlockColor() {
  197.         double d0 = 0.5D;
  198.         double d1 = 1.0D;
  199.         return ColorizerGrass.getGrassColor(d0, d1);
  200.     }
  201.  
  202.     /**
  203.      * Returns the color this block should be rendered. Used by leaves.
  204.      */
  205.     @SideOnly(Side.CLIENT)
  206.     public int getRenderColor(int p_149741_1_) {
  207.         return this.getBlockColor();
  208.     }
  209.  
  210.     /**
  211.      * Returns a integer with hex for 0xrrggbb with this color multiplied
  212.      * against the blocks color. Note only called when first determining what to
  213.      * render.
  214.      */
  215.     @SideOnly(Side.CLIENT)
  216.     public int colorMultiplier(IBlockAccess world, int xCoord, int yCoord,
  217.             int zCoord) {
  218.         int l = 0;
  219.         int i1 = 0;
  220.         int j1 = 0;
  221.  
  222.         for (int k1 = -1; k1 <= 1; ++k1) {
  223.             for (int l1 = -1; l1 <= 1; ++l1) {
  224.                 int i2 = world.getBiomeGenForCoords(xCoord + l1, zCoord + k1)
  225.                         .getBiomeGrassColor(xCoord + l1, yCoord, zCoord + k1);
  226.                 l += (i2 & 16711680) >> 16;
  227.                 i1 += (i2 & 65280) >> 8;
  228.                 j1 += i2 & 255;
  229.             }
  230.         }
  231.  
  232.         return (l / 9 & 255) << 16 | (i1 / 9 & 255) << 8 | j1 / 9 & 255;
  233.     }
  234.  
  235.     @SideOnly(Side.CLIENT)
  236.     public IIcon getIconSideOverlay() {
  237.         return this.side_overlay;
  238.     }
  239.  
  240.     @SideOnly(Side.CLIENT)
  241.     public IIcon getIconTopOverlay() {
  242.         return this.top_overlay;
  243.     }
  244.  
  245. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement