Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package mymod.plants;
- import cpw.mods.fml.relauncher.Side;
- import cpw.mods.fml.relauncher.SideOnly;
- import java.util.List;
- import java.util.Random;
- import mymod.Main;
- import mymod.biomeGen.ModWorldGenBanana;
- import mymod.biomeGen.ModWorldGenCoconut;
- import mymod.biomeGen.ModWorldGenPeach;
- import net.minecraft.block.BlockFlower;
- import net.minecraft.client.renderer.texture.IconRegister;
- import net.minecraft.creativetab.CreativeTabs;
- import net.minecraft.item.ItemStack;
- import net.minecraft.util.Icon;
- import net.minecraft.world.World;
- import net.minecraft.world.gen.feature.WorldGenBigTree;
- import net.minecraft.world.gen.feature.WorldGenForest;
- import net.minecraft.world.gen.feature.WorldGenHugeTrees;
- import net.minecraft.world.gen.feature.WorldGenTaiga2;
- import net.minecraft.world.gen.feature.WorldGenTrees;
- import net.minecraft.world.gen.feature.WorldGenerator;
- import net.minecraftforge.event.terraingen.TerrainGen;
- public class ModSaplings extends BlockFlower
- {
- public static final String[] saplings = new String[] {"coconut", "banana", "papaya", "peach"};
- private static final Icon[] iconLength = new Icon[saplings.length];
- public ModSaplings(int par1)
- {
- super(par1);
- float f = 0.4F;
- this.setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, f * 2.0F, 0.5F + f);
- this.setCreativeTab(Main.MyCreativeTab_2);
- }
- /**
- * Ticks the block if it's been scheduled
- */
- public void updateTick(World world, int x, int y, int z, Random random)
- {
- if (!world.isRemote)
- {
- super.updateTick(world, x, y, z, random);
- if (world.getBlockLightValue(x, y + 1, z) >= 9 && random.nextInt(7) == 0)
- {
- this.markOrGrowMarked(world, x, y, z, random);
- }
- }
- }
- /**
- * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata
- */
- public Icon getIcon(int side, int meta)
- {
- meta &= 3;
- return this.iconLength[meta];
- }
- public void markOrGrowMarked(World world, int x, int y, int z, Random random)
- {
- int l = world.getBlockMetadata(x, y, z);
- if ((l & 8) == 0)
- {
- world.setBlockMetadataWithNotify(x, y, z, l | 8, 4);
- }
- else
- {
- this.growTree(world, x, y, z, random);
- }
- }
- /**
- * Attempts to grow a sapling into a tree
- */
- public void growTree(World world, int x, int y, int z, Random random)
- {
- if (!TerrainGen.saplingGrowTree(world, random, x, y, z)) return;
- int l = world.getBlockMetadata(x, y, z) & 3;
- Object object = random.nextInt(10) == 0 ? new WorldGenBigTree(true) : new WorldGenTrees(true);
- int i1 = 0;
- int j1 = 0;
- boolean flag = false;
- switch (1) {
- case 0:
- object = new ModWorldGenBanana(false, 10, 0, 0, false);
- break;
- case 1:
- object = new ModWorldGenPeach(false, 13, 3, 3, false);
- break;
- case 2:
- object = new ModWorldGenCoconut(false, 10, 1, 1, false);
- break;
- case 3:
- break;
- case 4:
- break;
- case 5:
- break;
- default:
- break;
- }
- if (flag)
- {
- world.setBlock(x + i1, y, z + j1, 0, 0, 4);
- world.setBlock(x + i1 + 1, y, z + j1, 0, 0, 4);
- world.setBlock(x + i1, y, z + j1 + 1, 0, 0, 4);
- world.setBlock(x + i1 + 1, y, z + j1 + 1, 0, 0, 4);
- }
- else
- {
- world.setBlock(x, y, z, 0, 0, 4);
- }
- if (!((WorldGenerator)object).generate(world, random, x + i1, y, z + j1))
- {
- if (flag)
- {
- world.setBlock(x + i1, y, z + j1, this.blockID, l, 4);
- world.setBlock(x + i1 + 1, y, z + j1, this.blockID, l, 4);
- world.setBlock(x + i1, y, z + j1 + 1, this.blockID, l, 4);
- world.setBlock(x + i1 + 1, y, z + j1 + 1, this.blockID, l, 4);
- }
- else
- {
- world.setBlock(x, y, z, this.blockID, l, 4);
- }
- }
- }
- /**
- * Determines if the same sapling is present at the given location.
- */
- public boolean isSameSapling(World par1World, int par2, int par3, int par4, int par5)
- {
- return par1World.getBlockId(par2, par3, par4) == this.blockID && (par1World.getBlockMetadata(par2, par3, par4) & 3) == par5;
- }
- /**
- * Determines the damage on the item the block drops. Used in cloth and wood.
- */
- public int damageDropped(int par1)
- {
- return par1 & 3;
- }
- /**
- * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
- */
- public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List)
- {
- par3List.add(new ItemStack(par1, 1, 0));
- par3List.add(new ItemStack(par1, 1, 1));
- par3List.add(new ItemStack(par1, 1, 2));
- par3List.add(new ItemStack(par1, 1, 3));
- }
- /**
- * When this method is called, your block should register all the icons it needs with the given IconRegister. This
- * is the only chance you get to register icons.
- */
- public void registerIcons(IconRegister par1IconRegister)
- {
- for (int i = 0; i < iconLength.length; ++i)
- {
- iconLength[i] = par1IconRegister.registerIcon("mymod:" + this.getUnlocalizedName().substring(5) + "_" + saplings[i]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement