From f0e5ce3a6ced7816c0fc50cf8566317d95e31131 Mon Sep 17 00:00:00 2001 From: Adubbz Date: Wed, 25 Dec 2013 10:43:24 +1100 Subject: [PATCH] Readded colorized saplings --- .../blocks/BlockBOPColorizedSapling.java | 191 ++++++++++++++++++ .../biomesoplenty/common/core/BOPBlocks.java | 4 + .../itemblocks/ItemBlockColorizedSapling.java | 45 +++++ 3 files changed, 240 insertions(+) create mode 100644 src/main/java/biomesoplenty/common/blocks/BlockBOPColorizedSapling.java create mode 100644 src/main/java/biomesoplenty/common/itemblocks/ItemBlockColorizedSapling.java diff --git a/src/main/java/biomesoplenty/common/blocks/BlockBOPColorizedSapling.java b/src/main/java/biomesoplenty/common/blocks/BlockBOPColorizedSapling.java new file mode 100644 index 000000000..420c33333 --- /dev/null +++ b/src/main/java/biomesoplenty/common/blocks/BlockBOPColorizedSapling.java @@ -0,0 +1,191 @@ +package biomesoplenty.common.blocks; + +import java.util.List; +import java.util.Random; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockSapling; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.init.Blocks; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraft.world.World; +import net.minecraft.world.gen.feature.WorldGenerator; +import net.minecraftforge.common.util.ForgeDirection; +import biomesoplenty.BiomesOPlenty; + +public class BlockBOPColorizedSapling extends BlockSapling +{ + private static final String[] saplings = new String[] {"acacia", "mangrove", "palm", "redwood", "willow", "pine", "sacredoak"}; + private IIcon[] textures; + private static final int TYPES = 15; + + public BlockBOPColorizedSapling() + { + //TODO: this.setHardness + this.func_149711_c(0.0F); + + //TODO setStepSound(Block.soundGrassFootstep) + this.func_149672_a(Block.field_149779_h); + + //TODO: this.setCreativeTab() + this.func_149647_a(BiomesOPlenty.tabBiomesOPlenty); + } + + @Override + //TODO: registerIcons() + public void func_149651_a(IIconRegister iconRegister) + { + textures = new IIcon[saplings.length]; + + for (int i = 0; i < saplings.length; ++i) { + textures[i] = iconRegister.registerIcon("biomesoplenty:sapling_" + saplings[i]); + } + + } + + @Override + //TODO: getIcon() + public IIcon func_149691_a(int side, int meta) + { + if (meta < 0 || meta >= saplings.length) + { + meta = 0; + } + + return textures[meta]; + } + + @Override + //TODO: getSubBlocks() + public void func_149666_a(Item block, CreativeTabs creativeTabs, List list) + { + for (int i = 0; i < saplings.length; ++i) { + list.add(new ItemStack(block, 1, i)); + } + } + + @Override + //TODO: canPlaceBlockOnSide + public boolean func_149707_d(World world, int x, int y, int z, int side) + { + //TODO: getBlock() + Block block = world.func_147439_a(x, y - 1, z); + int meta = world.getBlockMetadata(x, y - 1, z); + + switch (meta) + { + case 1: // Mangrove + return block == Blocks.sand; + + default: + return block == Blocks.grass || block == Blocks.dirt || block == Blocks.farmland || block.canSustainPlant(world, x, y - 1, z, ForgeDirection.UP, this); + } + } + + @Override + //TODO: canBlockStay() + public boolean func_149718_j(World world, int x, int y, int z) + { + //TODO: getBlock() + Block soil = world.func_147439_a(x, y - 1, z); + + if (world.getBlockMetadata(x, y, z) != 1) + return (world.getFullBlockLightValue(x, y, z) >= 8 || world.canBlockSeeTheSky(x, y, z)) && + (soil != null && soil.canSustainPlant(world, x, y - 1, z, ForgeDirection.UP, this)); + else + return (world.getFullBlockLightValue(x, y, z) >= 8 || world.canBlockSeeTheSky(x, y, z)) && + (soil != null && (soil.canSustainPlant(world, x, y - 1, z, ForgeDirection.UP, this) || soil == Blocks.sand)); + } + + @Override + //TODO: updateTick() + public void func_149674_a(World world, int x, int y, int z, Random random) + { + if (!world.isRemote) + { + if (world.getBlockLightValue(x, y + 1, z) >= 9 && random.nextInt(7) == 0) + { + //TODO: growTree() + this.func_149878_d(world, x, y, z, random); + } + } + } + + @Override + //TODO: growTree() + public void func_149878_d(World world, int x, int y, int z, Random random) + { + int meta = world.getBlockMetadata(x, y, z) & TYPES; + Object obj = null; + int rnd = random.nextInt(8); + + /*TODO: FEATURE if (obj == null) + { + switch (meta) + { + case 0: // Acacia Tree + obj = new WorldGenAcacia(false); + break; + + case 1: // Mangrove Tree + obj = new WorldGenMangrove(false); + break; + + case 2: // Palm Tree + rnd = random.nextInt(4); + + if (rnd == 0) { + obj = new WorldGenPalmTree1(); + } else { + obj = new WorldGenPalmTree3(); + } + break; + + case 3: // Redwood Tree + obj = new WorldGenRedwoodTree2(false); + break; + + case 4: // Willow Tree + obj = new WorldGenWillow(); + break; + + case 5: // Pine Tree + obj = new WorldGenPineTree(); + break; + + case 6: // Sacred Oak + obj = new WorldGenMassiveTree(false); + break; + } + }*/ + + if (obj != null) + { + //TODO: setBlockToAir() + world.func_147468_f(x, y, z); + + if (!((WorldGenerator)obj).generate(world, random, x, y, z)) + { + //TODO: setBlock() + world.func_147465_d(x, y, z, this, meta, 2); + } + } + } + + @Override + //TODO damageDropped() + public int func_149692_a(int meta) + { + return meta & TYPES; + } + + @Override + //TODO: getDamageValue() + public int func_149643_k(World world, int x, int y, int z) + { + return world.getBlockMetadata(x, y, z) & TYPES; + } +} diff --git a/src/main/java/biomesoplenty/common/core/BOPBlocks.java b/src/main/java/biomesoplenty/common/core/BOPBlocks.java index 13fc8c080..c65834ba2 100644 --- a/src/main/java/biomesoplenty/common/core/BOPBlocks.java +++ b/src/main/java/biomesoplenty/common/core/BOPBlocks.java @@ -3,8 +3,10 @@ package biomesoplenty.common.core; import net.minecraft.block.Block; import net.minecraft.item.ItemBlock; import biomesoplenty.common.blocks.BlockAsh; +import biomesoplenty.common.blocks.BlockBOPColorizedSapling; import biomesoplenty.common.blocks.BlockCloud; import biomesoplenty.common.blocks.BlockMud; +import biomesoplenty.common.itemblocks.ItemBlockColorizedSapling; import biomesoplenty.common.itemblocks.ItemBlockMud; import cpw.mods.fml.common.registry.GameRegistry; @@ -25,6 +27,8 @@ public class BOPBlocks registerBlock(new BlockAsh().func_149663_c("ash")); registerBlock(new BlockCloud().func_149663_c("cloud")); + + registerBlock(new BlockBOPColorizedSapling().func_149663_c("colorizedSaplings"), ItemBlockColorizedSapling.class); } public static void registerBlock(Block block) diff --git a/src/main/java/biomesoplenty/common/itemblocks/ItemBlockColorizedSapling.java b/src/main/java/biomesoplenty/common/itemblocks/ItemBlockColorizedSapling.java new file mode 100644 index 000000000..881222d3e --- /dev/null +++ b/src/main/java/biomesoplenty/common/itemblocks/ItemBlockColorizedSapling.java @@ -0,0 +1,45 @@ +package biomesoplenty.common.itemblocks; + +import net.minecraft.block.Block; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; + +public class ItemBlockColorizedSapling extends ItemBlock +{ + private static final String[] saplings = new String[] {"acacia", "mangrove", "palm", "redwood", "willow", "pine", "sacredoak"}; + + public ItemBlockColorizedSapling(Block block) + { + super(block); + + this.setMaxDamage(0); + this.setHasSubtypes(true); + } + + @Override + public int getMetadata(int meta) + { + return meta & 15; + } + + @Override + public String getUnlocalizedName(ItemStack itemStack) + { + int meta = itemStack.getItemDamage(); + + if (meta < 0 || meta >= saplings.length) + { + meta = 0; + } + + return super.getUnlocalizedName() + "." + (new StringBuilder()).append(saplings[meta]).append("Sapling").toString(); + } + + @Override + public IIcon getIconFromDamage(int meta) + { + //TODO: block getIcon() + return field_150939_a.func_149691_a(0, meta); + } +}