Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.minecraft.src;
- public class mod_vine extends BaseMod {
- public static Block vine = new BlockVine(126,
- ModLoader.addOverride("/terrain.png","/vine/vine.png"))
- .setBlockName("vine");
- public mod_vine() {
- ModLoader.RegisterBlock(vine);
- ModLoader.AddName(vine, "Vine");
- }
- public String Version() {
- return "1.2_02v1";
- }
- public void AddRecipes(CraftingManager recipes) {
- recipes.addRecipe(new ItemStack(vine,64),
- new Object[] {"X", 'X', Block.dirt});
- }
- }
- package net.minecraft.src;
- import java.util.Random;
- public class BlockVine extends BlockLadder {
- public float ascensionSpeed = 0.2F;
- public float descensionSpeed = -0.15F;
- public int tickrate = 20*20;
- public int growChance = 5;
- public boolean debugVine = true;
- public BlockVine(int id, int sprite) {
- super(id, sprite);
- setHardness(0.4F);
- setStepSound(soundWoodFootstep);
- setTickOnLoad(true);
- }
- public int tickRate() {
- return tickrate;
- }
- public void updateTick(World world, int i, int j, int k, Random random)
- {
- if (debugVine) {
- ModLoader.getMinecraftInstance().effectRenderer.addBlockDestroyEffects(i,j,k);
- world.playSoundEffect(i,j,k, "random.pop", 1F, 1F);
- }
- System.out.format("update tick: %d %d %d\n", i,j,k);
- // bubble up
- if (world.getBlockId(i,j+1,k) == blockID) {
- System.out.println("bubble");
- int l;
- for(l = 1; world.getBlockId(i, j + l, k) == blockID; l++);
- world.scheduleBlockUpdate(i, j+l-1, k, blockID, tickRate());
- return;
- }
- int meta = world.getBlockMetadata(i,j,k);
- if (!world.isAirBlock(i,j+1,k)) {
- System.out.println("no air");
- return;
- }
- // can place block above
- //if (!canVineGrow(world,i,j+1,k,meta)) {
- if (!canPlaceBlockAt(world, i,j+1,k)) {
- System.out.println("can't grow");
- // try again later
- world.scheduleBlockUpdate(i, j, k, blockID, tickRate());
- return;
- }
- // find lowest non vine block
- int l;
- for(l = 1; world.getBlockId(i, j - l, k) == blockID; l++);
- // don't grow if not on ground
- if (world.getBlockMaterial(i,j-l,k) != Material.ground) {
- System.out.println("not on ground");
- return;
- }
- if (/*isWaterNearby(world, i, j-l, k) && */random.nextInt(growChance)==0) {
- // grow one block, auto schedule
- System.out.println("grown");
- world.setBlockWithNotify(i, j+1, k, blockID);
- onBlockPlaced(world,i,j+1,k,meta);
- } else {
- // try again
- world.scheduleBlockUpdate(i, j, k, blockID, tickRate());
- }
- }
- /*private boolean isWaterNearby(World world, int i, int j, int k) {
- for(int l = i - 4; l <= i + 4; l++) {
- for(int i1 = j; i1 <= j + 1; i1++) {
- for(int j1 = k - 4; j1 <= k + 4; j1++) {
- if(world.getBlockMaterial(l, i1, j1) == Material.water) {
- return true;
- }
- }
- }
- }
- return false;
- }*/
- public void onEntityCollidedWithBlock(World world, int i, int j, int k, Entity entity) {
- //int x = MathHelper.floor_double(entity.posX);
- //int y = MathHelper.floor_double(entity.boundingBox.minY);
- //int z = MathHelper.floor_double(entity.posZ);
- //if (!(world.getBlockId(x, y, z) == Block.ladder.blockID
- //|| world.getBlockId(x, y + 1, z) == Block.ladder.blockID))
- //return;
- if (entity instanceof IMobs)
- entity.attackEntityFrom(null, 1);
- entity.fallDistance = 0;
- if(entity.motionY < descensionSpeed) {
- entity.motionY = descensionSpeed;
- }
- if (entity.isCollidedHorizontally) {
- entity.motionY = ascensionSpeed;
- }
- }
- //public boolean canVineGrow(World world, int i, int j, int k, int meta) {
- //if(meta == 2 && world.isBlockOpaqueCube(i, j, k + 1)) {
- //return true;
- //}
- //if(meta == 3 && world.isBlockOpaqueCube(i, j, k - 1)) {
- //return true;
- //}
- //if(meta == 4 && world.isBlockOpaqueCube(i + 1, j, k)) {
- //return true;
- //}
- //if(meta == 5 && world.isBlockOpaqueCube(i - 1, j, k)) {
- //return true;
- //}
- //return false;
- //}
- public boolean canPlaceBlockAt(World world, int i, int j, int k) {
- // on ground or connected to vines
- if(world.getBlockMaterial(i,j-1,k)!=Material.ground &&
- world.getBlockId(i,j-1,k) != blockID &&
- world.getBlockId(i,j+1,k) != blockID)
- return false;
- if(world.isBlockOpaqueCube(i - 1, j, k)) {
- return true;
- }
- if(world.isBlockOpaqueCube(i + 1, j, k)) {
- return true;
- }
- if(world.isBlockOpaqueCube(i, j, k - 1)) {
- return true;
- }
- return world.isBlockOpaqueCube(i, j, k + 1);
- }
- public void onNeighborBlockChange(World world, int i, int j, int k, int l) {
- super.onNeighborBlockChange(world, i, j, k, l);
- //world.scheduleBlockUpdate(i, j, k, blockID);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment