aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/xmod/gregtech/common/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'src/Java/gtPlusPlus/xmod/gregtech/common/helpers')
-rw-r--r--src/Java/gtPlusPlus/xmod/gregtech/common/helpers/TreeFarmHelper.java31
-rw-r--r--src/Java/gtPlusPlus/xmod/gregtech/common/helpers/treefarm/TreeGenerator.java180
2 files changed, 167 insertions, 44 deletions
diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/helpers/TreeFarmHelper.java b/src/Java/gtPlusPlus/xmod/gregtech/common/helpers/TreeFarmHelper.java
index 624058f356..a87fac1dfd 100644
--- a/src/Java/gtPlusPlus/xmod/gregtech/common/helpers/TreeFarmHelper.java
+++ b/src/Java/gtPlusPlus/xmod/gregtech/common/helpers/TreeFarmHelper.java
@@ -285,6 +285,37 @@ public class TreeFarmHelper {
}
return SAWTOOL.NONE;
}
+
+ public static boolean isCorrectPart(final ItemStack aStack) {
+ if (aStack != null){
+ //Utils.LOG_WARNING("Found "+aStack.getDisplayName()+" in the GUI slot.");
+ if ((aStack.getItem() instanceof GT_MetaGenerated_Item_02) || (aStack.getItem() instanceof GT_MetaGenerated_Tool)){
+ if (OrePrefixes.craftingTool.contains(aStack)){
+ if (aStack.getDisplayName().toLowerCase().contains("saw") || aStack.getDisplayName().toLowerCase().contains("gt.metatool.01")){
+ if (aStack.getItemDamage() == 10){
+ return true;
+ }
+ else if (aStack.getItemDamage() == 140 || aStack.getDisplayName().toLowerCase().contains("gt.metatool.01.140")){
+ return true;
+ }
+ else if (aStack.getItemDamage() == 110 || aStack.getDisplayName().toLowerCase().contains("gt.metatool.01.110")){
+ return true;
+ }
+ else if (aStack.getItemDamage() == 112 || aStack.getDisplayName().toLowerCase().contains("gt.metatool.01.112")){
+ return true;
+ }
+ else if (aStack.getItemDamage() == 114 || aStack.getDisplayName().toLowerCase().contains("gt.metatool.01.114")){
+ return true;
+ }
+ else {
+ return false;
+ }
+ }
+ }
+ }
+ }
+ return false;
+ }
public static boolean isHumusLoaded = false;
public static boolean isForestryLogsLoaded = false;
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..b94ebf2918 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,32 @@ 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 static final FakeTreeInFakeWorldGenerator mTreeData;
+
+ static {
+ Logger.WARNING("Created Fake Tree Generator.");
+ mTreeData = new FakeTreeInFakeWorldGenerator();
}
- public class FakeWorldGenerator extends WorldGenAbstractTree
+
+ public TreeGenerator() {
+ 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) {
+ Logger.WARNING("Valid tree data output");
+ return aOutputMap;
+ }
+ Logger.WARNING("Invalid tree data output");
+ return aTemp;
+ }
+
+ public static class FakeTreeInFakeWorldGenerator extends WorldGenAbstractTree
{
/** The minimum height of a generated tree. */
private final int minTreeHeight;
@@ -33,42 +56,105 @@ 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.WARNING("Created Fake Tree In Fake World Instance.");
}
public AutoMap<ItemStack> getOutputFromTree(){
if (!hasGenerated) {
+ Logger.WARNING("Generating Tree sample data");
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) {
+ //Logger.WARNING("Getting all block data from fake world");
+ 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;
+ }
+ }
+ }
+
+ private FakeWorld aFakeWorld;
+
+ public FakeWorld getWorld() {
+ FakeWorld aWorld = this.mFakeWorld.get(mCurrentGeneratorIteration);
+ if (aWorld == null) {
+ this.mFakeWorld.set(mCurrentGeneratorIteration, new FakeWorld(200));
+ aWorld = this.mFakeWorld.get(mCurrentGeneratorIteration);
}
+ return aWorld;
+ }
+
+ public boolean generateTree(int aWorldX, int aWorldRealY, int aWorldZ) {
+ FakeWorld aWorld = getWorld();
//Set some static values
-
+
+ Logger.WARNING("Stepping through generateTree [0]");
//Dummy Value
int aWorldY = 10;
@@ -77,6 +163,7 @@ public class TreeGenerator {
if (aWorldY >= 1 && aWorldY + l + 1 <= 256)
{
+ Logger.WARNING("Stepping through generateTree [1]");
byte b0;
int k1;
Block block;
@@ -103,7 +190,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;
}
@@ -118,16 +205,20 @@ public class TreeGenerator {
if (!flag)
{
+ Logger.WARNING("Stepping through generateTree [2]");
return false;
}
else
{
+ Logger.WARNING("Stepping through generateTree [3]");
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)
+ if (/*isSoil &&*/ aWorldY < 256 - l - 1)
{
- block2.onPlantGrow(aWorld, aWorldX, aWorldY - 1, aWorldZ, aWorldX, aWorldY, aWorldZ);
+ Logger.WARNING("Stepping through generateTree [4]");
+ aBlockToGrowPlantOn.onPlantGrow(aWorld, aWorldX, aWorldY - 1, aWorldZ, aWorldX, aWorldY, aWorldZ);
b0 = 3;
byte b1 = 0;
int l1;
@@ -152,7 +243,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);
}
@@ -160,12 +251,13 @@ public class TreeGenerator {
}
}
}
+ Logger.WARNING("Stepping through generateTree [5]");
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))
+ 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);
@@ -193,9 +285,11 @@ public class TreeGenerator {
}
}
}
+ Logger.WARNING("Stepping through generateTree [6]");
if (this.vinesGrow)
{
+ Logger.WARNING("Stepping through generateTree [7]");
for (k1 = aWorldY - 3 + l; k1 <= aWorldY + l; ++k1)
{
i3 = k1 - (aWorldY + l);
@@ -205,24 +299,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);
}
@@ -230,6 +324,7 @@ public class TreeGenerator {
}
}
}
+ Logger.WARNING("Stepping through generateTree [8]");
if (CORE.RANDOM.nextInt(5) == 0 && l > 5)
{
@@ -246,48 +341,45 @@ public class TreeGenerator {
}
}
}
-
- hasGenerated = true;
+ Logger.WARNING("Stepping through generateTree [9]");
return true;
}
else
{
+ Logger.WARNING("Stepping through generateTree [10]");
return false;
}
}
}
else
{
+ Logger.WARNING("Stepping through generateTree [11]");
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)
+ 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)) {
+ Logger.WARNING("Setting block "+aX+", "+aY+", "+aZ+" | "+aBlock.getLocalizedName()+" | "+aMeta);
+ aWorld.setBlockAtCoords(aX, aY, aZ, aBlock, aMeta);
+ //aOutputsFromGenerator.put(ItemUtils.simpleMetaStack(aBlock, aMeta, 1));
+ }
}
}