303

Untitled

303
Mar 19th, 2011
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.56 KB | None | 0 0
  1. package net.minecraft.src;
  2.  
  3. public class mod_vine extends BaseMod {
  4.     public static Block vine = new BlockVine(126,
  5.             ModLoader.addOverride("/terrain.png","/vine/vine.png"))
  6.         .setBlockName("vine");
  7.  
  8.     public mod_vine() {
  9.         ModLoader.RegisterBlock(vine);
  10.         ModLoader.AddName(vine, "Vine");
  11.     }
  12.     public String Version() {
  13.         return "1.2_02v1";
  14.     }
  15.  
  16.     public void AddRecipes(CraftingManager recipes) {
  17.         recipes.addRecipe(new ItemStack(vine,64),
  18.                           new Object[] {"X", 'X', Block.dirt});
  19.     }
  20. }
  21.  
  22.  
  23. package net.minecraft.src;
  24. import java.util.Random;
  25.  
  26. public class BlockVine extends BlockLadder {
  27.     public float ascensionSpeed = 0.2F;
  28.     public float descensionSpeed = -0.15F;
  29.     public int tickrate = 20*20;
  30.     public int growChance = 5;
  31.  
  32.     public boolean debugVine = true;
  33.  
  34.     public BlockVine(int id, int sprite) {
  35.         super(id, sprite);
  36.         setHardness(0.4F);
  37.         setStepSound(soundWoodFootstep);
  38.         setTickOnLoad(true);
  39.     }
  40.  
  41.     public int tickRate() {
  42.         return tickrate;
  43.     }
  44.  
  45.     public void updateTick(World world, int i, int j, int k, Random random)
  46.     {
  47.         if (debugVine) {
  48.             ModLoader.getMinecraftInstance().effectRenderer.addBlockDestroyEffects(i,j,k);
  49.             world.playSoundEffect(i,j,k, "random.pop", 1F, 1F);
  50.         }
  51.  
  52.         System.out.format("update tick: %d %d %d\n", i,j,k);
  53.  
  54.         // bubble up
  55.         if (world.getBlockId(i,j+1,k) == blockID) {
  56.             System.out.println("bubble");
  57.  
  58.             int l;
  59.             for(l = 1; world.getBlockId(i, j + l, k) == blockID; l++);
  60.  
  61.             world.scheduleBlockUpdate(i, j+l-1, k, blockID, tickRate());
  62.             return;
  63.         }
  64.  
  65.         int meta = world.getBlockMetadata(i,j,k);
  66.  
  67.         if (!world.isAirBlock(i,j+1,k)) {
  68.             System.out.println("no air");
  69.             return;
  70.         }
  71.  
  72.         // can place block above
  73.         //if (!canVineGrow(world,i,j+1,k,meta)) {
  74.         if (!canPlaceBlockAt(world, i,j+1,k)) {
  75.             System.out.println("can't grow");
  76.             // try again later
  77.             world.scheduleBlockUpdate(i, j, k, blockID, tickRate());
  78.             return;
  79.         }
  80.            
  81.  
  82.         // find lowest non vine block
  83.         int l;
  84.         for(l = 1; world.getBlockId(i, j - l, k) == blockID; l++);
  85.  
  86.         // don't grow if not on ground
  87.         if (world.getBlockMaterial(i,j-l,k) != Material.ground) {
  88.             System.out.println("not on ground");
  89.             return;
  90.         }
  91.  
  92.         if (/*isWaterNearby(world, i, j-l, k) && */random.nextInt(growChance)==0) {
  93.             // grow one block, auto schedule
  94.             System.out.println("grown");
  95.             world.setBlockWithNotify(i, j+1, k, blockID);
  96.             onBlockPlaced(world,i,j+1,k,meta);
  97.         } else {
  98.             // try again
  99.             world.scheduleBlockUpdate(i, j, k, blockID, tickRate());
  100.         }
  101.     }
  102.  
  103.     /*private boolean isWaterNearby(World world, int i, int j, int k) {
  104.         for(int l = i - 4; l <= i + 4; l++) {
  105.             for(int i1 = j; i1 <= j + 1; i1++) {
  106.                 for(int j1 = k - 4; j1 <= k + 4; j1++) {
  107.                     if(world.getBlockMaterial(l, i1, j1) == Material.water) {
  108.                         return true;
  109.                     }
  110.                 }
  111.             }
  112.         }
  113.  
  114.         return false;
  115.     }*/
  116.  
  117.     public void onEntityCollidedWithBlock(World world, int i, int j, int k, Entity entity) {
  118.         //int x = MathHelper.floor_double(entity.posX);
  119.         //int y = MathHelper.floor_double(entity.boundingBox.minY);
  120.         //int z = MathHelper.floor_double(entity.posZ);
  121.  
  122.         //if (!(world.getBlockId(x, y, z) == Block.ladder.blockID
  123.               //|| world.getBlockId(x, y + 1, z) == Block.ladder.blockID))
  124.             //return;
  125.  
  126.         if (entity instanceof IMobs)
  127.             entity.attackEntityFrom(null, 1);
  128.  
  129.         entity.fallDistance = 0;
  130.  
  131.         if(entity.motionY < descensionSpeed) {
  132.             entity.motionY = descensionSpeed;
  133.         }
  134.  
  135.         if (entity.isCollidedHorizontally) {
  136.             entity.motionY = ascensionSpeed;
  137.         }
  138.     }
  139.  
  140.     //public boolean canVineGrow(World world, int i, int j, int k, int meta) {
  141.         //if(meta == 2 && world.isBlockOpaqueCube(i, j, k + 1)) {
  142.             //return true;
  143.         //}
  144.  
  145.         //if(meta == 3 && world.isBlockOpaqueCube(i, j, k - 1)) {
  146.             //return true;
  147.         //}
  148.  
  149.         //if(meta == 4 && world.isBlockOpaqueCube(i + 1, j, k)) {
  150.             //return true;
  151.         //}
  152.  
  153.         //if(meta == 5 && world.isBlockOpaqueCube(i - 1, j, k)) {
  154.             //return true;
  155.         //}
  156.  
  157.         //return false;
  158.     //}
  159.  
  160.     public boolean canPlaceBlockAt(World world, int i, int j, int k) {
  161.         // on ground or connected to vines
  162.         if(world.getBlockMaterial(i,j-1,k)!=Material.ground &&
  163.                 world.getBlockId(i,j-1,k) != blockID &&
  164.                 world.getBlockId(i,j+1,k) != blockID)
  165.             return false;
  166.  
  167.         if(world.isBlockOpaqueCube(i - 1, j, k)) {
  168.             return true;
  169.         }
  170.  
  171.         if(world.isBlockOpaqueCube(i + 1, j, k)) {
  172.             return true;
  173.         }
  174.  
  175.         if(world.isBlockOpaqueCube(i, j, k - 1)) {
  176.             return true;
  177.         }
  178.  
  179.         return world.isBlockOpaqueCube(i, j, k + 1);
  180.     }
  181.  
  182.  
  183.  
  184.     public void onNeighborBlockChange(World world, int i, int j, int k, int l) {
  185.         super.onNeighborBlockChange(world, i, j, k, l);
  186.         //world.scheduleBlockUpdate(i, j, k, blockID);
  187.     }
  188. }
Advertisement
Add Comment
Please, Sign In to add comment