diff options
8 files changed, 320 insertions, 18 deletions
diff --git a/src/Java/gtPlusPlus/api/objects/minecraft/FakeWorld.java b/src/Java/gtPlusPlus/api/objects/minecraft/FakeWorld.java new file mode 100644 index 0000000000..38cde74317 --- /dev/null +++ b/src/Java/gtPlusPlus/api/objects/minecraft/FakeWorld.java @@ -0,0 +1,5 @@ +package gtPlusPlus.api.objects.minecraft; + +public class FakeWorld { + +} diff --git a/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java b/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java index 722a4f3ff7..ef55792c63 100644 --- a/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java +++ b/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java @@ -463,13 +463,11 @@ public class ReflectionUtils { * therefore no more risk of code throwing NoClassDefFoundException. */ private static boolean isClassPresent(final String className) { - try { - Class.forName(className); - return true; - } catch (final Throwable ex) { - // Class or one of its dependencies is not present... - return false; + if (getClass(className) != null) { + return true; } + // Class or one of its dependencies is not present... + return false; } @Deprecated diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Muffler_Adv.java b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Muffler_Adv.java index 8c0c47bea2..2832941bdd 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Muffler_Adv.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Muffler_Adv.java @@ -23,7 +23,7 @@ public class GT_MetaTileEntity_Hatch_Muffler_Adv extends GT_MetaTileEntity_Hatch super.onConfigLoad(aConfig); if (CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK || CORE.GTNH) { try { - Integer a1 = (int) StaticFields59.getFieldFromGregtechProxy(false, "mPollutionSmogLimit"); + Integer a1 = (int) StaticFields59.getFieldFromGregtechProxy("mPollutionSmogLimit"); if (a1 != null && a1 > 0) { mPollutionSmogLimit = a1; } diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GregtechMetaPipeEntityFluid.java b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GregtechMetaPipeEntityFluid.java index 929dee22e4..8a29dc5db2 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GregtechMetaPipeEntityFluid.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GregtechMetaPipeEntityFluid.java @@ -1,10 +1,6 @@ package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations; -import net.minecraft.util.EnumChatFormatting; -import net.minecraftforge.fluids.FluidStack; -import gregtech.GT_Mod; import gregtech.api.enums.Dyes; -import gregtech.api.enums.Materials; import gregtech.api.enums.OrePrefixes; import gregtech.api.enums.SubTag; import gregtech.api.interfaces.ITexture; @@ -12,10 +8,9 @@ import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.implementations.GT_MetaPipeEntity_Fluid; import gregtech.api.objects.GT_RenderedTexture; - -import gtPlusPlus.core.lib.CORE; import gtPlusPlus.xmod.gregtech.api.enums.GregtechOrePrefixes.GT_Materials; import gtPlusPlus.xmod.gregtech.common.StaticFields59; +import net.minecraft.util.EnumChatFormatting; public class GregtechMetaPipeEntityFluid extends GT_MetaPipeEntity_Fluid { @@ -23,7 +18,7 @@ public class GregtechMetaPipeEntityFluid extends GT_MetaPipeEntity_Fluid { public static final boolean mGt6Pipe; static { - Boolean aGt6 = (Boolean) StaticFields59.getFieldFromGregtechProxy(false, "gt6Pipe"); + Boolean aGt6 = (Boolean) StaticFields59.getFieldFromGregtechProxy("gt6Pipe"); if (aGt6 != null) { mGt6Pipe = aGt6; } diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/Meta_GT_Proxy.java b/src/Java/gtPlusPlus/xmod/gregtech/common/Meta_GT_Proxy.java index 7505c2a808..77f3a31020 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/common/Meta_GT_Proxy.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/common/Meta_GT_Proxy.java @@ -32,6 +32,7 @@ import gtPlusPlus.api.objects.minecraft.FormattedTooltipString; import gtPlusPlus.core.handler.AchievementHandler; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.material.ELEMENT; +import gtPlusPlus.core.util.Utils; import gtPlusPlus.core.util.minecraft.FluidUtils; import gtPlusPlus.core.util.minecraft.MaterialUtils; import gtPlusPlus.xmod.gregtech.api.metatileentity.BaseCustomTileEntity; @@ -91,8 +92,10 @@ public class Meta_GT_Proxy { throw new RuntimeException(""); } - //Gotta set it here so that we don't try call gregtech too early. - StaticFields59.mGT6StylePipes = (boolean) StaticFields59.getFieldFromGregtechProxy(true, "gt6Pipe"); + //Gotta set it here so that we don't try call gregtech too early. + //Must set on the correct side + StaticFields59.mGT6StylePipes = (boolean) StaticFields59.getFieldFromGregtechProxy("gt6Pipe"); + GT_Log.out.println("GT++ Mod: Registering the BaseMetaTileEntity."); GameRegistry.registerTileEntity(tBaseMetaTileEntity.getClass(), "BaseMetaTileEntity_GTPP"); @@ -376,7 +379,7 @@ public class Meta_GT_Proxy { * @deprecated Use {@link StaticFields59#getFieldFromGregtechProxy(boolean,String)} instead */ public static Object getFieldFromGregtechProxy(boolean client, String fieldName) { - return StaticFields59.getFieldFromGregtechProxy(client, fieldName); + return StaticFields59.getFieldFromGregtechProxy(fieldName); } public void setCustomGregtechTooltip(String aNbtTagName, FormattedTooltipString aData) { diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/StaticFields59.java b/src/Java/gtPlusPlus/xmod/gregtech/common/StaticFields59.java index 2a3fd5e77c..99563b60ef 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/common/StaticFields59.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/common/StaticFields59.java @@ -22,6 +22,7 @@ import gregtech.api.util.GT_Recipe.GT_Recipe_Map; import gregtech.common.GT_Proxy; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.Utils; import gtPlusPlus.core.util.reflect.ProxyFinder; import gtPlusPlus.core.util.reflect.ReflectionUtils; import net.minecraft.block.Block; @@ -183,6 +184,11 @@ public class StaticFields59 { return null; } + + public static Object getFieldFromGregtechProxy(String fieldName) { + return getFieldFromGregtechProxy(Utils.isServer() ? false : true, fieldName); + } + public static Object getFieldFromGregtechProxy(boolean client, String fieldName) { Object proxyGT; diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/helpers/TreeFarmHelper.java b/src/Java/gtPlusPlus/xmod/gregtech/common/helpers/TreeFarmHelper.java index 3c60ae664e..624058f356 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/common/helpers/TreeFarmHelper.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/common/helpers/TreeFarmHelper.java @@ -320,7 +320,7 @@ public class TreeFarmHelper { if(blockHumus != null){ return blockHumus; } - else if (ReflectionUtils.doesClassExist("forestry.core.blocks.BlockSoil")){ + else if (isHumusLoaded){ final Class<?> humusClass = ReflectionUtils.getClass("forestry.core.blocks.BlockSoil"); final ItemStack humusStack = ItemUtils.getCorrectStacktype("Forestry:soil", 1); if (humusClass != null){ diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/helpers/treefarm/TreeGenerator.java b/src/Java/gtPlusPlus/xmod/gregtech/common/helpers/treefarm/TreeGenerator.java new file mode 100644 index 0000000000..7437bf19da --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/gregtech/common/helpers/treefarm/TreeGenerator.java @@ -0,0 +1,295 @@ +package gtPlusPlus.xmod.gregtech.common.helpers.treefarm; + +import java.util.Random; + +import gtPlusPlus.api.objects.data.AutoMap; +import gtPlusPlus.core.lib.CORE; +import net.minecraft.block.Block; +import net.minecraft.block.BlockSapling; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.util.Direction; +import net.minecraft.world.World; +import net.minecraft.world.gen.feature.WorldGenAbstractTree; +import net.minecraftforge.common.util.ForgeDirection; + +public class TreeGenerator { + + public static AutoMap<ItemStack> generateOutput(int aTreeSize){ + AutoMap<ItemStack> aOutputMap = new AutoMap<ItemStack>(); + + + return aOutputMap; + } + + public class FakeWorldGenerator extends WorldGenAbstractTree + { + /** The minimum height of a generated tree. */ + private final int minTreeHeight; + /** True if this tree should grow Vines. */ + private final boolean vinesGrow; + /** The metadata value of the wood to use in tree generation. */ + private final int metaWood; + /** The metadata value of the leaves to use in tree generation. */ + private final int metaLeaves; + + private boolean hasGenerated = false; + private AutoMap<ItemStack> aOutputsFromGenerator = new AutoMap<ItemStack>(); + + public FakeWorldGenerator() + { + this(4, 0, 0, false); + } + + public FakeWorldGenerator(int aMinHeight, int aWoodMeta, int aLeafMeta, boolean aVines) + { + super(false); + this.minTreeHeight = aMinHeight; + this.metaWood = aWoodMeta; + this.metaLeaves = aLeafMeta; + this.vinesGrow = aVines; + } + + + public AutoMap<ItemStack> getOutputFromTree(){ + if (!hasGenerated) { + generate(null, CORE.RANDOM, 0, 0, 0); + } + return aOutputsFromGenerator; + } + + + @Override + public boolean generate(World aWorld, Random aRand, int aWorldX, int aWorldRealY, int aWorldZ){ + + //Only Generate Once - This object is Cached + if (hasGenerated) { + return hasGenerated; + } + + //Set some static values + + //Dummy Value + int aWorldY = 10; + + int l = CORE.RANDOM.nextInt(3) + this.minTreeHeight; + boolean flag = true; + + if (aWorldY >= 1 && aWorldY + l + 1 <= 256) + { + byte b0; + int k1; + Block block; + + for (int i1 = aWorldY; i1 <= aWorldY + 1 + l; ++i1) + { + b0 = 1; + + if (i1 == aWorldY) + { + b0 = 0; + } + + if (i1 >= aWorldY + 1 + l - 2) + { + b0 = 2; + } + + for (int j1 = aWorldX - b0; j1 <= aWorldX + b0 && flag; ++j1) + { + for (k1 = aWorldZ - b0; k1 <= aWorldZ + b0 && flag; ++k1) + { + if (i1 >= 0 && i1 < 256) + { + block = aWorld.getBlock(j1, i1, k1); + + if (!this.isReplaceable(aWorld, j1, i1, k1)) + { + flag = false; + } + } + else + { + flag = false; + } + } + } + } + + if (!flag) + { + return false; + } + else + { + Block block2 = aWorld.getBlock(aWorldX, aWorldY - 1, aWorldZ); + + boolean isSoil = block2.canSustainPlant(aWorld, aWorldX, aWorldY - 1, aWorldZ, ForgeDirection.UP, (BlockSapling)Blocks.sapling); + if (isSoil && aWorldY < 256 - l - 1) + { + block2.onPlantGrow(aWorld, aWorldX, aWorldY - 1, aWorldZ, aWorldX, aWorldY, aWorldZ); + b0 = 3; + byte b1 = 0; + int l1; + int i2; + int j2; + int i3; + + for (k1 = aWorldY - b0 + l; k1 <= aWorldY + l; ++k1) + { + i3 = k1 - (aWorldY + l); + l1 = b1 + 1 - i3 / 2; + + for (i2 = aWorldX - l1; i2 <= aWorldX + l1; ++i2) + { + j2 = i2 - aWorldX; + + for (int k2 = aWorldZ - l1; k2 <= aWorldZ + l1; ++k2) + { + int l2 = k2 - aWorldZ; + + if (Math.abs(j2) != l1 || Math.abs(l2) != l1 || CORE.RANDOM.nextInt(2) != 0 && i3 != 0) + { + Block block1 = aWorld.getBlock(i2, k1, k2); + + if (block1.isAir(aWorld, i2, k1, k2) || block1.isLeaves(aWorld, i2, k1, k2)) + { + this.setBlockAndNotifyAdequately(aWorld, i2, k1, k2, Blocks.leaves, this.metaLeaves); + } + } + } + } + } + + for (k1 = 0; k1 < l; ++k1) + { + block = aWorld.getBlock(aWorldX, aWorldY + k1, aWorldZ); + + if (block.isAir(aWorld, aWorldX, aWorldY + k1, aWorldZ) || block.isLeaves(aWorld, aWorldX, aWorldY + k1, aWorldZ)) + { + this.setBlockAndNotifyAdequately(aWorld, aWorldX, aWorldY + k1, aWorldZ, Blocks.log, this.metaWood); + + if (this.vinesGrow && k1 > 0) + { + if (CORE.RANDOM.nextInt(3) > 0 && aWorld.isAirBlock(aWorldX - 1, aWorldY + k1, aWorldZ)) + { + this.setBlockAndNotifyAdequately(aWorld, aWorldX - 1, aWorldY + k1, aWorldZ, Blocks.vine, 8); + } + + if (CORE.RANDOM.nextInt(3) > 0 && aWorld.isAirBlock(aWorldX + 1, aWorldY + k1, aWorldZ)) + { + this.setBlockAndNotifyAdequately(aWorld, aWorldX + 1, aWorldY + k1, aWorldZ, Blocks.vine, 2); + } + + if (CORE.RANDOM.nextInt(3) > 0 && aWorld.isAirBlock(aWorldX, aWorldY + k1, aWorldZ - 1)) + { + this.setBlockAndNotifyAdequately(aWorld, aWorldX, aWorldY + k1, aWorldZ - 1, Blocks.vine, 1); + } + + if (CORE.RANDOM.nextInt(3) > 0 && aWorld.isAirBlock(aWorldX, aWorldY + k1, aWorldZ + 1)) + { + this.setBlockAndNotifyAdequately(aWorld, aWorldX, aWorldY + k1, aWorldZ + 1, Blocks.vine, 4); + } + } + } + } + + if (this.vinesGrow) + { + for (k1 = aWorldY - 3 + l; k1 <= aWorldY + l; ++k1) + { + i3 = k1 - (aWorldY + l); + l1 = 2 - i3 / 2; + + for (i2 = aWorldX - l1; i2 <= aWorldX + l1; ++i2) + { + for (j2 = aWorldZ - l1; j2 <= aWorldZ + l1; ++j2) + { + if (aWorld.getBlock(i2, k1, j2).isLeaves(aWorld, i2, k1, j2)) + { + if (CORE.RANDOM.nextInt(4) == 0 && aWorld.getBlock(i2 - 1, k1, j2).isAir(aWorld, i2 - 1, k1, j2)) + { + this.growVines(aWorld, i2 - 1, k1, j2, 8); + } + + if (CORE.RANDOM.nextInt(4) == 0 && aWorld.getBlock(i2 + 1, k1, j2).isAir(aWorld, i2 + 1, k1, j2)) + { + this.growVines(aWorld, i2 + 1, k1, j2, 2); + } + + if (CORE.RANDOM.nextInt(4) == 0 && aWorld.getBlock(i2, k1, j2 - 1).isAir(aWorld, i2, k1, j2 - 1)) + { + this.growVines(aWorld, i2, k1, j2 - 1, 1); + } + + if (CORE.RANDOM.nextInt(4) == 0 && aWorld.getBlock(i2, k1, j2 + 1).isAir(aWorld, i2, k1, j2 + 1)) + { + this.growVines(aWorld, i2, k1, j2 + 1, 4); + } + } + } + } + } + + if (CORE.RANDOM.nextInt(5) == 0 && l > 5) + { + for (k1 = 0; k1 < 2; ++k1) + { + for (i3 = 0; i3 < 4; ++i3) + { + if (CORE.RANDOM.nextInt(4 - k1) == 0) + { + l1 = CORE.RANDOM.nextInt(3); + this.setBlockAndNotifyAdequately(aWorld, aWorldX + Direction.offsetX[Direction.rotateOpposite[i3]], aWorldY + l - 5 + k1, aWorldZ + Direction.offsetZ[Direction.rotateOpposite[i3]], Blocks.cocoa, l1 << 2 | i3); + } + } + } + } + } + + hasGenerated = true; + return true; + } + else + { + return false; + } + } + } + else + { + return false; + } + } + + /** + * Grows vines downward from the given block for a given length. Args: World, x, starty, z, vine-length + */ + private void growVines(World aWorld, int aX, int aY, int aZ, int aMeta) + { + this.setBlockAndNotifyAdequately(aWorld, aX, aY, aZ, Blocks.vine, aMeta); + int i1 = 4; + + while (true) + { + --aY; + + if (!aWorld.getBlock(aX, aY, aZ).isAir(aWorld, aX, aY, aZ) || i1 <= 0) + { + return; + } + + this.setBlockAndNotifyAdequately(aWorld, aX, aY, aZ, Blocks.vine, aMeta); + --i1; + } + } + + @Override + protected void setBlockAndNotifyAdequately(World aWorld, int aX, int aY, int aZ, Block aBlock, int aMeta) { + + super.setBlockAndNotifyAdequately(aWorld, aX, aY, aZ, aBlock, aMeta); + } + } + + +} |