From ddefc4f7b11a3c0fab7f89416beac017634e58e0 Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Wed, 24 Apr 2019 17:55:18 +1000 Subject: % More work on rewriting the Tree Farmer. % Renamed Tree Farmer Casing. % Cleaned up a few imports. $ Fixed assorted minor bugs with Multis. $ Fixed Issue with GT_Utilities via ASM. --- .../gtPlusPlus/api/objects/minecraft/BlockPos.java | 12 +- .../api/objects/minecraft/FakeBlockPos.java | 253 +++++++++++++++++++++ .../api/objects/minecraft/FakeWorld.java | 153 ++++++++++++- 3 files changed, 415 insertions(+), 3 deletions(-) create mode 100644 src/Java/gtPlusPlus/api/objects/minecraft/FakeBlockPos.java (limited to 'src/Java/gtPlusPlus/api') diff --git a/src/Java/gtPlusPlus/api/objects/minecraft/BlockPos.java b/src/Java/gtPlusPlus/api/objects/minecraft/BlockPos.java index 9ab0f2eefb..7c11e7232b 100644 --- a/src/Java/gtPlusPlus/api/objects/minecraft/BlockPos.java +++ b/src/Java/gtPlusPlus/api/objects/minecraft/BlockPos.java @@ -42,8 +42,16 @@ public class BlockPos implements Serializable{ this.xPos = x; this.yPos = y; this.zPos = z; - this.dim = dim.provider.dimensionId; - this.world = dim; + + if (dim != null) { + this.dim = dim.provider.dimensionId; + this.world = dim; + } + else { + this.dim = 0; + this.world = null; + } + } public BlockPos(IGregTechTileEntity b) { diff --git a/src/Java/gtPlusPlus/api/objects/minecraft/FakeBlockPos.java b/src/Java/gtPlusPlus/api/objects/minecraft/FakeBlockPos.java new file mode 100644 index 0000000000..d0c1f3f040 --- /dev/null +++ b/src/Java/gtPlusPlus/api/objects/minecraft/FakeBlockPos.java @@ -0,0 +1,253 @@ +package gtPlusPlus.api.objects.minecraft; + +import java.util.HashSet; +import java.util.Set; + +import gtPlusPlus.api.objects.data.AutoMap; +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.world.World; +import net.minecraftforge.common.DimensionManager; + +public class FakeBlockPos extends BlockPos { + + private static final long serialVersionUID = -6442245826092414593L; + private Block aBlockAtPos; + private int aBlockMetaAtPos = 0; + + public static FakeBlockPos generateBlockPos(String sUUID) { + String[] s2 = sUUID.split("@"); + return new FakeBlockPos(s2); + } + + public FakeBlockPos(String[] s){ + this(Integer.parseInt(s[1]), Integer.parseInt(s[2]), Integer.parseInt(s[3]), Integer.parseInt(s[0])); + } + + public FakeBlockPos(int x, int y, int z, Block aBlock, int aMeta){ + this(x, y, z, 0); + aBlockAtPos = aBlock; + aBlockMetaAtPos = aMeta; + } + + private FakeBlockPos(int x, int y, int z, int dim){ + this(x, y, z, DimensionManager.getWorld(dim)); + } + + private FakeBlockPos(int x, int y, int z, World dim){ + super(x, y, z, null); + } + + public String getLocationString() { + String S = ""+this.xPos+"@"+this.yPos+"@"+this.zPos; + return S; + } + + public String getUniqueIdentifier() { + String S = ""+this.xPos+"@"+this.yPos+"@"+this.zPos+this.aBlockAtPos.getLocalizedName()+"@"+this.aBlockMetaAtPos; + return S; + } + + @Override + public int hashCode() { + int hash = 5; + hash += (13 * this.xPos); + hash += (19 * this.yPos); + hash += (31 * this.zPos); + hash += (17 * this.dim); + return hash; + } + + @Override + public boolean equals(Object other) { + if (other == null) { + return false; + } + if (other == this) { + return true; + } + if(!(other instanceof FakeBlockPos)) { + return false; + } + FakeBlockPos otherPoint = (FakeBlockPos) other; + return this.xPos == otherPoint.xPos && this.yPos == otherPoint.yPos && this.zPos == otherPoint.zPos; + } + + public int distanceFrom(FakeBlockPos target) { + if (target.dim != this.dim) { + return Short.MIN_VALUE; + } + return distanceFrom(target.xPos, target.yPos, target.zPos); + } + + /** + * + * @param x X coordinate of target. + * @param y Y coordinate of target. + * @param z Z coordinate of target. + * @return square of distance + */ + public int distanceFrom(int x, int y, int z) { + int distanceX = this.xPos - x; + int distanceY = this.yPos - y; + int distanceZ = this.zPos - z; + return distanceX * distanceX + distanceY * distanceY + distanceZ * distanceZ; + } + + public boolean isWithinRange(FakeBlockPos target, int range) { + if (target.dim != this.dim) { + return false; + } + return isWithinRange(target.xPos, target.yPos, target.zPos, range); + } + + public boolean isWithinRange(int x, int y, int z, int range) { + return distanceFrom(x, y, z) <= (range * range); + } + + + public FakeBlockPos getUp() { + return new FakeBlockPos(this.xPos, this.yPos+1, this.zPos, this.dim); + } + + public FakeBlockPos getDown() { + return new FakeBlockPos(this.xPos, this.yPos-1, this.zPos, this.dim); + } + + public FakeBlockPos getXPos() { + return new FakeBlockPos(this.xPos+1, this.yPos, this.zPos, this.dim); + } + + public FakeBlockPos getXNeg() { + return new FakeBlockPos(this.xPos-1, this.yPos, this.zPos, this.dim); + } + + public FakeBlockPos getZPos() { + return new FakeBlockPos(this.xPos, this.yPos, this.zPos+1, this.dim); + } + + public FakeBlockPos getZNeg() { + return new FakeBlockPos(this.xPos, this.yPos, this.zPos-1, this.dim); + } + + public AutoMap getSurroundingBlocks(){ + AutoMap sides = new AutoMap(); + sides.put(getUp()); + sides.put(getDown()); + sides.put(getXPos()); + sides.put(getXNeg()); + sides.put(getZPos()); + sides.put(getZNeg()); + return sides; + } + + public Block getBlockAtPos() { + return getBlockAtPos(this); + } + + public Block getBlockAtPos(FakeBlockPos pos) { + return getBlockAtPos(world, pos); + } + + public Block getBlockAtPos(World world, FakeBlockPos pos) { + return aBlockAtPos; + } + + public int getMetaAtPos() { + return getMetaAtPos(this); + } + + public int getMetaAtPos(FakeBlockPos pos) { + return getMetaAtPos(world, pos); + } + + public int getMetaAtPos(World world, FakeBlockPos pos) { + return aBlockMetaAtPos; + } + + public boolean hasSimilarNeighbour() { + return hasSimilarNeighbour(false); + } + + /** + * @param strict - Does this check Meta Data? + * @return - Does this block have a neighbour that is the same? + */ + public boolean hasSimilarNeighbour(boolean strict) { + for (BlockPos g : getSurroundingBlocks().values()) { + if (getBlockAtPos(g) == getBlockAtPos()) { + if (!strict) { + return true; + } + else { + if (getMetaAtPos() == getMetaAtPos(g)) { + return true; + } + } + } + } + return false; + } + + public AutoMap getSimilarNeighbour() { + return getSimilarNeighbour(false); + } + + /** + * @param strict - Does this check Meta Data? + * @return - Does this block have a neighbour that is the same? + */ + public AutoMap getSimilarNeighbour(boolean strict) { + AutoMap sides = new AutoMap(); + for (BlockPos g : getSurroundingBlocks().values()) { + if (getBlockAtPos(g) == getBlockAtPos()) { + if (!strict) { + sides.put(g); + } + else { + if (getMetaAtPos() == getMetaAtPos(g)) { + sides.put(g); + } + } + } + } + return sides; + } + + public Set getValidNeighboursAndSelf(){ + AutoMap h = getSimilarNeighbour(true); + h.put(this); + Set result = new HashSet(); + for (BlockPos f : h.values()) { + result.add(f); + } + return result; + } + + /** + * Called when a plant grows on this block, only implemented for saplings using the WorldGen*Trees classes right now. + * Modder may implement this for custom plants. + * This does not use ForgeDirection, because large/huge trees can be located in non-representable direction, + * so the source location is specified. + * Currently this just changes the block to dirt if it was grass. + * + * Note: This happens DURING the generation, the generation may not be complete when this is called. + * + * @param world Current world + * @param x Soil X + * @param y Soil Y + * @param z Soil Z + * @param sourceX Plant growth location X + * @param sourceY Plant growth location Y + * @param sourceZ Plant growth location Z + */ + public void onPlantGrow(FakeWorld world, int x, int y, int z, int sourceX, int sourceY, int sourceZ) + { + if (getBlockAtPos() == Blocks.grass || getBlockAtPos() == Blocks.farmland) + { + this.aBlockAtPos = Blocks.dirt; + this.aBlockMetaAtPos = 0; + } + } + +} diff --git a/src/Java/gtPlusPlus/api/objects/minecraft/FakeWorld.java b/src/Java/gtPlusPlus/api/objects/minecraft/FakeWorld.java index 38cde74317..21e7a7d331 100644 --- a/src/Java/gtPlusPlus/api/objects/minecraft/FakeWorld.java +++ b/src/Java/gtPlusPlus/api/objects/minecraft/FakeWorld.java @@ -1,5 +1,156 @@ package gtPlusPlus.api.objects.minecraft; -public class FakeWorld { +import java.util.HashMap; +import gregtech.api.enums.Materials; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.api.objects.data.AutoMap; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.biome.BiomeGenBase; +import net.minecraftforge.common.util.ForgeDirection; + +public class FakeWorld implements IBlockAccess { + + public HashMap mFakeWorldData = new HashMap(); + + /** + * Must be an odd number + */ + private int aWorldSize = 99; + private final int aDistanceFromOrigin; + private final int aWorldHeight; + + public FakeWorld() { + this(99); + } + + public FakeWorld(int aSize) { + if (MathUtils.isNumberEven(aSize)) { + aSize++; + } + aWorldSize = aSize; + aDistanceFromOrigin = ((aWorldSize-1)/2); + aWorldHeight = aDistanceFromOrigin >= 255 ? 255 : aDistanceFromOrigin; + Logger.INFO("Created a Fake World with data:"); + Logger.INFO("World Size: "+aWorldSize); + Logger.INFO("Distance from Origin in each dir: "+aDistanceFromOrigin); + Logger.INFO("World Height: "+aWorldHeight); + init(); + } + + private void init() { + Logger.INFO("Setting all Blocks in Fake World to Air."); + for (int y=0;y<=aWorldHeight;y++) { + for (int x=-aDistanceFromOrigin;x<=aDistanceFromOrigin;x++) { + for (int z=-aDistanceFromOrigin;z<=aDistanceFromOrigin;z++) { + FakeBlockPos aTempPos = new FakeBlockPos(x, y, z, Blocks.air, 0); + mFakeWorldData.put(aTempPos.getLocationString(), aTempPos); + } + } + } + Logger.INFO("Initialisation of FakeWorld is now complete."); + } + + public FakeBlockPos getBlockAtCoords(int x, int y, int z) { + String S = ""+x+"@"+y+"@"+z; + FakeBlockPos aBlock = mFakeWorldData.get(S); + return aBlock; + } + + public void setBlockAtCoords(int x, int y, int z, Block aBlock, int aMeta) { + FakeBlockPos aTempPos = new FakeBlockPos(x, y, z, aBlock, aMeta); + Logger.INFO("Setting "+x+", "+y+", "+z+" to "+aBlock.getLocalizedName()+":"+aMeta); + mFakeWorldData.put(aTempPos.getLocationString(), aTempPos); + } + + public AutoMap getAllBlocksStoredInFakeWorld(){ + AutoMap aOutput = new AutoMap(); + for (FakeBlockPos aPos : mFakeWorldData.values()) { + if (aPos.getBlockAtPos() == Blocks.air) { + continue; + } + else { + ItemStack aTempStack = ItemUtils.simpleMetaStack(aPos.getBlockAtPos(), aPos.getMetaAtPos(), 1); + if (ItemUtils.checkForInvalidItems(aTempStack)) { + aOutput.put(aTempStack); + } + } + } + return aOutput; + } + + public Block getBlock(int x, int y, int z) { + FakeBlockPos aPos = getBlockAtCoords(x, y, z); + return aPos.getBlockAtPos(); + } + + public boolean isAirBlock(int x, int y, int z) { + Block aBlock = getBlock(x, y, z); + return aBlock == Blocks.air || aBlock.getMaterial() == Material.air; + } + + + + + + + + + + + + + + @Override + public TileEntity getTileEntity(int p_147438_1_, int p_147438_2_, int p_147438_3_) { + return null; + } + + @Override + public int getLightBrightnessForSkyBlocks(int p_72802_1_, int p_72802_2_, int p_72802_3_, int p_72802_4_) { + return 0; + } + + @Override + public int getBlockMetadata(int x, int y, int z) { + return getBlockAtCoords(x, y, z).getMetaAtPos(); + } + + @Override + public int isBlockProvidingPowerTo(int p_72879_1_, int p_72879_2_, int p_72879_3_, int p_72879_4_) { + return 0; + } + + @Override + public BiomeGenBase getBiomeGenForCoords(int p_72807_1_, int p_72807_2_) { + return BiomeGenBase.plains; + } + + @Override + public int getHeight() { + return aWorldHeight; + } + + @Override + public boolean extendedLevelsInChunkCache() { + return false; + } + + @Override + public boolean isSideSolid(int x, int y, int z, ForgeDirection side, boolean _default) { + if (!isAirBlock(x, y, z)) { + return true; + } + return false; + } + + + } -- cgit From 866b2aee8b00f39c30728612dcdf3f10722e57f1 Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Fri, 26 Apr 2019 00:37:36 +1000 Subject: $ Fixed the Tree Farm. --- .../api/objects/minecraft/FakeWorld.java | 39 +++++-- .../minecraft/ThreadFakeWorldGenerator.java | 61 +++++++++++ .../common/helpers/treefarm/TreeGenerator.java | 35 +++++-- .../production/GregtechMetaTileEntityTreeFarm.java | 114 +++++++++++++++++---- 4 files changed, 210 insertions(+), 39 deletions(-) create mode 100644 src/Java/gtPlusPlus/api/objects/minecraft/ThreadFakeWorldGenerator.java (limited to 'src/Java/gtPlusPlus/api') diff --git a/src/Java/gtPlusPlus/api/objects/minecraft/FakeWorld.java b/src/Java/gtPlusPlus/api/objects/minecraft/FakeWorld.java index 21e7a7d331..800d8afaa4 100644 --- a/src/Java/gtPlusPlus/api/objects/minecraft/FakeWorld.java +++ b/src/Java/gtPlusPlus/api/objects/minecraft/FakeWorld.java @@ -18,6 +18,8 @@ import net.minecraftforge.common.util.ForgeDirection; public class FakeWorld implements IBlockAccess { + public static HashMap mStaticFakeWorldData; + public HashMap mFakeWorldData = new HashMap(); /** @@ -45,22 +47,36 @@ public class FakeWorld implements IBlockAccess { init(); } - private void init() { - Logger.INFO("Setting all Blocks in Fake World to Air."); - for (int y=0;y<=aWorldHeight;y++) { - for (int x=-aDistanceFromOrigin;x<=aDistanceFromOrigin;x++) { - for (int z=-aDistanceFromOrigin;z<=aDistanceFromOrigin;z++) { - FakeBlockPos aTempPos = new FakeBlockPos(x, y, z, Blocks.air, 0); - mFakeWorldData.put(aTempPos.getLocationString(), aTempPos); + public void init() { + + /*if (mStaticFakeWorldData == null) { + Logger.INFO("Setting all Blocks in Fake World to Air."); + mStaticFakeWorldData = new HashMap(); + for (int y=0;y<=aWorldHeight;y++) { + for (int x=-aDistanceFromOrigin;x<=aDistanceFromOrigin;x++) { + for (int z=-aDistanceFromOrigin;z<=aDistanceFromOrigin;z++) { + FakeBlockPos aTempPos = new FakeBlockPos(x, y, z, Blocks.air, 0); + mStaticFakeWorldData.put(aTempPos.getLocationString(), aTempPos); + } } } - } - Logger.INFO("Initialisation of FakeWorld is now complete."); + }*/ + //if (mStaticFakeWorldData != null) { + //Logger.INFO(" Instancing static air world."); + mFakeWorldData = new HashMap(); + //mFakeWorldData = (HashMap) mStaticFakeWorldData.clone(); + //} + + + //Logger.INFO("Initialisation of FakeWorld is now complete."); } public FakeBlockPos getBlockAtCoords(int x, int y, int z) { String S = ""+x+"@"+y+"@"+z; - FakeBlockPos aBlock = mFakeWorldData.get(S); + FakeBlockPos aBlock = mFakeWorldData.get(S); + if (aBlock == null) { + return new FakeBlockPos(x, y, z, Blocks.air, 0); + } return aBlock; } @@ -73,12 +89,13 @@ public class FakeWorld implements IBlockAccess { public AutoMap getAllBlocksStoredInFakeWorld(){ AutoMap aOutput = new AutoMap(); for (FakeBlockPos aPos : mFakeWorldData.values()) { - if (aPos.getBlockAtPos() == Blocks.air) { + if (aPos == null || aPos.getBlockAtPos() == Blocks.air) { continue; } else { ItemStack aTempStack = ItemUtils.simpleMetaStack(aPos.getBlockAtPos(), aPos.getMetaAtPos(), 1); if (ItemUtils.checkForInvalidItems(aTempStack)) { + //Logger.INFO("Output: "+aTempStack.getDisplayName()); aOutput.put(aTempStack); } } diff --git a/src/Java/gtPlusPlus/api/objects/minecraft/ThreadFakeWorldGenerator.java b/src/Java/gtPlusPlus/api/objects/minecraft/ThreadFakeWorldGenerator.java new file mode 100644 index 0000000000..393d3260b5 --- /dev/null +++ b/src/Java/gtPlusPlus/api/objects/minecraft/ThreadFakeWorldGenerator.java @@ -0,0 +1,61 @@ +package gtPlusPlus.api.objects.minecraft; + +import gtPlusPlus.xmod.gregtech.common.helpers.treefarm.TreeGenerator; + +public class ThreadFakeWorldGenerator extends Thread { + + public boolean canRun = true; + public boolean isRunning = false; + + private static final long INIT_TIME; + private static long internalTickCounter = 0; + + public TreeGenerator mGenerator; + + private static final ThreadFakeWorldGenerator mThread; + + static { + mThread = new ThreadFakeWorldGenerator(); + INIT_TIME = (System.currentTimeMillis()); + } + + public ThreadFakeWorldGenerator() { + setName("gtpp.handler.fakeworldtrees"); + run(); + } + + public static ThreadFakeWorldGenerator getInstance() { + return mThread; + } + + public static void stopThread() { + mThread.canRun = false; + } + + + @Override + public void run() { + + if (!isRunning) { + isRunning = true; + } + else { + return; + } + + if (canRun){ + if (mGenerator == null) { + mGenerator = new TreeGenerator(); + } + } + + while (mGenerator == null) { + if (mGenerator != null) { + break; + } + } + stopThread(); + } + + +} 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 a8603849b8..6093909167 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/common/helpers/treefarm/TreeGenerator.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/common/helpers/treefarm/TreeGenerator.java @@ -20,11 +20,15 @@ import net.minecraftforge.common.util.ForgeDirection; public class TreeGenerator { - private final FakeTreeInFakeWorldGenerator mTreeData; + private static final FakeTreeInFakeWorldGenerator mTreeData; + + static { + Logger.INFO("Created Fake Tree Generator."); + mTreeData = new FakeTreeInFakeWorldGenerator(); + } + public TreeGenerator() { - Logger.INFO("Created Fake Tree Generator."); - mTreeData = new FakeTreeInFakeWorldGenerator(); if (!mTreeData.hasGenerated) { mTreeData.generate(null, CORE.RANDOM, 0, 0, 0); } @@ -34,12 +38,14 @@ public class TreeGenerator { AutoMap aTemp = new AutoMap(); AutoMap aOutputMap = mTreeData.getOutputFromTree(); if (aOutputMap != null && aOutputMap.size() > 0) { + Logger.INFO("Valid tree data output"); return aOutputMap; } + Logger.INFO("Invalid tree data output"); return aTemp; } - public class FakeTreeInFakeWorldGenerator extends WorldGenAbstractTree + public static class FakeTreeInFakeWorldGenerator extends WorldGenAbstractTree { /** The minimum height of a generated tree. */ private final int minTreeHeight; @@ -78,12 +84,14 @@ public class TreeGenerator { public AutoMap getOutputFromTree(){ if (!hasGenerated) { + Logger.INFO("Generating Tree sample data"); generate(null, CORE.RANDOM, 0, 0, 0); } AutoMap aOutputMap = new AutoMap(); int aRandomTreeID = MathUtils.randInt(0, this.mFakeWorld.size()-1); FakeWorld aWorld = this.mFakeWorld.get(aRandomTreeID); if (aWorld != null) { + Logger.INFO("Getting all block data from fake world"); aOutputMap = aWorld.getAllBlocksStoredInFakeWorld(); } return aOutputMap; @@ -130,6 +138,8 @@ public class TreeGenerator { } } + private FakeWorld aFakeWorld; + public FakeWorld getWorld() { FakeWorld aWorld = this.mFakeWorld.get(mCurrentGeneratorIteration); if (aWorld == null) { @@ -143,7 +153,8 @@ public class TreeGenerator { FakeWorld aWorld = getWorld(); //Set some static values - + + Logger.INFO("Stepping through generateTree [0]"); //Dummy Value int aWorldY = 10; @@ -152,6 +163,7 @@ public class TreeGenerator { if (aWorldY >= 1 && aWorldY + l + 1 <= 256) { + Logger.INFO("Stepping through generateTree [1]"); byte b0; int k1; Block block; @@ -193,16 +205,19 @@ public class TreeGenerator { if (!flag) { + Logger.INFO("Stepping through generateTree [2]"); return false; } else { + Logger.INFO("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) { + Logger.INFO("Stepping through generateTree [4]"); aBlockToGrowPlantOn.onPlantGrow(aWorld, aWorldX, aWorldY - 1, aWorldZ, aWorldX, aWorldY, aWorldZ); b0 = 3; byte b1 = 0; @@ -236,6 +251,7 @@ public class TreeGenerator { } } } + Logger.INFO("Stepping through generateTree [5]"); for (k1 = 0; k1 < l; ++k1) { @@ -269,9 +285,11 @@ public class TreeGenerator { } } } + Logger.INFO("Stepping through generateTree [6]"); if (this.vinesGrow) { + Logger.INFO("Stepping through generateTree [7]"); for (k1 = aWorldY - 3 + l; k1 <= aWorldY + l; ++k1) { i3 = k1 - (aWorldY + l); @@ -306,6 +324,7 @@ public class TreeGenerator { } } } + Logger.INFO("Stepping through generateTree [8]"); if (CORE.RANDOM.nextInt(5) == 0 && l > 5) { @@ -322,16 +341,19 @@ public class TreeGenerator { } } } + Logger.INFO("Stepping through generateTree [9]"); return true; } else { + Logger.INFO("Stepping through generateTree [10]"); return false; } } } else { + Logger.INFO("Stepping through generateTree [11]"); return false; } } @@ -354,6 +376,7 @@ public class TreeGenerator { 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.INFO("Setting block "+aX+", "+aY+", "+aZ+" | "+aBlock.getLocalizedName()+" | "+aMeta); aWorld.setBlockAtCoords(aX, aY, aZ, aBlock, aMeta); //aOutputsFromGenerator.put(ItemUtils.simpleMetaStack(aBlock, aMeta, 1)); } diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntityTreeFarm.java b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntityTreeFarm.java index 23ab9afd61..2ee2acd726 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntityTreeFarm.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntityTreeFarm.java @@ -1,5 +1,9 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + import gregtech.api.GregTech_API; import gregtech.api.enums.TAE; import gregtech.api.enums.Textures; @@ -9,8 +13,10 @@ import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.objects.GT_RenderedTexture; import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.api.objects.data.AutoMap; +import gtPlusPlus.api.objects.minecraft.ThreadFakeWorldGenerator; import gtPlusPlus.core.block.ModBlocks; import gtPlusPlus.core.util.math.MathUtils; import gtPlusPlus.core.util.minecraft.FluidUtils; @@ -20,6 +26,7 @@ import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; import gtPlusPlus.xmod.gregtech.common.helpers.TreeFarmHelper; import gtPlusPlus.xmod.gregtech.common.helpers.treefarm.TreeGenerator; import net.minecraft.block.Block; +import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.FluidStack; @@ -42,6 +49,16 @@ public class GregtechMetaTileEntityTreeFarm extends GregtechMeta_MultiBlockBase mHatchName = ItemUtils.getLocalizedNameOfBlock(GregTech_API.sBlockMachines, 967); } + + + /* + * Static thread for Fake World Handling + */ + + + private static ScheduledExecutorService executor; + private static ThreadFakeWorldGenerator aThread; + public GregtechMetaTileEntityTreeFarm(final String aName) { super(aName); mFuelStack = FluidUtils.getFluidStack("cryotheum", 1); @@ -50,9 +67,32 @@ public class GregtechMetaTileEntityTreeFarm extends GregtechMeta_MultiBlockBase mCasingName = ItemUtils.getLocalizedNameOfBlock(ModBlocks.blockCasings2Misc, 15); mHatchName = ItemUtils.getLocalizedNameOfBlock(GregTech_API.sBlockMachines, 967); + /*if (executor == null || mTreeData == null) { + if (executor == null) { + executor = Executors.newScheduledThreadPool(10); + } + if (executor != null) { + if (aThread == null) { + aThread = new ThreadFakeWorldGenerator(); + executor.scheduleAtFixedRate(aThread, 0, 1, TimeUnit.SECONDS); + while (aThread.mGenerator == null) { + if (aThread.mGenerator != null) { + break; + } + } + if (aThread.mGenerator != null) { + mTreeData = aThread.mGenerator; + } + } + } + }*/ + if (mTreeData == null) { - mTreeData = new TreeGenerator(); + mTreeData = new TreeGenerator(); } + + + } @@ -117,7 +157,8 @@ public class GregtechMetaTileEntityTreeFarm extends GregtechMeta_MultiBlockBase } public boolean isCorrectMachinePart(final ItemStack aStack) { - return TreeFarmHelper.isCorrectPart(aStack); + //return TreeFarmHelper.isCorrectPart(aStack); + return true; } public boolean isFacingValid(final byte aFacing) { @@ -125,42 +166,71 @@ public class GregtechMetaTileEntityTreeFarm extends GregtechMeta_MultiBlockBase } public boolean checkRecipe(final ItemStack aStack) { - Logger.INFO("Trying to process virtual tree farming"); + //Logger.INFO("Trying to process virtual tree farming"); if (mTreeData != null) { - Logger.INFO("Tree Data is valid"); - this.getBaseMetaTileEntity().enableWorking(); + //Logger.INFO("Tree Data is valid"); + + long tVoltage = getMaxInputVoltage(); + byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); + this.mMaxProgresstime = 100; - this.mEUt = -500; + this.mEUt = 500; + + this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); this.mEfficiencyIncrease = 10000; + + // Overclock + if (this.mEUt <= 16) { + this.mEUt = (this.mEUt * (1 << tTier - 1) * (1 << tTier - 1)); + this.mMaxProgresstime = (this.mMaxProgresstime / (1 << tTier - 1)); + } else { + while (this.mEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) { + this.mEUt *= 4; + this.mMaxProgresstime /= 2; + } + } + + if (this.mEUt > 0) { + this.mEUt = (-this.mEUt); + } + + - int aChance = MathUtils.randInt(0, 10000); + int aChance = MathUtils.randInt(0, 10); AutoMap aOutputs = new AutoMap(); try { - Logger.INFO("Output Chance - "+aChance+" | Valid number? "+(aChance < 100)); - if (aChance < 100) { - //1% Chance per Tick - aOutputs = mTreeData.generateOutput(0); - if (aOutputs.size() > 0) { - Logger.INFO("Generated some Loot, adding it to the output busses"); - for (ItemStack aOutputItemStack : aOutputs) { - this.addOutput(aOutputItemStack); - } - Logger.INFO("Updating Slots"); - this.updateSlots(); - } + //Logger.INFO("Output Chance - "+aChance+" | Valid number? "+(aChance < 1000)); + if (aChance < 8) { + //1% Chance per Tick + for (int u=0; u<(Math.max(1, (MathUtils.randInt((3*tTier), 100)*tTier*tTier)/8));u++) { + aOutputs = mTreeData.generateOutput(0); + if (aOutputs.size() > 0) { + Logger.INFO("Generated some Loot, adding it to the output busses"); + + ItemStack aLeaves = ItemUtils.getSimpleStack(Blocks.leaves); + + for (ItemStack aOutputItemStack : aOutputs) { + if (!GT_Utility.areStacksEqual(aLeaves, aOutputItemStack)) { + this.addOutput(aOutputItemStack); + } + } + Logger.INFO("Updating Slots"); + this.updateSlots(); + } + } + } } catch (Throwable t) { t.printStackTrace(); } - Logger.INFO("Valid Recipe"); + //Logger.INFO("Valid Recipe"); return true; } else { - Logger.INFO("Invalid Recipe"); - this.getBaseMetaTileEntity().disableWorking(); + //Logger.INFO("Invalid Recipe"); return false; } //return this.checkRecipeGeneric(4, 100, 100); -- cgit From cf5475a417af586af27ae1de3d5e52e374c5a0b7 Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Fri, 26 Apr 2019 00:41:41 +1000 Subject: % Re-enabled Tree Farmer recipes. - Disabled some logging. --- .../api/objects/minecraft/FakeWorld.java | 18 +++++----- .../gtPlusPlus/core/recipe/RECIPES_Machines.java | 8 ++--- .../common/helpers/treefarm/TreeGenerator.java | 38 +++++++++++----------- .../production/GregtechMetaTileEntityTreeFarm.java | 16 ++++----- 4 files changed, 40 insertions(+), 40 deletions(-) (limited to 'src/Java/gtPlusPlus/api') diff --git a/src/Java/gtPlusPlus/api/objects/minecraft/FakeWorld.java b/src/Java/gtPlusPlus/api/objects/minecraft/FakeWorld.java index 800d8afaa4..8ee033a341 100644 --- a/src/Java/gtPlusPlus/api/objects/minecraft/FakeWorld.java +++ b/src/Java/gtPlusPlus/api/objects/minecraft/FakeWorld.java @@ -40,17 +40,17 @@ public class FakeWorld implements IBlockAccess { aWorldSize = aSize; aDistanceFromOrigin = ((aWorldSize-1)/2); aWorldHeight = aDistanceFromOrigin >= 255 ? 255 : aDistanceFromOrigin; - Logger.INFO("Created a Fake World with data:"); - Logger.INFO("World Size: "+aWorldSize); - Logger.INFO("Distance from Origin in each dir: "+aDistanceFromOrigin); - Logger.INFO("World Height: "+aWorldHeight); + Logger.WARNING("Created a Fake World with data:"); + Logger.WARNING("World Size: "+aWorldSize); + Logger.WARNING("Distance from Origin in each dir: "+aDistanceFromOrigin); + Logger.WARNING("World Height: "+aWorldHeight); init(); } public void init() { /*if (mStaticFakeWorldData == null) { - Logger.INFO("Setting all Blocks in Fake World to Air."); + Logger.WARNING("Setting all Blocks in Fake World to Air."); mStaticFakeWorldData = new HashMap(); for (int y=0;y<=aWorldHeight;y++) { for (int x=-aDistanceFromOrigin;x<=aDistanceFromOrigin;x++) { @@ -62,13 +62,13 @@ public class FakeWorld implements IBlockAccess { } }*/ //if (mStaticFakeWorldData != null) { - //Logger.INFO(" Instancing static air world."); + //Logger.WARNING(" Instancing static air world."); mFakeWorldData = new HashMap(); //mFakeWorldData = (HashMap) mStaticFakeWorldData.clone(); //} - //Logger.INFO("Initialisation of FakeWorld is now complete."); + //Logger.WARNING("Initialisation of FakeWorld is now complete."); } public FakeBlockPos getBlockAtCoords(int x, int y, int z) { @@ -82,7 +82,7 @@ public class FakeWorld implements IBlockAccess { public void setBlockAtCoords(int x, int y, int z, Block aBlock, int aMeta) { FakeBlockPos aTempPos = new FakeBlockPos(x, y, z, aBlock, aMeta); - Logger.INFO("Setting "+x+", "+y+", "+z+" to "+aBlock.getLocalizedName()+":"+aMeta); + Logger.WARNING("Setting "+x+", "+y+", "+z+" to "+aBlock.getLocalizedName()+":"+aMeta); mFakeWorldData.put(aTempPos.getLocationString(), aTempPos); } @@ -95,7 +95,7 @@ public class FakeWorld implements IBlockAccess { else { ItemStack aTempStack = ItemUtils.simpleMetaStack(aPos.getBlockAtPos(), aPos.getMetaAtPos(), 1); if (ItemUtils.checkForInvalidItems(aTempStack)) { - //Logger.INFO("Output: "+aTempStack.getDisplayName()); + //Logger.WARNING("Output: "+aTempStack.getDisplayName()); aOutput.put(aTempStack); } } diff --git a/src/Java/gtPlusPlus/core/recipe/RECIPES_Machines.java b/src/Java/gtPlusPlus/core/recipe/RECIPES_Machines.java index c26b01d0f7..e9c1da024c 100644 --- a/src/Java/gtPlusPlus/core/recipe/RECIPES_Machines.java +++ b/src/Java/gtPlusPlus/core/recipe/RECIPES_Machines.java @@ -801,10 +801,10 @@ public class RECIPES_Machines { RECIPE_IndustrialSieveGrate); } - if (CORE.ConfigSwitches.enableMultiblock_TreeFarmer){/* + if (CORE.ConfigSwitches.enableMultiblock_TreeFarmer){ //Industrial Tree Farmer RECIPE_TreeFarmController = GregtechItemList.Industrial_TreeFarm.get(1); - RECIPE_TreeFarmFrame = GregtechItemList.TreeFarmer_Structural.get(Casing_Amount); + RECIPE_TreeFarmFrame = GregtechItemList.Casing_PLACEHOLDER_TreeFarmer.get(Casing_Amount); //Industrial Tree Farm Controller if (!GTNH) { RecipeUtils.addShapedGregtechRecipe( @@ -813,7 +813,7 @@ public class RECIPES_Machines { "plateEglinSteel", CI.machineCasing_MV, "plateEglinSteel", RECIPE_TreeFarmController); } - if (GTNH) { + else { RecipeUtils.addShapedGregtechRecipe( "plateEglinSteel", "rotorEglinSteel", "plateEglinSteel", "cableGt02Silver", "pipeMediumStainlessSteel", "cableGt02Silver", @@ -826,7 +826,7 @@ public class RECIPES_Machines { "plankWood", "frameGtTumbaga", "plankWood", "plankWood", "plankWood", "plankWood", RECIPE_TreeFarmFrame); - */} + } if (CORE.ConfigSwitches.enableMachine_Tesseracts){ //Tesseracts 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 6093909167..b94ebf2918 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/common/helpers/treefarm/TreeGenerator.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/common/helpers/treefarm/TreeGenerator.java @@ -23,7 +23,7 @@ public class TreeGenerator { private static final FakeTreeInFakeWorldGenerator mTreeData; static { - Logger.INFO("Created Fake Tree Generator."); + Logger.WARNING("Created Fake Tree Generator."); mTreeData = new FakeTreeInFakeWorldGenerator(); } @@ -38,10 +38,10 @@ public class TreeGenerator { AutoMap aTemp = new AutoMap(); AutoMap aOutputMap = mTreeData.getOutputFromTree(); if (aOutputMap != null && aOutputMap.size() > 0) { - Logger.INFO("Valid tree data output"); + Logger.WARNING("Valid tree data output"); return aOutputMap; } - Logger.INFO("Invalid tree data output"); + Logger.WARNING("Invalid tree data output"); return aTemp; } @@ -78,20 +78,20 @@ public class TreeGenerator { this.vinesGrow = aVines; this.mFakeWorld = new AutoMap(); this.mTreesToGenerate = aTreeCount; - Logger.INFO("Created Fake Tree In Fake World Instance."); + Logger.WARNING("Created Fake Tree In Fake World Instance."); } public AutoMap getOutputFromTree(){ if (!hasGenerated) { - Logger.INFO("Generating Tree sample data"); + Logger.WARNING("Generating Tree sample data"); generate(null, CORE.RANDOM, 0, 0, 0); } AutoMap aOutputMap = new AutoMap(); int aRandomTreeID = MathUtils.randInt(0, this.mFakeWorld.size()-1); FakeWorld aWorld = this.mFakeWorld.get(aRandomTreeID); if (aWorld != null) { - Logger.INFO("Getting all block data from fake world"); + //Logger.WARNING("Getting all block data from fake world"); aOutputMap = aWorld.getAllBlocksStoredInFakeWorld(); } return aOutputMap; @@ -154,7 +154,7 @@ public class TreeGenerator { //Set some static values - Logger.INFO("Stepping through generateTree [0]"); + Logger.WARNING("Stepping through generateTree [0]"); //Dummy Value int aWorldY = 10; @@ -163,7 +163,7 @@ public class TreeGenerator { if (aWorldY >= 1 && aWorldY + l + 1 <= 256) { - Logger.INFO("Stepping through generateTree [1]"); + Logger.WARNING("Stepping through generateTree [1]"); byte b0; int k1; Block block; @@ -205,19 +205,19 @@ public class TreeGenerator { if (!flag) { - Logger.INFO("Stepping through generateTree [2]"); + Logger.WARNING("Stepping through generateTree [2]"); return false; } else { - Logger.INFO("Stepping through generateTree [3]"); + 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) { - Logger.INFO("Stepping through generateTree [4]"); + Logger.WARNING("Stepping through generateTree [4]"); aBlockToGrowPlantOn.onPlantGrow(aWorld, aWorldX, aWorldY - 1, aWorldZ, aWorldX, aWorldY, aWorldZ); b0 = 3; byte b1 = 0; @@ -251,7 +251,7 @@ public class TreeGenerator { } } } - Logger.INFO("Stepping through generateTree [5]"); + Logger.WARNING("Stepping through generateTree [5]"); for (k1 = 0; k1 < l; ++k1) { @@ -285,11 +285,11 @@ public class TreeGenerator { } } } - Logger.INFO("Stepping through generateTree [6]"); + Logger.WARNING("Stepping through generateTree [6]"); if (this.vinesGrow) { - Logger.INFO("Stepping through generateTree [7]"); + Logger.WARNING("Stepping through generateTree [7]"); for (k1 = aWorldY - 3 + l; k1 <= aWorldY + l; ++k1) { i3 = k1 - (aWorldY + l); @@ -324,7 +324,7 @@ public class TreeGenerator { } } } - Logger.INFO("Stepping through generateTree [8]"); + Logger.WARNING("Stepping through generateTree [8]"); if (CORE.RANDOM.nextInt(5) == 0 && l > 5) { @@ -341,19 +341,19 @@ public class TreeGenerator { } } } - Logger.INFO("Stepping through generateTree [9]"); + Logger.WARNING("Stepping through generateTree [9]"); return true; } else { - Logger.INFO("Stepping through generateTree [10]"); + Logger.WARNING("Stepping through generateTree [10]"); return false; } } } else { - Logger.INFO("Stepping through generateTree [11]"); + Logger.WARNING("Stepping through generateTree [11]"); return false; } } @@ -376,7 +376,7 @@ public class TreeGenerator { 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.INFO("Setting block "+aX+", "+aY+", "+aZ+" | "+aBlock.getLocalizedName()+" | "+aMeta); + Logger.WARNING("Setting block "+aX+", "+aY+", "+aZ+" | "+aBlock.getLocalizedName()+" | "+aMeta); aWorld.setBlockAtCoords(aX, aY, aZ, aBlock, aMeta); //aOutputsFromGenerator.put(ItemUtils.simpleMetaStack(aBlock, aMeta, 1)); } diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntityTreeFarm.java b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntityTreeFarm.java index 2ee2acd726..4357765303 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntityTreeFarm.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntityTreeFarm.java @@ -166,9 +166,9 @@ public class GregtechMetaTileEntityTreeFarm extends GregtechMeta_MultiBlockBase } public boolean checkRecipe(final ItemStack aStack) { - //Logger.INFO("Trying to process virtual tree farming"); + //Logger.WARNING("Trying to process virtual tree farming"); if (mTreeData != null) { - //Logger.INFO("Tree Data is valid"); + //Logger.WARNING("Tree Data is valid"); long tVoltage = getMaxInputVoltage(); byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); @@ -200,13 +200,13 @@ public class GregtechMetaTileEntityTreeFarm extends GregtechMeta_MultiBlockBase AutoMap aOutputs = new AutoMap(); try { - //Logger.INFO("Output Chance - "+aChance+" | Valid number? "+(aChance < 1000)); + //Logger.WARNING("Output Chance - "+aChance+" | Valid number? "+(aChance < 1000)); if (aChance < 8) { //1% Chance per Tick for (int u=0; u<(Math.max(1, (MathUtils.randInt((3*tTier), 100)*tTier*tTier)/8));u++) { aOutputs = mTreeData.generateOutput(0); if (aOutputs.size() > 0) { - Logger.INFO("Generated some Loot, adding it to the output busses"); + Logger.WARNING("Generated some Loot, adding it to the output busses"); ItemStack aLeaves = ItemUtils.getSimpleStack(Blocks.leaves); @@ -215,7 +215,7 @@ public class GregtechMetaTileEntityTreeFarm extends GregtechMeta_MultiBlockBase this.addOutput(aOutputItemStack); } } - Logger.INFO("Updating Slots"); + Logger.WARNING("Updating Slots"); this.updateSlots(); } } @@ -226,11 +226,11 @@ public class GregtechMetaTileEntityTreeFarm extends GregtechMeta_MultiBlockBase t.printStackTrace(); } - //Logger.INFO("Valid Recipe"); + //Logger.WARNING("Valid Recipe"); return true; } else { - //Logger.INFO("Invalid Recipe"); + //Logger.WARNING("Invalid Recipe"); return false; } //return this.checkRecipeGeneric(4, 100, 100); @@ -264,7 +264,7 @@ public class GregtechMetaTileEntityTreeFarm extends GregtechMeta_MultiBlockBase if (!isValidBlockForStructure(tTileEntity, CASING_TEXTURE_ID, true, aBlock, aMeta, ModBlocks.blockCasings2Misc, 15)) { - Logger.INFO("Bad centrifuge casing"); + Logger.WARNING("Bad centrifuge casing"); return false; } ++tAmount; -- cgit