diff options
author | Raven Szewczyk <git@eigenraven.me> | 2024-05-24 19:50:35 +0100 |
---|---|---|
committer | Raven Szewczyk <git@eigenraven.me> | 2024-05-24 19:50:35 +0100 |
commit | 6d1b2216464d4dad449ac6fcfec476832224a55e (patch) | |
tree | 526a0c15f7056313c80e6c0386e025e9b3f61781 /src/main/java/gtPlusPlus/xmod/bop | |
parent | b5d35f40afa606ed1b07061dad82e0521a59c186 (diff) | |
download | GT5-Unofficial-6d1b2216464d4dad449ac6fcfec476832224a55e.tar.gz GT5-Unofficial-6d1b2216464d4dad449ac6fcfec476832224a55e.tar.bz2 GT5-Unofficial-6d1b2216464d4dad449ac6fcfec476832224a55e.zip |
Merge addon sources
Diffstat (limited to 'src/main/java/gtPlusPlus/xmod/bop')
13 files changed, 1406 insertions, 0 deletions
diff --git a/src/main/java/gtPlusPlus/xmod/bop/HANDLER_BiomesOPlenty.java b/src/main/java/gtPlusPlus/xmod/bop/HANDLER_BiomesOPlenty.java new file mode 100644 index 0000000000..7727eaef38 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/bop/HANDLER_BiomesOPlenty.java @@ -0,0 +1,178 @@ +package gtPlusPlus.xmod.bop; + +import static gregtech.api.enums.Mods.BiomesOPlenty; + +import java.lang.reflect.Field; + +import net.minecraft.block.Block; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; + +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.core.util.reflect.ReflectionUtils; +import gtPlusPlus.xmod.bop.blocks.BOP_Block_Registrator; + +public class HANDLER_BiomesOPlenty { + + public static Item mPineCone; + + public static Block logs1; + public static Block logs2; + public static Block logs3; + public static Block logs4; + + public static Block leaves1; + public static Block leaves2; + public static Block leaves3; + public static Block leaves4; + + public static Block colorizedLeaves1; + public static Block colorizedLeaves2; + + public static Block saplings; + public static Block colorizedSaplings; + + public static void preInit() { + BOP_Block_Registrator.run(); + if (BiomesOPlenty.isModLoaded()) { + setFields(); + registerPineconeToOreDict(); + } + } + + public static void postInit() { + BOP_Block_Registrator.recipes(); + } + + private static void registerPineconeToOreDict() { + if (mPineCone != null) { + ItemStack aPinecone = ItemUtils.simpleMetaStack(mPineCone, 13, 1); + if (aPinecone != null) { + ItemUtils.addItemToOreDictionary(aPinecone, "pinecone"); + } + } + } + + public static ItemStack getStack(Block aBlock, int aMeta, int aSize) { + return ItemUtils.simpleMetaStack(aBlock, aMeta, aSize); + } + + // BOPCBlocks.logs4 - 0 + // BOPCBlocks.colorizedLeaves2 - 1 + + private static void setFields() { + Field aBopMiscItem = ReflectionUtils + .getField(ReflectionUtils.getClass("biomesoplenty.api.content.BOPCItems"), "misc"); + + Field aBopBlock1 = ReflectionUtils + .getField(ReflectionUtils.getClass("biomesoplenty.api.content.BOPCBlocks"), "logs1"); + Field aBopBlock2 = ReflectionUtils + .getField(ReflectionUtils.getClass("biomesoplenty.api.content.BOPCBlocks"), "logs2"); + Field aBopBlock3 = ReflectionUtils + .getField(ReflectionUtils.getClass("biomesoplenty.api.content.BOPCBlocks"), "logs3"); + Field aBopBlock4 = ReflectionUtils + .getField(ReflectionUtils.getClass("biomesoplenty.api.content.BOPCBlocks"), "logs4"); + + Field aBopLeaves1 = ReflectionUtils + .getField(ReflectionUtils.getClass("biomesoplenty.api.content.BOPCBlocks"), "leaves1"); + Field aBopLeaves2 = ReflectionUtils + .getField(ReflectionUtils.getClass("biomesoplenty.api.content.BOPCBlocks"), "leaves2"); + Field aBopLeaves3 = ReflectionUtils + .getField(ReflectionUtils.getClass("biomesoplenty.api.content.BOPCBlocks"), "leaves3"); + Field aBopLeaves4 = ReflectionUtils + .getField(ReflectionUtils.getClass("biomesoplenty.api.content.BOPCBlocks"), "leaves4"); + + Field aBopColouredLeaves1 = ReflectionUtils + .getField(ReflectionUtils.getClass("biomesoplenty.api.content.BOPCBlocks"), "colorizedLeaves1"); + Field aBopColouredLeaves2 = ReflectionUtils + .getField(ReflectionUtils.getClass("biomesoplenty.api.content.BOPCBlocks"), "colorizedLeaves2"); + + Field aBopSapling = ReflectionUtils + .getField(ReflectionUtils.getClass("biomesoplenty.api.content.BOPCBlocks"), "saplings"); + Field aBopColouredSapling = ReflectionUtils + .getField(ReflectionUtils.getClass("biomesoplenty.api.content.BOPCBlocks"), "colorizedSaplings"); + + if (aBopMiscItem != null) { + Item aMiscItem = ReflectionUtils.getFieldValue(aBopMiscItem); + if (aMiscItem != null) { + mPineCone = aMiscItem; + } + } + + if (aBopBlock1 != null) { + Block aBlock = ReflectionUtils.getFieldValue(aBopBlock1); + if (aBlock != null) { + logs1 = aBlock; + } + } + if (aBopBlock2 != null) { + Block aBlock = ReflectionUtils.getFieldValue(aBopBlock2); + if (aBlock != null) { + logs2 = aBlock; + } + } + if (aBopBlock3 != null) { + Block aBlock = ReflectionUtils.getFieldValue(aBopBlock3); + if (aBlock != null) { + logs3 = aBlock; + } + } + if (aBopBlock4 != null) { + Block aBlock = ReflectionUtils.getFieldValue(aBopBlock4); + if (aBlock != null) { + logs4 = aBlock; + } + } + + if (aBopLeaves1 != null) { + Block aBlock = ReflectionUtils.getFieldValue(aBopLeaves1); + if (aBlock != null) { + leaves1 = aBlock; + } + } + if (aBopLeaves2 != null) { + Block aBlock = ReflectionUtils.getFieldValue(aBopLeaves2); + if (aBlock != null) { + leaves2 = aBlock; + } + } + if (aBopLeaves3 != null) { + Block aBlock = ReflectionUtils.getFieldValue(aBopLeaves3); + if (aBlock != null) { + leaves3 = aBlock; + } + } + if (aBopLeaves4 != null) { + Block aBlock = ReflectionUtils.getFieldValue(aBopLeaves4); + if (aBlock != null) { + leaves4 = aBlock; + } + } + + if (aBopColouredLeaves1 != null) { + Block aBlock = ReflectionUtils.getFieldValue(aBopColouredLeaves1); + if (aBlock != null) { + colorizedLeaves1 = aBlock; + } + } + if (aBopColouredLeaves2 != null) { + Block aBlock = ReflectionUtils.getFieldValue(aBopColouredLeaves2); + if (aBlock != null) { + colorizedLeaves2 = aBlock; + } + } + + if (aBopSapling != null) { + Block aBlock = ReflectionUtils.getFieldValue(aBopSapling); + if (aBlock != null) { + saplings = aBlock; + } + } + if (aBopColouredSapling != null) { + Block aBlock = ReflectionUtils.getFieldValue(aBopColouredSapling); + if (aBlock != null) { + colorizedSaplings = aBlock; + } + } + } +} diff --git a/src/main/java/gtPlusPlus/xmod/bop/blocks/BOP_Block_Registrator.java b/src/main/java/gtPlusPlus/xmod/bop/blocks/BOP_Block_Registrator.java new file mode 100644 index 0000000000..4a3c91e9cb --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/bop/blocks/BOP_Block_Registrator.java @@ -0,0 +1,173 @@ +package gtPlusPlus.xmod.bop.blocks; + +import static gregtech.api.recipe.RecipeMaps.cutterRecipes; +import static gregtech.api.util.GT_RecipeBuilder.SECONDS; +import static gregtech.loaders.oreprocessing.ProcessingLog.addPyrolyeOvenRecipes; + +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; + +import gregtech.GT_Mod; +import gregtech.api.enums.GT_Values; +import gregtech.api.enums.Materials; +import gregtech.api.enums.OrePrefixes; +import gregtech.api.util.GT_ModHandler; +import gregtech.api.util.GT_OreDictUnificator; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.recipe.common.CI; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.core.util.minecraft.RecipeUtils; +import gtPlusPlus.xmod.bop.blocks.pine.LeavesPineTree; +import gtPlusPlus.xmod.bop.blocks.pine.LogPineTree; +import gtPlusPlus.xmod.bop.blocks.pine.SaplingPineTree; +import gtPlusPlus.xmod.bop.blocks.rainforest.LeavesRainforestTree; +import gtPlusPlus.xmod.bop.blocks.rainforest.LogRainforestTree; +import gtPlusPlus.xmod.bop.blocks.rainforest.SaplingRainforestTree; + +public class BOP_Block_Registrator { + + public static Block log_Rainforest; + public static Block leaves_Rainforest; + public static Block sapling_Rainforest; + public static Block log_Pine; + public static Block leaves_Pine; + public static Block sapling_Pine; + + // Runs Each tree Type separately + public static void run() { + registerTree_Rainforest(); + registerTree_Pine(); + } + + private static void registerTree_Rainforest() { + log_Rainforest = new LogRainforestTree(); + leaves_Rainforest = new LeavesRainforestTree(); + sapling_Rainforest = new SaplingRainforestTree(); + ItemUtils.addItemToOreDictionary(ItemUtils.getSimpleStack(log_Rainforest), "logWood", true); + ItemUtils.addItemToOreDictionary(ItemUtils.getSimpleStack(leaves_Rainforest), "treeLeaves", true); + ItemUtils.addItemToOreDictionary(ItemUtils.getSimpleStack(sapling_Rainforest), "treeSapling", true); + } + + private static void registerTree_Pine() { + log_Pine = new LogPineTree(); + leaves_Pine = new LeavesPineTree(); + sapling_Pine = new SaplingPineTree(); + ItemUtils.addItemToOreDictionary(ItemUtils.getSimpleStack(log_Pine), "logWood", true); + ItemUtils.addItemToOreDictionary(ItemUtils.getSimpleStack(leaves_Pine), "treeLeaves", true); + ItemUtils.addItemToOreDictionary(ItemUtils.getSimpleStack(sapling_Pine), "treeSapling", true); + } + + public static void recipes() { + // Rainforest Oak + addLogRecipes(ItemUtils.getSimpleStack(log_Rainforest)); + // Pine + addLogRecipes(ItemUtils.getSimpleStack(log_Pine)); + } + + public static void addLogRecipes(final ItemStack aStack) { + RecipeUtils.addShapelessGregtechRecipe( + new ItemStack[] { aStack }, + ItemUtils + .getSimpleStack(Item.getItemFromBlock(Blocks.planks), GT_Mod.gregtechproxy.mNerfedWoodPlank ? 2 : 4)); + RecipeUtils.recipeBuilder( + CI.craftingToolSaw, + null, + null, + aStack, + null, + null, + null, + null, + null, + ItemUtils.getSimpleStack(Item.getItemFromBlock(Blocks.planks), 4)); + GT_ModHandler.addCraftingRecipe( + GT_OreDictUnificator.get(OrePrefixes.stickLong, Materials.Wood, 2L), + GT_ModHandler.RecipeBits.DO_NOT_CHECK_FOR_COLLISIONS | GT_ModHandler.RecipeBits.BUFFERED, + new Object[] { "sLf", 'L', GT_Utility.copyAmount(1L, aStack) }); + + final short aMeta = (short) aStack.getItemDamage(); + if (GT_Utility.areStacksEqual( + GT_ModHandler.getSmeltingOutput(GT_Utility.copyAmount(1L, aStack), false, null), + new ItemStack(Items.coal, 1, 1))) { + addPyrolyeOvenRecipes(aStack); + GT_ModHandler.removeFurnaceSmelting(GT_Utility.copyAmount(1L, aStack)); + } + if (aMeta == 32767) { + for (int i = 0; i < 32767; ++i) { + if (GT_Utility.areStacksEqual( + GT_ModHandler.getSmeltingOutput(new ItemStack(aStack.getItem(), 1, i), false, null), + new ItemStack(Items.coal, 1, 1))) { + addPyrolyeOvenRecipes(aStack); + GT_ModHandler.removeFurnaceSmelting(new ItemStack(aStack.getItem(), 1, i)); + } + final ItemStack tStack = GT_ModHandler.getRecipeOutput(new ItemStack(aStack.getItem(), 1, i)); + if (tStack == null) { + if (i >= 16) { + break; + } + } else { + final ItemStack tPlanks = GT_Utility.copy(tStack); + tPlanks.stackSize = tPlanks.stackSize * 3 / 2; + GT_Values.RA.stdBuilder() + .itemInputs(new ItemStack(aStack.getItem(), 1, i)) + .itemOutputs( + GT_Utility.copyAmount( + GT_Mod.gregtechproxy.mNerfedWoodPlank ? ((long) tStack.stackSize) + : (((long) tStack.stackSize) * 5L / 4), + tStack), + GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Wood, 2L)) + .duration(10 * SECONDS) + .eut(8) + .addTo(cutterRecipes); + GT_ModHandler.removeRecipe(new ItemStack(aStack.getItem(), 1, i)); + GT_ModHandler.addCraftingRecipe( + GT_Utility.copyAmount( + GT_Mod.gregtechproxy.mNerfedWoodPlank ? ((long) tStack.stackSize) + : (((long) tStack.stackSize) * 5L / 4), + tStack), + new Object[] { "s", "L", 'L', new ItemStack(aStack.getItem(), 1, i) }); + GT_ModHandler.addShapelessCraftingRecipe( + GT_Utility + .copyAmount(tStack.stackSize / (GT_Mod.gregtechproxy.mNerfedWoodPlank ? 2 : 1), tStack), + new Object[] { new ItemStack(aStack.getItem(), 1, i) }); + } + } + } else { + final ItemStack tStack2 = GT_ModHandler.getRecipeOutput(GT_Utility.copyAmount(1L, aStack)); + if (tStack2 != null) { + final ItemStack tPlanks2 = GT_Utility.copy(tStack2); + tPlanks2.stackSize = tPlanks2.stackSize * 3 / 2; + GT_Values.RA.stdBuilder() + .itemInputs(GT_Utility.copyAmount(1L, aStack)) + .itemOutputs( + GT_Utility.copyAmount( + GT_Mod.gregtechproxy.mNerfedWoodPlank ? ((long) tStack2.stackSize) + : (((long) tStack2.stackSize) * 5L / 4), + tStack2), + GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Wood, 2L)) + .duration(10 * SECONDS) + .eut(8) + .addTo(cutterRecipes); + GT_ModHandler.removeRecipe(GT_Utility.copyAmount(1L, aStack)); + GT_ModHandler.addCraftingRecipe( + GT_Utility.copyAmount( + GT_Mod.gregtechproxy.mNerfedWoodPlank ? ((long) tStack2.stackSize) + : (((long) tStack2.stackSize) * 5L / 4), + tStack2), + new Object[] { "s", "L", 'L', GT_Utility.copyAmount(1L, aStack) }); + GT_ModHandler.addShapelessCraftingRecipe( + GT_Utility.copyAmount(tStack2.stackSize / (GT_Mod.gregtechproxy.mNerfedWoodPlank ? 2 : 1), tStack2), + new Object[] { GT_Utility.copyAmount(1L, aStack) }); + } + } + if (GT_Utility.areStacksEqual( + GT_ModHandler.getSmeltingOutput(GT_Utility.copyAmount(1L, aStack), false, null), + new ItemStack(Items.coal, 1, 1))) { + addPyrolyeOvenRecipes(aStack); + GT_ModHandler.removeFurnaceSmelting(GT_Utility.copyAmount(1L, aStack)); + } + } +} diff --git a/src/main/java/gtPlusPlus/xmod/bop/blocks/base/LeavesBase.java b/src/main/java/gtPlusPlus/xmod/bop/blocks/base/LeavesBase.java new file mode 100644 index 0000000000..171bb9a58c --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/bop/blocks/base/LeavesBase.java @@ -0,0 +1,106 @@ +package gtPlusPlus.xmod.bop.blocks.base; + +import static gregtech.api.enums.Mods.GTPlusPlus; + +import java.util.List; +import java.util.Random; + +import net.minecraft.block.BlockLeaves; +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.ItemBlock; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraft.world.World; + +import cpw.mods.fml.common.registry.GameRegistry; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.creative.AddToCreativeTab; +import gtPlusPlus.core.util.Utils; +import gtPlusPlus.core.util.minecraft.ItemUtils; + +public class LeavesBase extends BlockLeaves { + + protected IIcon[][] leafTextures = new IIcon[2][]; + protected String[][] leafType = new String[][] { {}, {} }; + protected String[] treeType = new String[] {}; + protected ItemStack[] bonusDrops; + + public LeavesBase(String blockNameLocalized, String blockNameUnlocalized, ItemStack[] bonusDrops) { + this.bonusDrops = bonusDrops; + String blockName = "block" + Utils.sanitizeString(blockNameLocalized) + "Leaves"; + GameRegistry.registerBlock(this, ItemBlock.class, blockName); + this.setBlockName(blockName); + ItemUtils.addItemToOreDictionary(ItemUtils.getSimpleStack(this), "treeLeaves", true); + this.setCreativeTab(AddToCreativeTab.tabBOP); + Blocks.fire.setFireInfo(this, 80, 150); + } + + private void setVanillaVariable(Object toSet, Object value) { + toSet = value; + } + + @Override + public int quantityDropped(Random p_149745_1_) { + return p_149745_1_.nextInt(20) == 0 ? 1 : 0; + } + + @Override // Drops when Leaf is broken + protected void func_150124_c(World world, int x, int y, int z, int meta, int randomChance) { + Logger.INFO("Dropping Bonus Drops"); + for (ItemStack bonusDrop : this.bonusDrops) { + if (bonusDrop != null && world.rand.nextInt(randomChance) == 0) { + this.dropBlockAsItem(world, x, y, z, ItemUtils.getSimpleStack(bonusDrop, 1)); + } + } + } + + /** + * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks) + */ + @SuppressWarnings("unchecked") + @Override + @SideOnly(Side.CLIENT) + public void getSubBlocks(Item item, CreativeTabs tab, @SuppressWarnings("rawtypes") List metaList) { + for (int i = 0; i < this.treeType.length; ++i) { + metaList.add(new ItemStack(item, 1, i)); + } + } + + /** + * Gets the block's texture. Args: side, meta + */ + @Override + @SideOnly(Side.CLIENT) + public IIcon getIcon(int ordinalSide, int metaID) { + return (metaID & 3) == 1 ? this.leafTextures[this.field_150127_b][1] + : this.leafTextures[this.field_150127_b][0]; + } + + @Override + public boolean isOpaqueCube() { + return false; + } + + @Override + @SideOnly(Side.CLIENT) + public void registerBlockIcons(IIconRegister iIcon) { + for (int i = 0; i < leafType.length; ++i) { + this.leafTextures[i] = new IIcon[leafType[i].length]; + for (int j = 0; j < leafType[i].length; ++j) { + this.leafTextures[i][j] = iIcon + .registerIcon(GTPlusPlus.ID + ":" + "trees/" + "leaves/" + "leaves_" + leafType[i][j]); + } + } + setVanillaVariable(this.field_150129_M, this.leafTextures); + } + + @Override + public String[] func_150125_e() { + return treeType; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/bop/blocks/base/LogBase.java b/src/main/java/gtPlusPlus/xmod/bop/blocks/base/LogBase.java new file mode 100644 index 0000000000..2cf8ba1fbc --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/bop/blocks/base/LogBase.java @@ -0,0 +1,85 @@ +package gtPlusPlus.xmod.bop.blocks.base; + +import static gregtech.api.enums.Mods.GTPlusPlus; + +import java.util.List; + +import net.minecraft.block.BlockLog; +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.ItemBlock; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; + +import cpw.mods.fml.common.registry.GameRegistry; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gtPlusPlus.core.creative.AddToCreativeTab; +import gtPlusPlus.core.util.Utils; +import gtPlusPlus.core.util.minecraft.ItemUtils; + +public abstract class LogBase extends BlockLog { + + public String[] treeType = new String[] {}; + protected IIcon[] textureSide; + protected IIcon[] textureTop; + + public LogBase(String blockNameLocalized, String blockNameUnlocalized, String[] treeTypes) { + this.treeType = treeTypes; + String blockName = "block" + Utils.sanitizeString(blockNameLocalized) + "Log"; + GameRegistry.registerBlock(this, ItemBlock.class, blockName); + this.setBlockName(blockName); + ItemUtils.addItemToOreDictionary( + ItemUtils.getSimpleStack(this), + "log" + Utils.sanitizeString(blockNameLocalized), + true); + ItemUtils.addItemToOreDictionary(ItemUtils.getSimpleStack(this), "logWood", true); + this.setCreativeTab(AddToCreativeTab.tabBOP); + Blocks.fire.setFireInfo(this, 20, 100); + } + + private void setVanillaVariable(Object toSet, Object value) { + toSet = value; + } + + /** + * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks) + */ + @Override + @SideOnly(Side.CLIENT) + public void getSubBlocks(Item item, CreativeTabs tab, List metaList) { + for (int i = 0; i < this.textureSide.length; ++i) { + metaList.add(new ItemStack(item, 1, i)); + } + } + + @Override + @SideOnly(Side.CLIENT) + protected IIcon getTopIcon(int meta) { + return this.textureTop[meta % this.textureTop.length]; + } + + @Override + @SideOnly(Side.CLIENT) + protected IIcon getSideIcon(int metaID) { + return this.textureSide[metaID % this.textureSide.length]; + } + + @Override + @SideOnly(Side.CLIENT) + public void registerBlockIcons(IIconRegister iIcon) { + this.textureSide = new IIcon[treeType.length]; + this.textureTop = new IIcon[treeType.length]; + + for (int i = 0; i < this.textureSide.length; ++i) { + this.textureSide[i] = iIcon.registerIcon(GTPlusPlus.ID + ":" + "trees/" + "logs/" + "log_" + treeType[i]); + this.textureTop[i] = iIcon + .registerIcon(GTPlusPlus.ID + ":" + "trees/" + "logs/" + "log_" + treeType[i] + "_top"); + } + + setVanillaVariable(this.field_150167_a, this.textureSide); + setVanillaVariable(this.field_150166_b, this.textureTop); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/bop/blocks/base/SaplingBase.java b/src/main/java/gtPlusPlus/xmod/bop/blocks/base/SaplingBase.java new file mode 100644 index 0000000000..ff5c8770d4 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/bop/blocks/base/SaplingBase.java @@ -0,0 +1,166 @@ +package gtPlusPlus.xmod.bop.blocks.base; + +import static gregtech.api.enums.Mods.GTPlusPlus; + +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.ItemBlock; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraft.util.MathHelper; +import net.minecraft.world.World; +import net.minecraft.world.gen.feature.WorldGenBigTree; +import net.minecraft.world.gen.feature.WorldGenTrees; +import net.minecraft.world.gen.feature.WorldGenerator; + +import cpw.mods.fml.common.registry.GameRegistry; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.creative.AddToCreativeTab; +import gtPlusPlus.core.util.Utils; +import gtPlusPlus.core.util.minecraft.ItemUtils; + +public class SaplingBase extends BlockSapling { + + protected String[] saplingTypes = new String[] {}; + protected IIcon[] saplingTextures = new IIcon[] {}; + + // Sapling types - field_149882_a + // Iicons - field_149881_b + + protected SaplingBase(String blockNameLocalized, String blockNameUnlocalized, String[] saplingTypes) { + float f = 0.4F; + this.setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, f * 2.0F, 0.5F + f); + this.saplingTypes = saplingTypes; + this.saplingTextures = new IIcon[saplingTypes.length]; + String blockName = "block" + Utils.sanitizeString(blockNameLocalized); + GameRegistry.registerBlock(this, ItemBlock.class, blockName); + this.setBlockName(blockName); + ItemUtils.addItemToOreDictionary(ItemUtils.getSimpleStack(this), "treeSapling", true); + this.setCreativeTab(AddToCreativeTab.tabBOP); + } + + private void setVanillaVariable(Object toSet, Object value) { + toSet = value; + } + + /** + * Gets the block's texture. Args: side, meta + */ + @Override + @SideOnly(Side.CLIENT) + public IIcon getIcon(int someInt, int meta) { + /* + * meta &= 7; return saplingTextures[MathHelper.clamp_int(meta, 0, 5)]; + */ + // return this.saplingTextures[meta % this.saplingTextures.length]; + try { + return this.saplingTextures[meta]; + } catch (Throwable T) { + Logger.WARNING("Invalid Sapling meta is " + meta); + return this.saplingTextures[0]; + } + } + + /** + * Ticks the block if it's been scheduled + */ + @Override + public void updateTick(World world, int x, int y, int z, Random rand) { + if (!world.isRemote) { + super.updateTick(world, x, y, z, rand); + if (world.getBlockLightValue(x, y + 1, z) >= 9 && rand.nextInt(7) == 0) { + Logger.WARNING("Update Tick"); + this.updateMeta(world, x, y, z, rand); + } else { + Logger.WARNING("Tried to Tick."); + } + } + } + + // Dunno - Think it is doGrow || doGrowthTick + @Override + public void func_149853_b(World world, Random rand, int x, int y, int z) { + Logger.WARNING("Please find what calls me - func_149853_b"); + this.updateMeta(world, x, y, z, rand); + } + + public void updateMeta(World world, int x, int y, int z, Random rand) { + func_149879_c(world, x, y, z, rand); + } + + @Override + public void func_149879_c(World world, int x, int y, int z, Random rand) { + Logger.WARNING("func_149879_c - 1"); + int l = world.getBlockMetadata(x, y, z); + + if ((l & 8) == 0) { + Logger.WARNING("func_149879_c - 2"); + world.setBlockMetadataWithNotify(x, y, z, l | 8, 4); + } else { + Logger.WARNING("func_149879_c - 3"); + this.func_149878_d(world, x, y, z, rand); + } + } + + @Override + public void func_149878_d(World world, int x, int y, int z, Random rand) { + Logger.WARNING("func_149878_d - 1"); + if (!net.minecraftforge.event.terraingen.TerrainGen.saplingGrowTree(world, rand, x, y, z)) return; + int l = world.getBlockMetadata(x, y, z) & 7; + Object object = rand.nextInt(10) == 0 ? new WorldGenBigTree(true) : new WorldGenTrees(true); + int i1 = 0; + int j1 = 0; + boolean flag = false; + + Block block = Blocks.air; + + world.setBlock(x, y, z, block, 0, 4); + + if (!((WorldGenerator) object).generate(world, rand, x + i1, y, z + j1)) { + world.setBlock(x, y, z, this, l, 4); + } + } + + @Override + public boolean func_149880_a(World world, int p_149880_2_, int p_149880_3_, int p_149880_4_, int p_149880_5_) { + return world.getBlock(p_149880_2_, p_149880_3_, p_149880_4_) == this + && (world.getBlockMetadata(p_149880_2_, p_149880_3_, p_149880_4_) & 7) == p_149880_5_; + } + + /** + * Determines the damage on the item the block drops. Used in cloth and wood. + */ + @Override + public int damageDropped(int meta) { + return MathHelper.clamp_int(meta & 7, 0, 5); + } + + /** + * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks) + */ + @Override + @SideOnly(Side.CLIENT) + public void getSubBlocks(Item item, CreativeTabs tab, List metaList) { + for (int i = 0; i < this.saplingTextures.length; ++i) { + metaList.add(new ItemStack(item, 1, i)); + } + } + + @Override + @SideOnly(Side.CLIENT) + public void registerBlockIcons(IIconRegister iIcon) { + for (int i = 0; i < saplingTextures.length; ++i) { + saplingTextures[i] = iIcon + .registerIcon(GTPlusPlus.ID + ":" + "trees/" + "saplings/" + "sapling_" + saplingTypes[i]); + } + } +} diff --git a/src/main/java/gtPlusPlus/xmod/bop/blocks/pine/LeavesPineTree.java b/src/main/java/gtPlusPlus/xmod/bop/blocks/pine/LeavesPineTree.java new file mode 100644 index 0000000000..93f7e59a1e --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/bop/blocks/pine/LeavesPineTree.java @@ -0,0 +1,41 @@ +package gtPlusPlus.xmod.bop.blocks.pine; + +import java.util.Random; + +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.item.chemistry.AgriculturalChem; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.xmod.bop.blocks.BOP_Block_Registrator; +import gtPlusPlus.xmod.bop.blocks.base.LeavesBase; + +public class LeavesPineTree extends LeavesBase { + + public LeavesPineTree() { + super("Pine", "pine", new ItemStack[] {}); + this.treeType = new String[] { "pine" }; + this.leafType = new String[][] { { "pine" }, { "pine_opaque" } }; + } + + @Override + public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_) { + return Item.getItemFromBlock(BOP_Block_Registrator.sapling_Pine); + } + + @Override // Drops when Leaf is broken + protected void func_150124_c(World world, int x, int y, int z, int meta, int randomChance) { + Logger.INFO("Dropping Bonus Drops"); + if (MathUtils.randInt(0, 10) >= 9) { + this.dropBlockAsItem( + world, + x, + y, + z, + ItemUtils.getSimpleStack(AgriculturalChem.mPinecone, MathUtils.randInt(1, 4))); + } + } +} diff --git a/src/main/java/gtPlusPlus/xmod/bop/blocks/pine/LogPineTree.java b/src/main/java/gtPlusPlus/xmod/bop/blocks/pine/LogPineTree.java new file mode 100644 index 0000000000..98e384cd3f --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/bop/blocks/pine/LogPineTree.java @@ -0,0 +1,21 @@ +package gtPlusPlus.xmod.bop.blocks.pine; + +import gtPlusPlus.xmod.bop.blocks.base.LogBase; + +public class LogPineTree extends LogBase { + + public LogPineTree() { + super("Pine Log", "pine", new String[] { "pine" }); + this.treeType = new String[] { "pine" }; + } + + /* + * @Override + * @SideOnly(Side.CLIENT) protected IIcon getSideIcon(int metaID){ return this.textureSide[metaID % + * this.textureSide.length]; } + * @Override + * @SideOnly(Side.CLIENT) protected IIcon getTopIcon(int metaID){ return this.textureTop[metaID % + * this.textureTop.length]; } + */ + +} diff --git a/src/main/java/gtPlusPlus/xmod/bop/blocks/pine/SaplingPineTree.java b/src/main/java/gtPlusPlus/xmod/bop/blocks/pine/SaplingPineTree.java new file mode 100644 index 0000000000..2c2bb38af6 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/bop/blocks/pine/SaplingPineTree.java @@ -0,0 +1,52 @@ +package gtPlusPlus.xmod.bop.blocks.pine; + +import java.util.Random; + +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.world.World; +import net.minecraft.world.gen.feature.WorldGenBigTree; +import net.minecraft.world.gen.feature.WorldGenTrees; +import net.minecraft.world.gen.feature.WorldGenerator; + +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.xmod.bop.blocks.base.SaplingBase; +import gtPlusPlus.xmod.bop.world.features.trees.WorldGenPineTree; + +public class SaplingPineTree extends SaplingBase { + + public SaplingPineTree() { + super("Pine Sapling", "pine", new String[] { "pine" }); + } + + @Override + public void func_149878_d(World world, int x, int y, int z, Random rand) { + Logger.WARNING("func_149878_d - 1"); + if (!net.minecraftforge.event.terraingen.TerrainGen.saplingGrowTree(world, rand, x, y, z)) return; + rand.nextInt(10); + new WorldGenBigTree(true); + new WorldGenTrees(true); + int i1 = 0; + int j1 = 0; + boolean flag = false; + + Block block = Blocks.air; + + if (flag) { + world.setBlock(x + i1, y, z + j1, block, 0, 4); + world.setBlock(x + i1 + 1, y, z + j1, block, 0, 4); + world.setBlock(x + i1, y, z + j1 + 1, block, 0, 4); + world.setBlock(x + i1 + 1, y, z + j1 + 1, block, 0, 4); + } else { + world.setBlock(x, y, z, block, 0, 4); + } + Object obj = new WorldGenPineTree(); + if (obj != null) { + world.setBlockToAir(x, y, z); + if (!((WorldGenerator) obj).generate(world, CORE.RANDOM, x, y, z)) { + world.setBlock(x, y, z, this, 0, 2); + } + } + } +} diff --git a/src/main/java/gtPlusPlus/xmod/bop/blocks/rainforest/LeavesRainforestTree.java b/src/main/java/gtPlusPlus/xmod/bop/blocks/rainforest/LeavesRainforestTree.java new file mode 100644 index 0000000000..816b666a40 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/bop/blocks/rainforest/LeavesRainforestTree.java @@ -0,0 +1,25 @@ +package gtPlusPlus.xmod.bop.blocks.rainforest; + +import java.util.Random; + +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; + +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.xmod.bop.blocks.BOP_Block_Registrator; +import gtPlusPlus.xmod.bop.blocks.base.LeavesBase; + +public class LeavesRainforestTree extends LeavesBase { + + public LeavesRainforestTree() { + super("Rainforest Oak", "rainforestoak", new ItemStack[] { ItemUtils.getSimpleStack(Items.apple) }); + this.treeType = new String[] { "rainforest" }; + this.leafType = new String[][] { { "rainforest" }, { "rainforest_opaque" } }; + } + + @Override + public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_) { + return Item.getItemFromBlock(BOP_Block_Registrator.sapling_Rainforest); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/bop/blocks/rainforest/LogRainforestTree.java b/src/main/java/gtPlusPlus/xmod/bop/blocks/rainforest/LogRainforestTree.java new file mode 100644 index 0000000000..4e769b7c95 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/bop/blocks/rainforest/LogRainforestTree.java @@ -0,0 +1,12 @@ +package gtPlusPlus.xmod.bop.blocks.rainforest; + +import gtPlusPlus.xmod.bop.blocks.base.LogBase; + +public class LogRainforestTree extends LogBase { + + public LogRainforestTree() { + super("Rainforest Oak", "rainforestoak", new String[] { "rainforest" }); + this.treeType = new String[] { "rainforest" }; + } + +} diff --git a/src/main/java/gtPlusPlus/xmod/bop/blocks/rainforest/SaplingRainforestTree.java b/src/main/java/gtPlusPlus/xmod/bop/blocks/rainforest/SaplingRainforestTree.java new file mode 100644 index 0000000000..362eb2f541 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/bop/blocks/rainforest/SaplingRainforestTree.java @@ -0,0 +1,65 @@ +package gtPlusPlus.xmod.bop.blocks.rainforest; + +import java.util.Random; + +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.world.World; +import net.minecraft.world.gen.feature.WorldGenBigTree; +import net.minecraft.world.gen.feature.WorldGenTrees; +import net.minecraft.world.gen.feature.WorldGenerator; + +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.xmod.bop.blocks.BOP_Block_Registrator; +import gtPlusPlus.xmod.bop.blocks.base.SaplingBase; +import gtPlusPlus.xmod.bop.world.features.trees.WorldGenRainForestTree_Ex; + +public class SaplingRainforestTree extends SaplingBase { + + public SaplingRainforestTree() { + super("Rainforest Oak Sapling", "rainforestoak", new String[] { "rainforest" }); + } + + @Override + public void func_149878_d(World world, int x, int y, int z, Random rand) { + Logger.WARNING("func_149878_d - 1"); + if (!net.minecraftforge.event.terraingen.TerrainGen.saplingGrowTree(world, rand, x, y, z)) return; + int l = world.getBlockMetadata(x, y, z) & 7; + rand.nextInt(10); + new WorldGenBigTree(true); + new WorldGenTrees(true); + int i1 = 0; + int j1 = 0; + boolean flag = false; + + Block block = Blocks.air; + + if (flag) { + world.setBlock(x + i1, y, z + j1, block, 0, 4); + world.setBlock(x + i1 + 1, y, z + j1, block, 0, 4); + world.setBlock(x + i1, y, z + j1 + 1, block, 0, 4); + world.setBlock(x + i1 + 1, y, z + j1 + 1, block, 0, 4); + } else { + world.setBlock(x, y, z, block, 0, 4); + } + Object o = new WorldGenRainForestTree_Ex( + BOP_Block_Registrator.log_Rainforest, + BOP_Block_Registrator.leaves_Rainforest, + 0, + 0, + true, + 50, + 75); + + if (!((WorldGenerator) o).generate(world, rand, x + i1, y, z + j1)) { + if (flag) { + world.setBlock(x + i1, y, z + j1, this, l, 4); + world.setBlock(x + i1 + 1, y, z + j1, this, l, 4); + world.setBlock(x + i1, y, z + j1 + 1, this, l, 4); + world.setBlock(x + i1 + 1, y, z + j1 + 1, this, l, 4); + } else { + world.setBlock(x, y, z, this, l, 4); + } + } + } +} diff --git a/src/main/java/gtPlusPlus/xmod/bop/world/features/trees/WorldGenPineTree.java b/src/main/java/gtPlusPlus/xmod/bop/world/features/trees/WorldGenPineTree.java new file mode 100644 index 0000000000..bc97042c82 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/bop/world/features/trees/WorldGenPineTree.java @@ -0,0 +1,172 @@ +package gtPlusPlus.xmod.bop.world.features.trees; + +import java.util.Random; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockSapling; +import net.minecraft.init.Blocks; +import net.minecraft.world.World; +import net.minecraft.world.gen.feature.WorldGenAbstractTree; +import net.minecraftforge.common.util.ForgeDirection; + +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.xmod.bop.blocks.BOP_Block_Registrator; + +public class WorldGenPineTree extends WorldGenAbstractTree { + + public WorldGenPineTree() { + super(true); + } + + @Override + public boolean generate(World world, Random random, int x, int y, int z) { + while (world.isAirBlock(x, y, z) && y > 2) { + --y; + } + + Block aSoilBlock = world.getBlock(x, y, z); + + if (!canBlockSustainSapling(world, aSoilBlock, x, y, z)) { + return false; + } else { + int height; + int branches; + for (height = -2; height <= 2; ++height) { + for (branches = -2; branches <= 2; ++branches) { + if (world.isAirBlock(x + height, y - 1, z + branches) + && world.isAirBlock(x + height, y - 2, z + branches) + && !world.isAirBlock(x + height, y, z + branches)) { + return false; + } + } + } + + height = 2 + MathUtils.randInt(8, 16); + branches = 2 + MathUtils.randInt(6, 18); + int h = 1; + aSoilBlock.onPlantGrow(world, x, y - 1, z, x, y, z); + + int c; + int r = MathUtils.randInt(1, 3); + for (c = 0; c < height; ++c) { + this.buildBlock(world, x, y + h, z, BOP_Block_Registrator.log_Pine, 0); + h++; + if (c >= r && c % 2 == 0) { + this.generateBranch(world, random, x, y + h, z, c); + } + } + + this.generateTop(world, x, y + h, z); + return true; + } + } + + public void generateTop(World world, int x, int y, int z) { + for (int i = -1; i < 2; ++i) { + for (int j = -1; j < 2; ++j) { + this.buildBlock(world, x + i, y, z + j, BOP_Block_Registrator.leaves_Pine, 0); + } + } + + this.buildBlock(world, x, y, z, BOP_Block_Registrator.log_Pine, 0); + this.buildBlock(world, x + 1, y + 1, z, BOP_Block_Registrator.leaves_Pine, 0); + this.buildBlock(world, x, y + 1, z - 1, BOP_Block_Registrator.leaves_Pine, 0); + this.buildBlock(world, x, y + 1, z + 1, BOP_Block_Registrator.leaves_Pine, 0); + this.buildBlock(world, x - 1, y + 1, z, BOP_Block_Registrator.leaves_Pine, 0); + this.buildBlock(world, x, y + 2, z, BOP_Block_Registrator.leaves_Pine, 0); + } + + public void generateBranch(World world, Random rand, int x, int y, int z, int n) { + int var99999; + int var99998; + for (var99999 = -1; var99999 < 2; ++var99999) { + for (var99998 = -1; var99998 < 2; ++var99998) { + this.buildBlock(world, x + var99999, y, z + var99998, BOP_Block_Registrator.leaves_Pine, 0); + } + } + + var99999 = rand.nextInt(2); + var99998 = rand.nextInt(2); + int var99997 = rand.nextInt(2); + int var99996 = rand.nextInt(2); + if (n % 2 == 0) { + if (var99998 == 0) { + this.buildBlock(world, x + 1, y - 1, z - 2, BOP_Block_Registrator.leaves_Pine, 0); + this.buildBlock(world, x + 2, y - 1, z - 1, BOP_Block_Registrator.leaves_Pine, 0); + if (var99999 == 0) { + this.buildBlock(world, x + 2, y - 2, z - 2, BOP_Block_Registrator.leaves_Pine, 0); + } else { + this.buildBlock(world, x + 2, y - 1, z - 2, BOP_Block_Registrator.leaves_Pine, 0); + } + } else { + this.buildBlock(world, x + 1, y, z - 2, BOP_Block_Registrator.leaves_Pine, 0); + this.buildBlock(world, x + 2, y, z - 1, BOP_Block_Registrator.leaves_Pine, 0); + this.buildBlock(world, x + 2, y, z - 2, BOP_Block_Registrator.leaves_Pine, 0); + } + + if (var99997 == 0) { + this.buildBlock(world, x - 2, y - 1, z + 1, BOP_Block_Registrator.leaves_Pine, 0); + this.buildBlock(world, x - 1, y - 1, z + 2, BOP_Block_Registrator.leaves_Pine, 0); + if (var99996 == 0) { + this.buildBlock(world, x - 2, y - 2, z + 2, BOP_Block_Registrator.leaves_Pine, 0); + } else { + this.buildBlock(world, x - 2, y - 1, z + 2, BOP_Block_Registrator.leaves_Pine, 0); + } + } else { + this.buildBlock(world, x - 2, y, z + 1, BOP_Block_Registrator.leaves_Pine, 0); + this.buildBlock(world, x - 1, y, z + 2, BOP_Block_Registrator.leaves_Pine, 0); + this.buildBlock(world, x - 2, y, z + 2, BOP_Block_Registrator.leaves_Pine, 0); + } + } else { + if (var99998 == 0) { + this.buildBlock(world, x + 2, y - 1, z + 1, BOP_Block_Registrator.leaves_Pine, 0); + this.buildBlock(world, x + 1, y - 1, z + 2, BOP_Block_Registrator.leaves_Pine, 0); + if (var99999 == 0) { + this.buildBlock(world, x + 2, y - 2, z + 2, BOP_Block_Registrator.leaves_Pine, 0); + } else { + this.buildBlock(world, x + 2, y - 1, z + 2, BOP_Block_Registrator.leaves_Pine, 0); + } + } else { + this.buildBlock(world, x + 2, y, z + 1, BOP_Block_Registrator.leaves_Pine, 0); + this.buildBlock(world, x + 1, y, z + 2, BOP_Block_Registrator.leaves_Pine, 0); + if (var99999 == 0) { + this.buildBlock(world, x + 2, y - 1, z + 2, BOP_Block_Registrator.leaves_Pine, 0); + } else { + this.buildBlock(world, x + 2, y, z + 2, BOP_Block_Registrator.leaves_Pine, 0); + } + } + + if (var99997 == 0) { + this.buildBlock(world, x - 1, y - 1, z - 2, BOP_Block_Registrator.leaves_Pine, 0); + this.buildBlock(world, x - 2, y - 1, z - 1, BOP_Block_Registrator.leaves_Pine, 0); + if (var99996 == 0) { + this.buildBlock(world, x - 2, y - 2, z - 2, BOP_Block_Registrator.leaves_Pine, 0); + } else { + this.buildBlock(world, x - 2, y - 1, z - 2, BOP_Block_Registrator.leaves_Pine, 0); + } + } else { + this.buildBlock(world, x - 1, y, z - 2, BOP_Block_Registrator.leaves_Pine, 0); + this.buildBlock(world, x - 2, y, z - 1, BOP_Block_Registrator.leaves_Pine, 0); + if (var99996 == 0) { + this.buildBlock(world, x - 2, y - 1, z - 2, BOP_Block_Registrator.leaves_Pine, 0); + } else { + this.buildBlock(world, x - 2, y, z - 2, BOP_Block_Registrator.leaves_Pine, 0); + } + } + } + + this.buildBlock(world, x, y, z, BOP_Block_Registrator.log_Pine, 0); + this.buildBlock(world, x, y + 1, z, BOP_Block_Registrator.log_Pine, 0); + } + + public void buildBlock(World world, int x, int y, int z, Block block, int meta) { + if (world.isAirBlock(x, y, z) || world.getBlock(x, y, z) + .isLeaves(world, x, y, z)) { + world.setBlock(x, y, z, block, meta, 2); + } + } + + public boolean canBlockSustainSapling(World world, Block block, int x, int y, int z) { + return block.canSustainPlant(world, x, y, z, ForgeDirection.UP, (BlockSapling) Blocks.sapling); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/bop/world/features/trees/WorldGenRainForestTree_Ex.java b/src/main/java/gtPlusPlus/xmod/bop/world/features/trees/WorldGenRainForestTree_Ex.java new file mode 100644 index 0000000000..d3ad2efaea --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/bop/world/features/trees/WorldGenRainForestTree_Ex.java @@ -0,0 +1,310 @@ +package gtPlusPlus.xmod.bop.world.features.trees; + +import java.util.Random; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockSapling; +import net.minecraft.init.Blocks; +import net.minecraft.world.World; +import net.minecraft.world.gen.feature.WorldGenAbstractTree; +import net.minecraftforge.common.util.ForgeDirection; + +import gtPlusPlus.api.objects.Logger; + +public class WorldGenRainForestTree_Ex extends WorldGenAbstractTree { + + private final int minTreeHeight; + private final int randomTreeHeight; + private final Block wood; + private final Block leaves; + private final int woodMeta; + private final int leavesMeta; + + // return random.nextInt(5) == 0 ? new WorldGenTrees(false, 4 + random.nextInt(7), 3, 3, true) : new + // WorldGenRainforestTree1(BOPCBlocks.logs4, BOPCBlocks.colorizedLeaves2, 3, 2, false, 8, 8); + + public WorldGenRainForestTree_Ex(Block wood, Block leaves, int woodMeta, int leavesMeta, boolean doBlockNotify, + int minTreeHeight, int randomTreeHeight) { + super(doBlockNotify); + this.wood = wood; + this.leaves = leaves; + this.woodMeta = woodMeta; + this.leavesMeta = leavesMeta; + this.minTreeHeight = minTreeHeight; + this.randomTreeHeight = randomTreeHeight; + } + + @Override + public boolean generate(World world, Random random, int x, int y, int z) { + int treeHeight = random.nextInt(this.randomTreeHeight) + this.minTreeHeight; + boolean flag = true; + if ((y >= 1) && (y + treeHeight + 1 <= 256)) { + for (int i1 = y; i1 <= y + 1 + treeHeight; i1++) { + byte b0 = 1; + if (i1 == y) { + b0 = 0; + } + if (i1 >= y + 1 + treeHeight - 2) { + b0 = 2; + } + for (int j1 = x - b0; (j1 <= x + b0) && (flag); j1++) { + for (int k1 = z - b0; (k1 <= z + b0) && (flag); k1++) { + if ((i1 >= 0) && (i1 < 256)) { + Block block = world.getBlock(j1, i1, k1); + if (!isReplaceable(world, j1, i1, k1)) { + flag = false; + } + } else { + flag = false; + } + } + } + } + if (!flag) { + return false; + } + Block block2 = world.getBlock(x, y - 1, z); + + boolean isSoil = block2 + .canSustainPlant(world, x, y - 1, z, ForgeDirection.UP, (BlockSapling) Blocks.sapling); + if ((isSoil) && (y < 256 - treeHeight - 1)) { + block2.onPlantGrow(world, x, y - 1, z, x, y, z); + byte b0 = 3; + byte b1 = 0; + Logger.WARNING("Sapling located at X:" + x + " | Y:" + y + " | Z:" + z); + for (int k1 = y - b0 + treeHeight; k1 <= y + treeHeight; k1++) { + Logger + .WARNING("[1]| k1 = " + k1 + " | y = " + y + " | b0 = " + b0 + " | l = " + treeHeight + " | "); + int i3 = k1 - (y + treeHeight); + int l1 = b1 + 1 - i3; + for (int i2 = x - l1; i2 <= x + l1; i2++) { + int j2 = i2 - x; + Logger.WARNING("[2]| i2 = " + i2 + " | x = " + x + " | l1 = " + l1 + " | j2 = " + j2 + " | "); + for (int k2 = z - l1; k2 <= z + l1; k2++) { + int l2 = k2 - z; + Logger + .WARNING("[3]| k2 = " + k2 + " | z = " + z + " | l1 = " + l1 + " | l2 = " + l2 + " | "); + if ((Math.abs(j2) != l1) || (Math.abs(l2) != l1) + || ((random.nextInt(2) != 0) && (i3 != 0))) { + Block block1 = world.getBlock(i2, k1, k2); + if ((block1.isAir(world, i2, k1, k2)) || (block1.isLeaves(world, i2, k1, k2))) { + Logger.WARNING("Setting something as leaves?"); + setBlockAndNotifyAdequately(world, i2, k1, k2, this.leaves, this.leavesMeta); + } + } + } + } + } + for (int k1 = 0; k1 < treeHeight; k1++) { + Logger.WARNING("Building tree - Layer " + k1 + " | Max height is " + treeHeight); + Block block = world.getBlock(x, y + k1, z); + if ((block.isAir(world, x, y + k1, z)) || (block.isLeaves(world, x, y + k1, z))) { + setBlockAndNotifyAdequately(world, x, y + k1, z, this.wood, this.woodMeta); + + // Trying this to make trunk + setBlockAndNotifyAdequately(world, x, y + k1, z + 1, this.wood, this.woodMeta); + setBlockAndNotifyAdequately(world, x, y + k1, z - 1, this.wood, this.woodMeta); + setBlockAndNotifyAdequately(world, x + 1, y + k1, z, this.wood, this.woodMeta); + setBlockAndNotifyAdequately(world, x - 1, y + k1, z, this.wood, this.woodMeta); + + if (k1 >= 5) { + if (k1 % 5 == 0) { + // Bottom layer + Block block5 = world.getBlock(x, y + k1, z); + for (int xDir = -5; xDir <= 5; xDir++) { + for (int zDir = -5; zDir <= 5; zDir++) { + if (canRemoveLeafBlockLayer2(-5, 5, xDir, -5, 5, zDir)) { + Logger.WARNING( + "Doing Nothing at " + "x=" + xDir + " | y=" + y + " z=" + zDir); + } else { + Logger.WARNING( + "Trying to place leaves at " + "x=" + + xDir + + " | y=" + + y + + " z=" + + zDir); + block5 = world.getBlock(x + xDir, y + k1, z + zDir); + if (block5.isAir(world, x + xDir, y + k1, x + zDir)) { + setBlockAndNotifyAdequately( + world, + x + xDir, + y + k1, + z + zDir, + this.leaves, + this.leavesMeta); + } + } + } + } + // Next Layer + for (int xDir = -4; xDir <= 4; xDir++) { + for (int zDir = -4; zDir <= 4; zDir++) { + if (canRemoveLeafBlockLayer2(-4, 4, xDir, -4, 4, zDir)) { + Logger.WARNING( + "Doing Nothing at " + "x=" + + xDir + + " | y=" + + y + + k1 + + 1 + + " z=" + + zDir); + } else { + Logger.WARNING( + "Trying to place leaves at " + "x=" + + xDir + + " | y=" + + y + + k1 + + 1 + + " z=" + + zDir); + block5 = world.getBlock(x + xDir, y + k1 + 1, z + zDir); + if (block5.isAir(world, x + xDir, y + k1 + 1, x + zDir)) { + setBlockAndNotifyAdequately( + world, + x + xDir, + y + k1 + 1, + z + zDir, + this.leaves, + this.leavesMeta); + } + } + } + } + + // Third Layer + for (int xDir = -3; xDir <= 3; xDir++) { + for (int zDir = -3; zDir <= 3; zDir++) { + if (canRemoveLeafBlockLayer2(-3, 3, xDir, -3, 3, zDir)) { + Logger.WARNING( + "Doing Nothing at " + "x=" + + xDir + + " | y=" + + y + + k1 + + 2 + + " z=" + + zDir); + } else { + Logger.WARNING( + "Trying to place leaves at " + "x=" + + xDir + + " | y=" + + y + + k1 + + 2 + + " z=" + + zDir); + block5 = world.getBlock(x + xDir, y + k1 + 2, z + zDir); + if (block5.isAir(world, x + xDir, y + k1 + 2, x + zDir)) { + setBlockAndNotifyAdequately( + world, + x + xDir, + y + k1 + 2, + z + zDir, + this.leaves, + this.leavesMeta); + } + } + } + } + + // Fourth Layer + for (int xDir = -2; xDir <= 2; xDir++) { + for (int zDir = -2; zDir <= 2; zDir++) { + if (canRemoveLeafBlockLayer2(-2, 2, xDir, -2, 2, zDir)) { + Logger.WARNING( + "Doing Nothing at " + "x=" + + xDir + + " | y=" + + y + + k1 + + 3 + + " z=" + + zDir); + } else { + Logger.WARNING( + "Trying to place leaves at " + "x=" + + xDir + + " | y=" + + y + + k1 + + 3 + + " z=" + + zDir); + block5 = world.getBlock(x + xDir, y + k1 + 3, z + zDir); + if (block5.isAir(world, x + xDir, y + k1 + 3, x + zDir)) { + setBlockAndNotifyAdequately( + world, + x + xDir, + y + k1 + 3, + z + zDir, + this.leaves, + this.leavesMeta); + } + } + } + } + } else { + + } + } + + setBlockAndNotifyAdequately(world, x - 3, y + (treeHeight - 3), z, this.wood, this.woodMeta); + setBlockAndNotifyAdequately(world, x + 3, y + (treeHeight - 3), z, this.wood, this.woodMeta); + setBlockAndNotifyAdequately(world, x, y + (treeHeight - 3), z - 3, this.wood, this.woodMeta); + setBlockAndNotifyAdequately(world, x, y + (treeHeight - 3), z + 3, this.wood, this.woodMeta); + setBlockAndNotifyAdequately(world, x - 2, y + (treeHeight - 4), z, this.wood, this.woodMeta); + setBlockAndNotifyAdequately(world, x + 2, y + (treeHeight - 4), z, this.wood, this.woodMeta); + setBlockAndNotifyAdequately(world, x, y + (treeHeight - 4), z - 2, this.wood, this.woodMeta); + setBlockAndNotifyAdequately(world, x, y + (treeHeight - 4), z + 2, this.wood, this.woodMeta); + setBlockAndNotifyAdequately(world, x - 2, y + (treeHeight - 5), z, this.wood, this.woodMeta); + setBlockAndNotifyAdequately(world, x + 2, y + (treeHeight - 5), z, this.wood, this.woodMeta); + setBlockAndNotifyAdequately(world, x, y + (treeHeight - 5), z - 2, this.wood, this.woodMeta); + setBlockAndNotifyAdequately(world, x, y + (treeHeight - 5), z + 2, this.wood, this.woodMeta); + setBlockAndNotifyAdequately(world, x - 1, y + (treeHeight - 6), z, this.wood, this.woodMeta); + setBlockAndNotifyAdequately(world, x + 1, y + (treeHeight - 6), z, this.wood, this.woodMeta); + setBlockAndNotifyAdequately(world, x, y + (treeHeight - 6), z - 1, this.wood, this.woodMeta); + setBlockAndNotifyAdequately(world, x, y + (treeHeight - 6), z + 1, this.wood, this.woodMeta); + setBlockAndNotifyAdequately(world, x, y + (treeHeight - 3), z, this.leaves, this.leavesMeta); + setBlockAndNotifyAdequately(world, x, y + (treeHeight - 2), z, this.leaves, this.leavesMeta); + setBlockAndNotifyAdequately(world, x, y + (treeHeight - 1), z, this.leaves, this.leavesMeta); + setBlockAndNotifyAdequately(world, x, y + treeHeight, z, this.leaves, this.leavesMeta); + func_150515_a(world, x, y + (treeHeight - 4), z, Blocks.air); + func_150515_a(world, x, y + (treeHeight - 5), z, Blocks.air); + setBlockAndNotifyAdequately(world, x - 1, y + (treeHeight - 3), z, this.wood, this.woodMeta); + setBlockAndNotifyAdequately(world, x + 1, y + (treeHeight - 3), z, this.wood, this.woodMeta); + setBlockAndNotifyAdequately(world, x, y + (treeHeight - 3), z - 1, this.wood, this.woodMeta); + setBlockAndNotifyAdequately(world, x, y + (treeHeight - 3), z + 1, this.wood, this.woodMeta); + setBlockAndNotifyAdequately(world, x, y + (treeHeight - 2), z, this.wood, this.woodMeta); + } + } + return true; + } + return false; + } + return false; + } + + private boolean canRemoveLeafBlockLayer2(int xDirMin, int xDirMax, int xDir, int zDirMin, int zDirMax, int zDir) { + if (xDir == xDirMin || xDir == xDirMin + 1 || xDir == xDirMax || xDir == xDirMax - 1) { + if (zDir == zDirMin || zDir == zDirMin + 1 || zDir == zDirMax || zDir == zDirMax - 1) { + if (xDir == xDirMin + 1 && zDir == zDirMin + 1) { + return false; + } else if (xDir == xDirMin + 1 && zDir == zDirMax - 1) { + return false; + } else if (xDir == xDirMax - 1 && zDir == zDirMin + 1) { + return false; + } else if (xDir == xDirMax - 1 && zDir == zDirMax - 1) { + return false; + } + return true; + } + return false; + } else { + return false; + } + } +} |