aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/xmod/gregtech/common/helpers/treefarm
diff options
context:
space:
mode:
Diffstat (limited to 'src/Java/gtPlusPlus/xmod/gregtech/common/helpers/treefarm')
-rw-r--r--src/Java/gtPlusPlus/xmod/gregtech/common/helpers/treefarm/TreeGenerator.java152
1 files changed, 110 insertions, 42 deletions
diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/helpers/treefarm/TreeGenerator.java b/src/Java/gtPlusPlus/xmod/gregtech/common/helpers/treefarm/TreeGenerator.java
index 7437bf19da..c9f2d493ab 100644
--- a/src/Java/gtPlusPlus/xmod/gregtech/common/helpers/treefarm/TreeGenerator.java
+++ b/src/Java/gtPlusPlus/xmod/gregtech/common/helpers/treefarm/TreeGenerator.java
@@ -2,10 +2,15 @@ package gtPlusPlus.xmod.gregtech.common.helpers.treefarm;
import java.util.Random;
+import gtPlusPlus.api.objects.Logger;
import gtPlusPlus.api.objects.data.AutoMap;
+import gtPlusPlus.api.objects.minecraft.FakeBlockPos;
+import gtPlusPlus.api.objects.minecraft.FakeWorld;
import gtPlusPlus.core.lib.CORE;
+import gtPlusPlus.core.util.math.MathUtils;
import net.minecraft.block.Block;
import net.minecraft.block.BlockSapling;
+import net.minecraft.block.material.Material;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Direction;
@@ -15,14 +20,26 @@ import net.minecraftforge.common.util.ForgeDirection;
public class TreeGenerator {
- public static AutoMap<ItemStack> generateOutput(int aTreeSize){
- AutoMap<ItemStack> aOutputMap = new AutoMap<ItemStack>();
-
-
- return aOutputMap;
+ private final FakeTreeInFakeWorldGenerator mTreeData;
+
+ public TreeGenerator() {
+ Logger.INFO("Created Fake Tree Generator.");
+ mTreeData = new FakeTreeInFakeWorldGenerator();
+ if (!mTreeData.hasGenerated) {
+ mTreeData.generate(null, CORE.RANDOM, 0, 0, 0);
+ }
+ }
+
+ public AutoMap<ItemStack> generateOutput(int aTreeSize){
+ AutoMap<ItemStack> aTemp = new AutoMap<ItemStack>();
+ AutoMap<ItemStack> aOutputMap = mTreeData.getOutputFromTree();
+ if (aOutputMap != null && aOutputMap.size() > 0) {
+ return aOutputMap;
+ }
+ return aTemp;
}
- public class FakeWorldGenerator extends WorldGenAbstractTree
+ public class FakeTreeInFakeWorldGenerator extends WorldGenAbstractTree
{
/** The minimum height of a generated tree. */
private final int minTreeHeight;
@@ -33,21 +50,29 @@ public class TreeGenerator {
/** The metadata value of the leaves to use in tree generation. */
private final int metaLeaves;
+ private final AutoMap<FakeWorld> mFakeWorld;
+ private final int mTreesToGenerate;
+
+ private int mCurrentGeneratorIteration = 0;
+
private boolean hasGenerated = false;
private AutoMap<ItemStack> aOutputsFromGenerator = new AutoMap<ItemStack>();
- public FakeWorldGenerator()
+ public FakeTreeInFakeWorldGenerator()
{
- this(4, 0, 0, false);
+ this(4, 0, 0, false, 5000);
}
- public FakeWorldGenerator(int aMinHeight, int aWoodMeta, int aLeafMeta, boolean aVines)
+ public FakeTreeInFakeWorldGenerator(int aMinHeight, int aWoodMeta, int aLeafMeta, boolean aVines, int aTreeCount)
{
super(false);
this.minTreeHeight = aMinHeight;
this.metaWood = aWoodMeta;
this.metaLeaves = aLeafMeta;
this.vinesGrow = aVines;
+ this.mFakeWorld = new AutoMap<FakeWorld>();
+ this.mTreesToGenerate = aTreeCount;
+ Logger.INFO("Created Fake Tree In Fake World Instance.");
}
@@ -55,17 +80,66 @@ public class TreeGenerator {
if (!hasGenerated) {
generate(null, CORE.RANDOM, 0, 0, 0);
}
- return aOutputsFromGenerator;
+ AutoMap<ItemStack> aOutputMap = new AutoMap<ItemStack>();
+ int aRandomTreeID = MathUtils.randInt(0, this.mFakeWorld.size()-1);
+ FakeWorld aWorld = this.mFakeWorld.get(aRandomTreeID);
+ if (aWorld != null) {
+ aOutputMap = aWorld.getAllBlocksStoredInFakeWorld();
+ }
+ return aOutputMap;
+
}
+ @Override
+ protected boolean func_150523_a(Block p_150523_1_)
+ {
+ return p_150523_1_.getMaterial() == Material.air || p_150523_1_.getMaterial() == Material.leaves || p_150523_1_ == Blocks.grass || p_150523_1_ == Blocks.dirt || p_150523_1_ == Blocks.log || p_150523_1_ == Blocks.log2 || p_150523_1_ == Blocks.sapling || p_150523_1_ == Blocks.vine;
+ }
+
+ @Override
+ protected boolean isReplaceable(World world, int x, int y, int z)
+ {
+ FakeWorld aWorld = getWorld();
+ Block block = aWorld.getBlock(x, y, z);
+ return block.isAir(null, x, y, z) || block.isLeaves(null, x, y, z) || block.isWood(null, x, y, z) || func_150523_a(block);
+ }
@Override
- public boolean generate(World aWorld, Random aRand, int aWorldX, int aWorldRealY, int aWorldZ){
-
+ public boolean generate(World world, Random aRand, int aWorldX, int aWorldRealY, int aWorldZ){
//Only Generate Once - This object is Cached
if (hasGenerated) {
return hasGenerated;
+ }
+ else {
+ for (int yy=0;yy<mTreesToGenerate;yy++) {
+ generateTree(0, 0, 0);
+ mCurrentGeneratorIteration++;
+ }
+ hasGenerated = true;
+ if (this.mFakeWorld.size() > 0) {
+ for (FakeWorld aWorld : this.mFakeWorld) {
+ for (ItemStack aBlockInFakeWorld : aWorld.getAllBlocksStoredInFakeWorld()) {
+ aOutputsFromGenerator.add(aBlockInFakeWorld);
+ }
+ }
+ return true;
+ }
+ else {
+ return false;
+ }
+ }
+ }
+
+ public FakeWorld getWorld() {
+ FakeWorld aWorld = this.mFakeWorld.get(mCurrentGeneratorIteration);
+ if (aWorld == null) {
+ aWorld = (this.mFakeWorld.set(mCurrentGeneratorIteration, new FakeWorld(200)));
}
+ return aWorld;
+ }
+
+ public boolean generateTree(int aWorldX, int aWorldRealY, int aWorldZ) {
+ FakeWorld aWorld = getWorld();
//Set some static values
@@ -103,7 +177,7 @@ public class TreeGenerator {
{
block = aWorld.getBlock(j1, i1, k1);
- if (!this.isReplaceable(aWorld, j1, i1, k1))
+ if (!this.isReplaceable(null, j1, i1, k1))
{
flag = false;
}
@@ -123,11 +197,12 @@ public class TreeGenerator {
else
{
Block block2 = aWorld.getBlock(aWorldX, aWorldY - 1, aWorldZ);
+ FakeBlockPos aBlockToGrowPlantOn = aWorld.getBlockAtCoords(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);
+ aBlockToGrowPlantOn.onPlantGrow(aWorld, aWorldX, aWorldY - 1, aWorldZ, aWorldX, aWorldY, aWorldZ);
b0 = 3;
byte b1 = 0;
int l1;
@@ -152,7 +227,7 @@ public class TreeGenerator {
{
Block block1 = aWorld.getBlock(i2, k1, k2);
- if (block1.isAir(aWorld, i2, k1, k2) || block1.isLeaves(aWorld, i2, k1, k2))
+ if (block1.isAir(null, i2, k1, k2) || block1.isLeaves(null, i2, k1, k2))
{
this.setBlockAndNotifyAdequately(aWorld, i2, k1, k2, Blocks.leaves, this.metaLeaves);
}
@@ -165,7 +240,7 @@ public class TreeGenerator {
{
block = aWorld.getBlock(aWorldX, aWorldY + k1, aWorldZ);
- if (block.isAir(aWorld, aWorldX, aWorldY + k1, aWorldZ) || block.isLeaves(aWorld, aWorldX, aWorldY + k1, aWorldZ))
+ if (block.isAir(null, aWorldX, aWorldY + k1, aWorldZ) || block.isLeaves(null, aWorldX, aWorldY + k1, aWorldZ))
{
this.setBlockAndNotifyAdequately(aWorld, aWorldX, aWorldY + k1, aWorldZ, Blocks.log, this.metaWood);
@@ -205,24 +280,24 @@ public class TreeGenerator {
{
for (j2 = aWorldZ - l1; j2 <= aWorldZ + l1; ++j2)
{
- if (aWorld.getBlock(i2, k1, j2).isLeaves(aWorld, i2, k1, j2))
+ if (aWorld.getBlock(i2, k1, j2).isLeaves(null, i2, k1, j2))
{
- if (CORE.RANDOM.nextInt(4) == 0 && aWorld.getBlock(i2 - 1, k1, j2).isAir(aWorld, i2 - 1, k1, j2))
+ if (CORE.RANDOM.nextInt(4) == 0 && aWorld.getBlock(i2 - 1, k1, j2).isAir(null, 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))
+ if (CORE.RANDOM.nextInt(4) == 0 && aWorld.getBlock(i2 + 1, k1, j2).isAir(null, 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))
+ if (CORE.RANDOM.nextInt(4) == 0 && aWorld.getBlock(i2, k1, j2 - 1).isAir(null, 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))
+ if (CORE.RANDOM.nextInt(4) == 0 && aWorld.getBlock(i2, k1, j2 + 1).isAir(null, i2, k1, j2 + 1))
{
this.growVines(aWorld, i2, k1, j2 + 1, 4);
}
@@ -246,8 +321,6 @@ public class TreeGenerator {
}
}
}
-
- hasGenerated = true;
return true;
}
else
@@ -262,32 +335,27 @@ public class TreeGenerator {
}
}
- /**
+ /**
* 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)
+ private void growVines(FakeWorld 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;
+ int aLoopSize = vinesGrow ? MathUtils.randInt(0, 4) : 0;
+ for (int i=0;i<aLoopSize;i++) {
+ this.setBlockAndNotifyAdequately(aWorld, aX, aY, aZ, Blocks.vine, aMeta);
}
}
@Override
- protected void setBlockAndNotifyAdequately(World aWorld, int aX, int aY, int aZ, Block aBlock, int aMeta) {
-
- super.setBlockAndNotifyAdequately(aWorld, aX, aY, aZ, aBlock, aMeta);
+ protected void setBlockAndNotifyAdequately(World aWorld, int aX, int aY, int aZ, Block aBlock, int aMeta) {
+ setBlockAndNotifyAdequately(getWorld(), aX, aY, aZ, aBlock, aMeta);
+ }
+
+ protected void setBlockAndNotifyAdequately(FakeWorld aWorld, int aX, int aY, int aZ, Block aBlock, int aMeta) {
+ if (aBlock != null && (aMeta >= 0 && aMeta <= Short.MAX_VALUE)) {
+ aWorld.setBlockAtCoords(aX, aY, aZ, aBlock, aMeta);
+ //aOutputsFromGenerator.put(ItemUtils.simpleMetaStack(aBlock, aMeta, 1));
+ }
}
}