From 2e20b14e06cf2ca637f6f40e968568cb21e3ecc0 Mon Sep 17 00:00:00 2001 From: Jason Mitchell Date: Sun, 18 Feb 2024 08:30:15 -0800 Subject: [PATCH] Allocation reduction (#62) * Allocation reduction --- dependencies.gradle | 6 +- gradle.properties | 9 +- settings.gradle | 2 +- .../forestry/apiculture/BeekeepingLogic.java | 2 +- .../multiblock/TileAlvearySwarmer.java | 5 +- .../java/forestry/core/gui/GuiAlyzer.java | 5 +- .../java/forestry/core/utils/vect/IVect.java | 29 +++++- .../forestry/core/utils/vect/MutableVect.java | 91 +++++++++++++++++++ .../java/forestry/core/utils/vect/Vect.java | 20 +++- .../java/forestry/farming/logic/Crop.java | 17 ++-- .../farming/logic/CropBasicAgriCraft.java | 11 ++- .../farming/logic/CropBasicFruit.java | 11 ++- .../farming/logic/CropBasicGrowthCraft.java | 15 +-- .../farming/logic/CropBasicIC2Crop.java | 5 +- .../forestry/farming/logic/CropBlock.java | 11 ++- .../forestry/farming/logic/CropFruit.java | 17 ++-- .../java/forestry/farming/logic/CropPeat.java | 13 ++- .../forestry/farming/logic/CropRubber.java | 7 +- .../forestry/farming/logic/FarmLogic.java | 5 +- .../farming/logic/FarmLogicArboreal.java | 26 +++--- .../farming/logic/FarmLogicCocoa.java | 33 ++++--- .../farming/logic/FarmLogicCrops.java | 5 +- .../farming/logic/FarmLogicEnder.java | 5 +- .../farming/logic/FarmLogicGourd.java | 5 +- .../farming/logic/FarmLogicInfernal.java | 5 +- .../farming/logic/FarmLogicOrchard.java | 68 +++++++------- .../forestry/farming/logic/FarmLogicPeat.java | 5 +- .../farming/logic/FarmLogicReeds.java | 5 +- .../farming/logic/FarmLogicRubber.java | 26 +++--- .../farming/logic/FarmLogicSucculent.java | 5 +- .../farming/multiblock/FarmController.java | 7 +- .../farming/multiblock/InventoryFarm.java | 6 +- 32 files changed, 329 insertions(+), 153 deletions(-) diff --git a/dependencies.gradle b/dependencies.gradle index 417dd1ecb..2dee653fa 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -2,9 +2,9 @@ dependencies { api('curse.maven:cofh-lib-220333:2388748') - devOnlyNonPublishable('com.github.GTNewHorizons:NotEnoughItems:2.5.3-GTNH:dev') - compileOnly('com.github.GTNewHorizons:inventory-tweaks:1.6.1:api') - compileOnly('com.github.GTNewHorizons:BuildCraft:7.1.38:api') + devOnlyNonPublishable('com.github.GTNewHorizons:NotEnoughItems:2.5.18-GTNH:dev') + compileOnly('com.github.GTNewHorizons:inventory-tweaks:1.6.2:api') + compileOnly('com.github.GTNewHorizons:BuildCraft:7.1.39:api') compileOnly('net.industrial-craft:industrialcraft-2:2.2.828-experimental:dev') compileOnly('curse.maven:craftguide-75557:2459320') } diff --git a/gradle.properties b/gradle.properties index 53d9c3ded..a9a8e01a5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -33,7 +33,7 @@ channel = stable mappingsVersion = 12 # Defines other MCP mappings for dependency deobfuscation. -remoteMappings = https://raw.githubusercontent.com/MinecraftForge/FML/1.7.10/conf/ +remoteMappings = https\://raw.githubusercontent.com/MinecraftForge/FML/1.7.10/conf/ # Select a default username for testing your mod. You can always override this per-run by running # `./gradlew runClient --username=AnotherPlayer`, or configuring this command in your IDE. @@ -61,6 +61,9 @@ gradleTokenModId = # [DEPRECATED] Mod name replacement token. gradleTokenModName = +# [DEPRECATED] Mod Group replacement token. +gradleTokenGroupName = + # [DEPRECATED] # Multiple source files can be defined here by providing a comma-separated list: Class1.java,Class2.java,Class3.java # public static final String VERSION = "GRADLETOKEN_VERSION"; @@ -123,7 +126,7 @@ includeWellKnownRepositories = true usesMavenPublishing = true # Maven repository to publish the mod to. -# mavenPublishUrl = https://nexus.gtnewhorizons.com/repository/releases/ +# mavenPublishUrl = https\://nexus.gtnewhorizons.com/repository/releases/ # Publishing to Modrinth requires you to set the MODRINTH_TOKEN environment variable to your current Modrinth API token. # @@ -187,5 +190,3 @@ curseForgeRelations = # This is meant to be set in $HOME/.gradle/gradle.properties. # ideaCheckSpotlessOnBuild = true -# Non-GTNH properties -gradleTokenGroupName = diff --git a/settings.gradle b/settings.gradle index e8946ada2..16a5b4ca7 100644 --- a/settings.gradle +++ b/settings.gradle @@ -17,7 +17,7 @@ pluginManagement { } plugins { - id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.8' + id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.14' } diff --git a/src/main/java/forestry/apiculture/BeekeepingLogic.java b/src/main/java/forestry/apiculture/BeekeepingLogic.java index 21f0a5acf..1a6100bff 100755 --- a/src/main/java/forestry/apiculture/BeekeepingLogic.java +++ b/src/main/java/forestry/apiculture/BeekeepingLogic.java @@ -115,7 +115,7 @@ public class BeekeepingLogic implements IBeekeepingLogic, IStreamable { Stack spawnCopy = new Stack<>(); if (spawn.size() < 128) spawnCopy.addAll(spawn); - else for (byte b = 0; b < 128; ++b) spawnCopy.add(spawn.get(b)); + else for (int b = 0; b < 128; ++b) spawnCopy.add(spawn.get(b)); NBTTagList nbttaglist = new NBTTagList(); while (!spawnCopy.isEmpty() && spawnCopy.size() <= 128) { NBTTagCompound nbttagcompound1 = new NBTTagCompound(); diff --git a/src/main/java/forestry/apiculture/multiblock/TileAlvearySwarmer.java b/src/main/java/forestry/apiculture/multiblock/TileAlvearySwarmer.java index fd82a8c4d..f18602120 100644 --- a/src/main/java/forestry/apiculture/multiblock/TileAlvearySwarmer.java +++ b/src/main/java/forestry/apiculture/multiblock/TileAlvearySwarmer.java @@ -8,8 +8,9 @@ ******************************************************************************/ package forestry.apiculture.multiblock; +import java.util.ArrayDeque; +import java.util.Deque; import java.util.Map.Entry; -import java.util.Stack; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.ISidedInventory; @@ -39,7 +40,7 @@ import forestry.core.utils.ItemStackUtil; public class TileAlvearySwarmer extends TileAlveary implements ISidedInventory, IActivatable, IAlvearyComponent.Active { private final InventorySwarmer inventory; - private final Stack pendingSpawns = new Stack<>(); + private final Deque pendingSpawns = new ArrayDeque<>(); private boolean active; public TileAlvearySwarmer() { diff --git a/src/main/java/forestry/core/gui/GuiAlyzer.java b/src/main/java/forestry/core/gui/GuiAlyzer.java index a81feff14..50c25c522 100755 --- a/src/main/java/forestry/core/gui/GuiAlyzer.java +++ b/src/main/java/forestry/core/gui/GuiAlyzer.java @@ -8,10 +8,11 @@ ******************************************************************************/ package forestry.core.gui; +import java.util.ArrayDeque; +import java.util.Deque; import java.util.HashMap; import java.util.Locale; import java.util.Map; -import java.util.Stack; import net.minecraft.client.renderer.RenderHelper; import net.minecraft.entity.player.EntityPlayer; @@ -208,7 +209,7 @@ public abstract class GuiAlyzer extends GuiForestry textLayout.drawLine(StringUtil.localize("gui.alyzer.classification") + ":", 12); textLayout.newLine(); - Stack hierarchy = new Stack<>(); + Deque hierarchy = new ArrayDeque<>(); IClassification classification = individual.getGenome().getPrimary().getBranch(); while (classification != null) { diff --git a/src/main/java/forestry/core/utils/vect/IVect.java b/src/main/java/forestry/core/utils/vect/IVect.java index c0418dc5d..4c9a7b369 100644 --- a/src/main/java/forestry/core/utils/vect/IVect.java +++ b/src/main/java/forestry/core/utils/vect/IVect.java @@ -16,7 +16,7 @@ import forestry.api.farming.FarmDirection; /** * Represents a position or dimensions. */ -public interface IVect { +public interface IVect extends Comparable { int getX(); @@ -34,5 +34,32 @@ public interface IVect { IVect add(ChunkCoordinates coordinates); + IVect multiply(int factor); + + IVect multiply(float factor); + int[] toArray(); + + Vect asImmutable(); + + MutableVect asMutable(); + + // NOTE: All classes implementing this must implement the same hashCode and equals methods as Vect + int hashCode(); + + boolean equals(Object obj); + + default int compareTo(IVect other) { + int x = this.getX() - other.getX(); + if (x != 0) { + return x; + } + + int y = this.getY() - other.getY(); + if (y != 0) { + return y; + } + + return this.getZ() - other.getZ(); + } } diff --git a/src/main/java/forestry/core/utils/vect/MutableVect.java b/src/main/java/forestry/core/utils/vect/MutableVect.java index 70c58acc4..5f43d8aad 100644 --- a/src/main/java/forestry/core/utils/vect/MutableVect.java +++ b/src/main/java/forestry/core/utils/vect/MutableVect.java @@ -22,6 +22,10 @@ public class MutableVect implements IVect { public int y; public int z; + public MutableVect() { + this(0, 0, 0); + } + public MutableVect(int x, int y, int z) { this.x = x; this.y = y; @@ -96,7 +100,16 @@ public class MutableVect implements IVect { return new int[] { x, y, z }; } + @Override public MutableVect multiply(float factor) { + this.x = Math.round(x * factor); + this.y = Math.round(y * factor); + this.z = Math.round(z * factor); + return this; + } + + @Override + public IVect multiply(int factor) { this.x *= factor; this.y *= factor; this.z *= factor; @@ -140,4 +153,82 @@ public class MutableVect implements IVect { public int getZ() { return z; } + + public MutableVect setX(int x) { + this.x = x; + return this; + } + + public MutableVect setY(int y) { + this.y = y; + return this; + } + + public MutableVect setZ(int z) { + this.z = z; + return this; + } + + public MutableVect set(int x, int y, int z) { + this.x = x; + this.y = y; + this.z = z; + return this; + } + + public MutableVect set(IVect vect) { + this.x = vect.getX(); + this.y = vect.getY(); + this.z = vect.getZ(); + return this; + } + + public MutableVect set(ChunkCoordinates coordinates) { + this.x = coordinates.posX; + this.y = coordinates.posY; + this.z = coordinates.posZ; + return this; + } + + public MutableVect set(ForgeDirection direction) { + this.x = direction.offsetX; + this.y = direction.offsetY; + this.z = direction.offsetZ; + return this; + } + + public MutableVect set(FarmDirection direction) { + return set(direction.getForgeDirection()); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + x; + result = prime * result + y; + result = prime * result + z; + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof IVect other) { + return x == other.getX() && y == other.getY() && z == other.getZ(); + } + return false; + } + + @Override + public Vect asImmutable() { + return new Vect(x, y, z); + } + + @Override + public MutableVect asMutable() { + return this; + } } diff --git a/src/main/java/forestry/core/utils/vect/Vect.java b/src/main/java/forestry/core/utils/vect/Vect.java index 6837f2027..e8f27a0f4 100644 --- a/src/main/java/forestry/core/utils/vect/Vect.java +++ b/src/main/java/forestry/core/utils/vect/Vect.java @@ -121,10 +121,12 @@ public class Vect implements IVect { return new int[] { x, y, z }; } + @Override public Vect multiply(int factor) { return new Vect(x * factor, y * factor, z * factor); } + @Override public Vect multiply(float factor) { return new Vect(Math.round(x * factor), Math.round(y * factor), Math.round(z * factor)); } @@ -149,11 +151,10 @@ public class Vect implements IVect { if (this == obj) { return true; } - if (!(obj instanceof Vect)) { - return false; + if ((obj instanceof IVect other)) { + return (x == other.getX()) && (y == other.getY()) && (z == other.getZ()); } - Vect other = (Vect) obj; - return (x == other.x) && (y == other.y) && (z == other.z); + return false; } @Override @@ -170,4 +171,15 @@ public class Vect implements IVect { public int getZ() { return z; } + + @Override + public Vect asImmutable() { + return this; + } + + @Override + public MutableVect asMutable() { + return new MutableVect(this); + } + } diff --git a/src/main/java/forestry/farming/logic/Crop.java b/src/main/java/forestry/farming/logic/Crop.java index bf7d09314..3dd3ce440 100755 --- a/src/main/java/forestry/farming/logic/Crop.java +++ b/src/main/java/forestry/farming/logic/Crop.java @@ -16,6 +16,7 @@ import net.minecraft.world.World; import forestry.api.farming.ICrop; import forestry.core.config.Constants; +import forestry.core.utils.vect.IVect; import forestry.core.utils.vect.Vect; public abstract class Crop implements ICrop { @@ -28,21 +29,21 @@ public abstract class Crop implements ICrop { this.position = position; } - protected final void setBlock(Vect position, Block block, int meta) { - world.setBlock(position.x, position.y, position.z, block, meta, Constants.FLAG_BLOCK_SYNCH); + protected final void setBlock(IVect position, Block block, int meta) { + world.setBlock(position.getX(), position.getY(), position.getZ(), block, meta, Constants.FLAG_BLOCK_SYNCH); } - protected final Block getBlock(Vect position) { - return world.getBlock(position.x, position.y, position.z); + protected final Block getBlock(IVect position) { + return world.getBlock(position.getX(), position.getY(), position.getZ()); } - protected final int getBlockMeta(Vect position) { - return world.getBlockMetadata(position.x, position.y, position.z); + protected final int getBlockMeta(IVect position) { + return world.getBlockMetadata(position.getX(), position.getY(), position.getZ()); } - protected abstract boolean isCrop(Vect pos); + protected abstract boolean isCrop(IVect pos); - protected abstract Collection harvestBlock(Vect pos); + protected abstract Collection harvestBlock(IVect pos); @Override public Collection harvest() { diff --git a/src/main/java/forestry/farming/logic/CropBasicAgriCraft.java b/src/main/java/forestry/farming/logic/CropBasicAgriCraft.java index 058052195..0fabc0137 100644 --- a/src/main/java/forestry/farming/logic/CropBasicAgriCraft.java +++ b/src/main/java/forestry/farming/logic/CropBasicAgriCraft.java @@ -19,6 +19,7 @@ import net.minecraft.world.World; import forestry.core.config.Constants; import forestry.core.proxy.Proxies; +import forestry.core.utils.vect.IVect; import forestry.core.utils.vect.Vect; public class CropBasicAgriCraft extends Crop { @@ -33,21 +34,21 @@ public class CropBasicAgriCraft extends Crop { } @Override - protected boolean isCrop(Vect pos) { + protected boolean isCrop(IVect pos) { return getBlock(pos) == block && getBlockMeta(pos) == meta; } @Override - protected Collection harvestBlock(Vect pos) { - ArrayList harvest = block.getDrops(world, pos.x, pos.y, pos.z, meta, 0); + protected Collection harvestBlock(IVect pos) { + ArrayList harvest = block.getDrops(world, pos.getX(), pos.getY(), pos.getZ(), meta, 0); if (harvest.size() > 1) { harvest.remove(1); // AgriCraft returns cropsticks in 0, seeds in 1 in getDrops, removing since harvesting // doesn't // return them. } harvest.remove(0); - Proxies.common.addBlockDestroyEffects(world, pos.x, pos.y, pos.z, Blocks.melon_block, 0); - world.setBlockMetadataWithNotify(pos.x, pos.y, pos.z, 0, Constants.FLAG_BLOCK_SYNCH); + Proxies.common.addBlockDestroyEffects(world, pos.getX(), pos.getY(), pos.getZ(), Blocks.melon_block, 0); + world.setBlockMetadataWithNotify(pos.getX(), pos.getY(), pos.getZ(), 0, Constants.FLAG_BLOCK_SYNCH); harvest.removeAll(Collections.singleton(null)); // sanatize nulls that get thru from Agricraft+Harvestcraft // (sesameseed) return harvest; diff --git a/src/main/java/forestry/farming/logic/CropBasicFruit.java b/src/main/java/forestry/farming/logic/CropBasicFruit.java index 56f3ce0c0..03a9f9582 100644 --- a/src/main/java/forestry/farming/logic/CropBasicFruit.java +++ b/src/main/java/forestry/farming/logic/CropBasicFruit.java @@ -16,6 +16,7 @@ import net.minecraft.world.World; import forestry.core.config.Constants; import forestry.core.proxy.Proxies; +import forestry.core.utils.vect.IVect; import forestry.core.utils.vect.Vect; public class CropBasicFruit extends Crop { @@ -30,15 +31,15 @@ public class CropBasicFruit extends Crop { } @Override - protected boolean isCrop(Vect pos) { + protected boolean isCrop(IVect pos) { return getBlock(pos) == block && getBlockMeta(pos) == meta; } @Override - protected Collection harvestBlock(Vect pos) { - Collection harvested = block.getDrops(world, pos.x, pos.y, pos.z, meta, 0); - Proxies.common.addBlockDestroyEffects(world, pos.x, pos.y, pos.z, block, 0); - world.setBlock(pos.x, pos.y, pos.z, block, 0, Constants.FLAG_BLOCK_SYNCH); + protected Collection harvestBlock(IVect pos) { + Collection harvested = block.getDrops(world, pos.getX(), pos.getY(), pos.getZ(), meta, 0); + Proxies.common.addBlockDestroyEffects(world, pos.getX(), pos.getY(), pos.getZ(), block, 0); + world.setBlock(pos.getX(), pos.getY(), pos.getZ(), block, 0, Constants.FLAG_BLOCK_SYNCH); return harvested; } diff --git a/src/main/java/forestry/farming/logic/CropBasicGrowthCraft.java b/src/main/java/forestry/farming/logic/CropBasicGrowthCraft.java index c9081eea7..310a7c0a2 100644 --- a/src/main/java/forestry/farming/logic/CropBasicGrowthCraft.java +++ b/src/main/java/forestry/farming/logic/CropBasicGrowthCraft.java @@ -17,6 +17,7 @@ import net.minecraft.world.World; import forestry.core.config.Constants; import forestry.core.proxy.Proxies; +import forestry.core.utils.vect.IVect; import forestry.core.utils.vect.Vect; public class CropBasicGrowthCraft extends Crop { @@ -35,26 +36,26 @@ public class CropBasicGrowthCraft extends Crop { } @Override - protected boolean isCrop(Vect pos) { + protected boolean isCrop(IVect pos) { return getBlock(pos) == block && getBlockMeta(pos) == meta; } @Override - protected Collection harvestBlock(Vect pos) { - ArrayList harvest = block.getDrops(world, pos.x, pos.y, pos.z, meta, 0); + protected Collection harvestBlock(IVect pos) { + ArrayList harvest = block.getDrops(world, pos.getX(), pos.getY(), pos.getZ(), meta, 0); if (harvest.size() > 1) { harvest.remove(0); // Hops have rope as first drop. } - Proxies.common.addBlockDestroyEffects(world, pos.x, pos.y, pos.z, block, 0); + Proxies.common.addBlockDestroyEffects(world, pos.getX(), pos.getY(), pos.getZ(), block, 0); if (isGrape) { - world.setBlockToAir(pos.x, pos.y, pos.z); + world.setBlockToAir(pos.getX(), pos.getY(), pos.getZ()); } else { - world.setBlockMetadataWithNotify(pos.x, pos.y, pos.z, 0, Constants.FLAG_BLOCK_SYNCH); + world.setBlockMetadataWithNotify(pos.getX(), pos.getY(), pos.getZ(), 0, Constants.FLAG_BLOCK_SYNCH); } if (isRice) { - world.setBlockMetadataWithNotify(pos.x, pos.y - 1, pos.z, 7, Constants.FLAG_BLOCK_SYNCH); + world.setBlockMetadataWithNotify(pos.getX(), pos.getY() - 1, pos.getZ(), 7, Constants.FLAG_BLOCK_SYNCH); } return harvest; diff --git a/src/main/java/forestry/farming/logic/CropBasicIC2Crop.java b/src/main/java/forestry/farming/logic/CropBasicIC2Crop.java index d0336eddf..bac84d608 100644 --- a/src/main/java/forestry/farming/logic/CropBasicIC2Crop.java +++ b/src/main/java/forestry/farming/logic/CropBasicIC2Crop.java @@ -6,6 +6,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; +import forestry.core.utils.vect.IVect; import forestry.core.utils.vect.Vect; import forestry.plugins.compat.PluginIC2; @@ -19,12 +20,12 @@ public class CropBasicIC2Crop extends Crop { } @Override - protected boolean isCrop(Vect pos) { + protected boolean isCrop(IVect pos) { return PluginIC2.instance.canHarvestCrop(this.tileEntity); } @Override - protected Collection harvestBlock(Vect pos) { + protected Collection harvestBlock(IVect pos) { return PluginIC2.instance.getCropDrops(this.tileEntity); } } diff --git a/src/main/java/forestry/farming/logic/CropBlock.java b/src/main/java/forestry/farming/logic/CropBlock.java index 5d8938e78..61e69cc5f 100755 --- a/src/main/java/forestry/farming/logic/CropBlock.java +++ b/src/main/java/forestry/farming/logic/CropBlock.java @@ -15,6 +15,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.world.World; import forestry.core.proxy.Proxies; +import forestry.core.utils.vect.IVect; import forestry.core.utils.vect.Vect; public class CropBlock extends Crop { @@ -29,16 +30,16 @@ public class CropBlock extends Crop { } @Override - protected boolean isCrop(Vect pos) { + protected boolean isCrop(IVect pos) { return getBlock(pos) == block && getBlockMeta(pos) == meta; } @Override - protected Collection harvestBlock(Vect pos) { - Collection harvested = block.getDrops(world, pos.x, pos.y, pos.z, meta, 0); - Proxies.common.addBlockDestroyEffects(world, pos.x, pos.y, pos.z, block, 0); + protected Collection harvestBlock(IVect pos) { + Collection harvested = block.getDrops(world, pos.getX(), pos.getY(), pos.getZ(), meta, 0); + Proxies.common.addBlockDestroyEffects(world, pos.getX(), pos.getY(), pos.getZ(), block, 0); // Block.breakBlock() is called by vanilla itself, removing TEs. - world.setBlockToAir(pos.x, pos.y, pos.z); + world.setBlockToAir(pos.getX(), pos.getY(), pos.getZ()); return harvested; } diff --git a/src/main/java/forestry/farming/logic/CropFruit.java b/src/main/java/forestry/farming/logic/CropFruit.java index d18202441..d5f3a1a9d 100755 --- a/src/main/java/forestry/farming/logic/CropFruit.java +++ b/src/main/java/forestry/farming/logic/CropFruit.java @@ -18,6 +18,7 @@ import net.minecraft.world.World; import forestry.api.genetics.IFruitBearer; import forestry.core.network.packets.PacketFXSignal; import forestry.core.proxy.Proxies; +import forestry.core.utils.vect.IVect; import forestry.core.utils.vect.Vect; public class CropFruit extends Crop { @@ -27,8 +28,8 @@ public class CropFruit extends Crop { } @Override - protected boolean isCrop(Vect pos) { - TileEntity tile = world.getTileEntity(pos.x, pos.y, pos.z); + protected boolean isCrop(IVect pos) { + TileEntity tile = world.getTileEntity(pos.getX(), pos.getY(), pos.getZ()); if (!(tile instanceof IFruitBearer)) { return false; } @@ -44,8 +45,8 @@ public class CropFruit extends Crop { } @Override - protected Collection harvestBlock(Vect pos) { - TileEntity tile = world.getTileEntity(pos.x, pos.y, pos.z); + protected Collection harvestBlock(IVect pos) { + TileEntity tile = world.getTileEntity(pos.getX(), pos.getY(), pos.getZ()); if (!(tile instanceof IFruitBearer)) { return new ArrayList<>(); } @@ -54,10 +55,10 @@ public class CropFruit extends Crop { PacketFXSignal.VisualFXType.BLOCK_DESTROY, PacketFXSignal.SoundFXType.LEAF, world, - pos.x, - pos.y, - pos.z, - world.getBlock(pos.x, pos.y, pos.z), + pos.getX(), + pos.getY(), + pos.getZ(), + world.getBlock(pos.getX(), pos.getY(), pos.getZ()), 0); return ((IFruitBearer) tile).pickFruit(null); } diff --git a/src/main/java/forestry/farming/logic/CropPeat.java b/src/main/java/forestry/farming/logic/CropPeat.java index 5dc4b502f..68e5dbe05 100755 --- a/src/main/java/forestry/farming/logic/CropPeat.java +++ b/src/main/java/forestry/farming/logic/CropPeat.java @@ -19,6 +19,7 @@ import net.minecraft.world.World; import forestry.core.blocks.BlockSoil; import forestry.core.proxy.Proxies; +import forestry.core.utils.vect.IVect; import forestry.core.utils.vect.Vect; import forestry.plugins.PluginCore; @@ -29,7 +30,7 @@ public class CropPeat extends Crop { } @Override - protected boolean isCrop(Vect pos) { + protected boolean isCrop(IVect pos) { Block block = getBlock(pos); if (!(block instanceof BlockSoil)) { return false; @@ -41,11 +42,17 @@ public class CropPeat extends Crop { } @Override - protected Collection harvestBlock(Vect pos) { + protected Collection harvestBlock(IVect pos) { List drops = new ArrayList<>(); drops.add(PluginCore.items.peat.getItemStack()); - Proxies.common.addBlockDestroyEffects(world, pos.x, pos.y, pos.z, world.getBlock(pos.x, pos.y, pos.z), 0); + Proxies.common.addBlockDestroyEffects( + world, + pos.getX(), + pos.getY(), + pos.getZ(), + world.getBlock(pos.getX(), pos.getY(), pos.getZ()), + 0); setBlock(pos, Blocks.dirt, 0); return drops; } diff --git a/src/main/java/forestry/farming/logic/CropRubber.java b/src/main/java/forestry/farming/logic/CropRubber.java index 89c94dad5..04e943612 100755 --- a/src/main/java/forestry/farming/logic/CropRubber.java +++ b/src/main/java/forestry/farming/logic/CropRubber.java @@ -17,6 +17,7 @@ import net.minecraft.world.World; import forestry.core.config.Constants; import forestry.core.proxy.Proxies; +import forestry.core.utils.vect.IVect; import forestry.core.utils.vect.Vect; import forestry.plugins.compat.PluginIC2; @@ -27,11 +28,11 @@ public class CropRubber extends CropBlock { } @Override - protected Collection harvestBlock(Vect pos) { + protected Collection harvestBlock(IVect pos) { Collection harvested = new ArrayList<>(); harvested.add(PluginIC2.resin.copy()); - Proxies.common.addBlockDestroyEffects(world, pos.x, pos.y, pos.z, block, 0); - world.setBlock(pos.x, pos.y, pos.z, block, meta + 6, Constants.FLAG_BLOCK_SYNCH); + Proxies.common.addBlockDestroyEffects(world, pos.getX(), pos.getY(), pos.getZ(), block, 0); + world.setBlock(pos.getX(), pos.getY(), pos.getZ(), block, meta + 6, Constants.FLAG_BLOCK_SYNCH); return harvested; } } diff --git a/src/main/java/forestry/farming/logic/FarmLogic.java b/src/main/java/forestry/farming/logic/FarmLogic.java index 3fbd06bf6..3e98a419d 100755 --- a/src/main/java/forestry/farming/logic/FarmLogic.java +++ b/src/main/java/forestry/farming/logic/FarmLogic.java @@ -27,6 +27,7 @@ import forestry.core.config.Constants; import forestry.core.entities.EntitySelector; import forestry.core.render.SpriteSheet; import forestry.core.utils.EntityUtil; +import forestry.core.utils.vect.MutableVect; import forestry.core.utils.vect.Vect; public abstract class FarmLogic implements IFarmLogic { @@ -64,8 +65,10 @@ public abstract class FarmLogic implements IFarmLogic { && world.getBlockMetadata(position.x, position.y, position.z) == 0; } + protected final MutableVect mutableVect = new MutableVect(); + protected final Vect translateWithOffset(int x, int y, int z, FarmDirection farmDirection, int step) { - return new Vect(farmDirection.getForgeDirection()).multiply(step).add(x, y, z); + return new Vect(mutableVect.set(farmDirection.getForgeDirection()).multiply(step).add(x, y, z)); } protected final void setBlock(Vect position, Block block, int meta) { diff --git a/src/main/java/forestry/farming/logic/FarmLogicArboreal.java b/src/main/java/forestry/farming/logic/FarmLogicArboreal.java index 1a1c42b09..210661d65 100755 --- a/src/main/java/forestry/farming/logic/FarmLogicArboreal.java +++ b/src/main/java/forestry/farming/logic/FarmLogicArboreal.java @@ -8,13 +8,14 @@ ******************************************************************************/ package forestry.farming.logic; +import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.Deque; import java.util.HashMap; import java.util.HashSet; import java.util.Set; -import java.util.Stack; import net.minecraft.block.Block; import net.minecraft.init.Blocks; @@ -32,6 +33,7 @@ import forestry.api.farming.IFarmHousing; import forestry.api.farming.IFarmable; import forestry.core.blocks.BlockSoil; import forestry.core.render.SpriteSheet; +import forestry.core.utils.vect.MutableVect; import forestry.core.utils.vect.Vect; import forestry.core.utils.vect.VectUtil; import forestry.plugins.PluginCore; @@ -128,7 +130,7 @@ public class FarmLogicArboreal extends FarmLogicHomogeneous { World world = getWorld(); Set seen = new HashSet<>(); - Stack crops = new Stack<>(); + Deque crops = new ArrayDeque<>(); // Determine what type we want to harvest. IFarmable germling = null; @@ -162,7 +164,7 @@ public class FarmLogicArboreal extends FarmLogicHomogeneous { return crops; } - private ArrayList processHarvestBlock(IFarmable germling, Stack crops, Set seen, Vect start, + private ArrayList processHarvestBlock(IFarmable germling, Deque crops, Set seen, Vect start, Vect position) { World world = getWorld(); @@ -170,30 +172,32 @@ public class FarmLogicArboreal extends FarmLogicHomogeneous { ArrayList candidates = new ArrayList<>(); // Get additional candidates to return + MutableVect mutable = new MutableVect(); for (int x = -1; x < 2; x++) { for (int y = -1; y < 2; y++) { for (int z = -1; z < 2; z++) { - Vect candidate = position.add(x, y, z); - if (candidate.equals(position)) { + mutable.set(position).add(x, y, z); + if (mutable.equals(position)) { continue; } - if (Math.abs(candidate.x - start.x) > BRANCH_RANGE) { + if (Math.abs(mutable.x - start.x) > BRANCH_RANGE) { continue; } - if (Math.abs(candidate.z - start.z) > BRANCH_RANGE) { + if (Math.abs(mutable.z - start.z) > BRANCH_RANGE) { continue; } // See whether the given position has already been processed - if (seen.contains(candidate)) { + if (seen.contains(mutable)) { continue; } - ICrop crop = germling.getCropAt(world, candidate.x, candidate.y, candidate.z); + ICrop crop = germling.getCropAt(world, mutable.x, mutable.y, mutable.z); if (crop != null) { + Vect immutable = mutable.asImmutable(); crops.push(crop); - candidates.add(candidate); - seen.add(candidate); + candidates.add(immutable); + seen.add(immutable); } } } diff --git a/src/main/java/forestry/farming/logic/FarmLogicCocoa.java b/src/main/java/forestry/farming/logic/FarmLogicCocoa.java index 2cf7a7c32..83bedcbd1 100755 --- a/src/main/java/forestry/farming/logic/FarmLogicCocoa.java +++ b/src/main/java/forestry/farming/logic/FarmLogicCocoa.java @@ -8,12 +8,13 @@ ******************************************************************************/ package forestry.farming.logic; +import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Collection; +import java.util.Deque; import java.util.HashMap; import java.util.HashSet; import java.util.Set; -import java.util.Stack; import net.minecraft.block.Block; import net.minecraft.block.BlockLog; @@ -29,6 +30,7 @@ import forestry.api.farming.FarmDirection; import forestry.api.farming.ICrop; import forestry.api.farming.IFarmHousing; import forestry.api.farming.IFarmable; +import forestry.core.utils.vect.IVect; import forestry.core.utils.vect.MutableVect; import forestry.core.utils.vect.Vect; import forestry.core.utils.vect.VectUtil; @@ -160,7 +162,7 @@ public class FarmLogicCocoa extends FarmLogic { private Collection getHarvestBlocks(Vect position) { Set seen = new HashSet<>(); - Stack crops = new Stack<>(); + Deque crops = new ArrayDeque<>(); // Determine what type we want to harvest. Block block = VectUtil.getBlock(getWorld(), position); @@ -193,40 +195,43 @@ public class FarmLogicCocoa extends FarmLogic { return crops; } - private ArrayList processHarvestBlock(Stack crops, Set seen, Vect start, Vect position) { + private ArrayList processHarvestBlock(Deque crops, Set seen, Vect start, IVect position) { World world = getWorld(); ArrayList candidates = new ArrayList<>(); // Get additional candidates to return + MutableVect mutable = new MutableVect(); for (int i = -1; i < 2; i++) { for (int j = 0; j < 2; j++) { for (int k = -1; k < 2; k++) { - Vect candidate = position.add(i, j, k); - if (candidate.equals(position)) { + mutable.set(position).add(i, j, k); + if (mutable.equals(position)) { continue; } - if (Math.abs(candidate.x - start.x) > 5) { + if (Math.abs(mutable.x - start.x) > 5) { continue; } - if (Math.abs(candidate.z - start.z) > 5) { + if (Math.abs(mutable.z - start.z) > 5) { continue; } // See whether the given position has already been processed - if (seen.contains(candidate)) { + if (seen.contains(mutable)) { continue; } - ICrop crop = cocoa.getCropAt(world, candidate.x, candidate.y, candidate.z); + ICrop crop = cocoa.getCropAt(world, mutable.x, mutable.y, mutable.z); if (crop != null) { + Vect immutable = mutable.asImmutable(); crops.push(crop); - candidates.add(candidate); - seen.add(candidate); - } else if (VectUtil.isWoodBlock(world, candidate)) { - candidates.add(candidate); - seen.add(candidate); + candidates.add(immutable); + seen.add(immutable); + } else if (VectUtil.isWoodBlock(world, mutable)) { + Vect immutable = mutable.asImmutable(); + candidates.add(immutable); + seen.add(immutable); } } } diff --git a/src/main/java/forestry/farming/logic/FarmLogicCrops.java b/src/main/java/forestry/farming/logic/FarmLogicCrops.java index 8b7ee5a17..0c7e7c0bf 100755 --- a/src/main/java/forestry/farming/logic/FarmLogicCrops.java +++ b/src/main/java/forestry/farming/logic/FarmLogicCrops.java @@ -8,8 +8,9 @@ ******************************************************************************/ package forestry.farming.logic; +import java.util.ArrayDeque; import java.util.Collection; -import java.util.Stack; +import java.util.Deque; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; @@ -111,7 +112,7 @@ public abstract class FarmLogicCrops extends FarmLogicWatered { public Collection harvest(int x, int y, int z, FarmDirection direction, int extent) { World world = getWorld(); - Stack crops = new Stack<>(); + Deque crops = new ArrayDeque<>(); for (int i = 0; i < extent; i++) { Vect position = translateWithOffset(x, y + 1, z, direction, i); for (IFarmable seed : seeds) { diff --git a/src/main/java/forestry/farming/logic/FarmLogicEnder.java b/src/main/java/forestry/farming/logic/FarmLogicEnder.java index 6c7ff2707..c7efe781c 100644 --- a/src/main/java/forestry/farming/logic/FarmLogicEnder.java +++ b/src/main/java/forestry/farming/logic/FarmLogicEnder.java @@ -8,8 +8,9 @@ ******************************************************************************/ package forestry.farming.logic; +import java.util.ArrayDeque; import java.util.Collection; -import java.util.Stack; +import java.util.Deque; import net.minecraft.init.Blocks; import net.minecraft.init.Items; @@ -68,7 +69,7 @@ public class FarmLogicEnder extends FarmLogicHomogeneous { public Collection harvest(int x, int y, int z, FarmDirection direction, int extent) { World world = getWorld(); - Stack crops = new Stack<>(); + Deque crops = new ArrayDeque<>(); for (int i = 0; i < extent; i++) { Vect position = translateWithOffset(x, y + 1, z, direction, i); for (IFarmable farmable : germlings) { diff --git a/src/main/java/forestry/farming/logic/FarmLogicGourd.java b/src/main/java/forestry/farming/logic/FarmLogicGourd.java index 544a2737c..6d18c6225 100755 --- a/src/main/java/forestry/farming/logic/FarmLogicGourd.java +++ b/src/main/java/forestry/farming/logic/FarmLogicGourd.java @@ -8,8 +8,9 @@ ******************************************************************************/ package forestry.farming.logic; +import java.util.ArrayDeque; import java.util.Collection; -import java.util.Stack; +import java.util.Deque; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; @@ -85,7 +86,7 @@ public class FarmLogicGourd extends FarmLogic { public Collection harvest(int x, int y, int z, FarmDirection direction, int extent) { World world = getWorld(); - Stack crops = new Stack<>(); + Deque crops = new ArrayDeque<>(); for (int i = 0; i < extent; i++) { Vect position = translateWithOffset(x, y + 1, z, direction, i); for (IFarmable seed : seeds) { diff --git a/src/main/java/forestry/farming/logic/FarmLogicInfernal.java b/src/main/java/forestry/farming/logic/FarmLogicInfernal.java index 5286be2f0..0156c73d2 100755 --- a/src/main/java/forestry/farming/logic/FarmLogicInfernal.java +++ b/src/main/java/forestry/farming/logic/FarmLogicInfernal.java @@ -8,8 +8,9 @@ ******************************************************************************/ package forestry.farming.logic; +import java.util.ArrayDeque; import java.util.Collection; -import java.util.Stack; +import java.util.Deque; import net.minecraft.init.Blocks; import net.minecraft.init.Items; @@ -68,7 +69,7 @@ public class FarmLogicInfernal extends FarmLogicHomogeneous { public Collection harvest(int x, int y, int z, FarmDirection direction, int extent) { World world = getWorld(); - Stack crops = new Stack<>(); + Deque crops = new ArrayDeque<>(); for (int i = 0; i < extent; i++) { Vect position = translateWithOffset(x, y + 1, z, direction, i); for (IFarmable farmable : germlings) { diff --git a/src/main/java/forestry/farming/logic/FarmLogicOrchard.java b/src/main/java/forestry/farming/logic/FarmLogicOrchard.java index fefe8bf3f..0ebf7e5dc 100755 --- a/src/main/java/forestry/farming/logic/FarmLogicOrchard.java +++ b/src/main/java/forestry/farming/logic/FarmLogicOrchard.java @@ -8,13 +8,14 @@ ******************************************************************************/ package forestry.farming.logic; +import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Collection; +import java.util.Deque; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Set; -import java.util.Stack; import net.minecraft.block.Block; import net.minecraft.init.Blocks; @@ -35,6 +36,8 @@ import forestry.api.farming.IFarmHousing; import forestry.api.farming.IFarmable; import forestry.api.farming.IFarmableBasic; import forestry.api.genetics.IFruitBearer; +import forestry.core.utils.vect.IVect; +import forestry.core.utils.vect.MutableVect; import forestry.core.utils.vect.Vect; import forestry.core.utils.vect.VectUtil; import forestry.plugins.PluginCore; @@ -145,7 +148,7 @@ public class FarmLogicOrchard extends FarmLogic { private Collection getHarvestBlocks(Vect position) { Set seen = new HashSet<>(); - Stack crops = new Stack<>(); + Deque crops = new ArrayDeque<>(); World world = getWorld(); @@ -158,8 +161,8 @@ public class FarmLogicOrchard extends FarmLogic { List candidates = processHarvestBlock(crops, seen, position, position); List temp = new ArrayList<>(); while (!candidates.isEmpty() && crops.size() < 20) { - for (Vect candidate : candidates) { - temp.addAll(processHarvestBlock(crops, seen, position, candidate)); + for (int i = 0; i < candidates.size(); i++) { + temp.addAll(processHarvestBlock(crops, seen, position, candidates.get(i))); } candidates.clear(); candidates.addAll(temp); @@ -169,39 +172,41 @@ public class FarmLogicOrchard extends FarmLogic { return crops; } - private List processHarvestBlock(Stack crops, Set seen, Vect start, Vect position) { + private List processHarvestBlock(Deque crops, Set seen, IVect start, IVect position) { World world = getWorld(); List candidates = new ArrayList<>(); + final MutableVect mutable = new MutableVect(); // Get additional candidates to return for (int i = -2; i < 3; i++) { for (int j = 0; j < 2; j++) { for (int k = -1; k < 2; k++) { - Vect candidate = position.add(i, j, k); - if (Math.abs(candidate.x - start.x) > 5) { + mutable.set(position).add(i, j, k); + if (Math.abs(mutable.getX() - start.getX()) > 5) { continue; } - if (Math.abs(candidate.z - start.z) > 5) { + if (Math.abs(mutable.getZ() - start.getZ()) > 5) { continue; } // See whether the given position has already been processed - if (seen.contains(candidate)) { + if (seen.contains(mutable)) { continue; } - if (VectUtil.isAirBlock(world, candidate)) { + if (VectUtil.isAirBlock(world, mutable)) { continue; } - if (VectUtil.isWoodBlock(world, candidate) - || isBlockTraversable(world, candidate, traversalBlocks)) { - candidates.add(candidate); - seen.add(candidate); - } else if (isFruitBearer(world, candidate)) { - candidates.add(candidate); - seen.add(candidate); + if (VectUtil.isWoodBlock(world, mutable) || isBlockTraversable(world, mutable, traversalBlocks)) { + final Vect immutable = new Vect(mutable); + candidates.add(immutable); + seen.add(immutable); + } else if (isFruitBearer(world, mutable)) { + final Vect immutable = new Vect(mutable); + candidates.add(immutable); + seen.add(immutable); - ICrop crop = getCrop(world, candidate); + ICrop crop = getCrop(world, immutable); if (crop != null) { crops.push(crop); } @@ -213,20 +218,20 @@ public class FarmLogicOrchard extends FarmLogic { return candidates; } - private boolean isFruitBearer(World world, Vect position) { + private boolean isFruitBearer(World world, IVect position) { - TileEntity tile = world.getTileEntity(position.x, position.y, position.z); + TileEntity tile = world.getTileEntity(position.getX(), position.getY(), position.getZ()); if (tile instanceof IFruitBearer) { return true; } - Block block = precalcBlockType ? world.getBlock(position.x, position.y, position.z) : null; - int meta = precalcBlockMeta ? world.getBlockMetadata(position.x, position.y, position.z) : -1; + Block block = precalcBlockType ? world.getBlock(position.getX(), position.getY(), position.getZ()) : null; + int meta = precalcBlockMeta ? world.getBlockMetadata(position.getX(), position.getY(), position.getZ()) : -1; for (IFarmable farmable : farmables) { if (farmable instanceof IFarmableBasic) { if (((IFarmableBasic) farmable).isSapling(block, meta)) return true; - } else if (farmable.isSaplingAt(world, position.x, position.y, position.z)) { + } else if (farmable.isSaplingAt(world, position.getX(), position.getY(), position.getZ())) { return true; } } @@ -234,29 +239,28 @@ public class FarmLogicOrchard extends FarmLogic { return false; } - private static boolean isBlockTraversable(World world, Vect position, ImmutableList traversalBlocks) { + private static boolean isBlockTraversable(World world, IVect position, ImmutableList traversalBlocks) { Block candidate = VectUtil.getBlock(world, position); - for (Block block : traversalBlocks) { - if (block == (candidate)) { + for (int i = 0; i < traversalBlocks.size(); i++) { + if (candidate == traversalBlocks.get(i)) { return true; } } return false; } - private ICrop getCrop(World world, Vect position) { + private ICrop getCrop(World world, IVect position) { - TileEntity tile = world.getTileEntity(position.x, position.y, position.z); + TileEntity tile = world.getTileEntity(position.getX(), position.getY(), position.getZ()); - if (tile instanceof IFruitBearer) { - IFruitBearer fruitBearer = (IFruitBearer) tile; + if (tile instanceof IFruitBearer fruitBearer) { if (fruitBearer.hasFruit() && fruitBearer.getRipeness() >= 0.9f) { - return new CropFruit(world, position); + return new CropFruit(world, position.asImmutable()); } } else { for (IFarmable seed : farmables) { - ICrop crop = seed.getCropAt(world, position.x, position.y, position.z); + ICrop crop = seed.getCropAt(world, position.getX(), position.getY(), position.getZ()); if (crop != null) { return crop; } diff --git a/src/main/java/forestry/farming/logic/FarmLogicPeat.java b/src/main/java/forestry/farming/logic/FarmLogicPeat.java index 00bc95b6f..267faa0f2 100755 --- a/src/main/java/forestry/farming/logic/FarmLogicPeat.java +++ b/src/main/java/forestry/farming/logic/FarmLogicPeat.java @@ -8,8 +8,9 @@ ******************************************************************************/ package forestry.farming.logic; +import java.util.ArrayDeque; import java.util.Collection; -import java.util.Stack; +import java.util.Deque; import net.minecraft.block.Block; import net.minecraft.item.ItemStack; @@ -77,7 +78,7 @@ public class FarmLogicPeat extends FarmLogicWatered { public Collection harvest(int x, int y, int z, FarmDirection direction, int extent) { World world = getWorld(); - Stack crops = new Stack<>(); + Deque crops = new ArrayDeque<>(); for (int i = 0; i < extent; i++) { Vect position = translateWithOffset(x, y, z, direction, i); ItemStack occupant = VectUtil.getAsItemStack(world, position); diff --git a/src/main/java/forestry/farming/logic/FarmLogicReeds.java b/src/main/java/forestry/farming/logic/FarmLogicReeds.java index 60c374f7d..e7fcc1a5d 100644 --- a/src/main/java/forestry/farming/logic/FarmLogicReeds.java +++ b/src/main/java/forestry/farming/logic/FarmLogicReeds.java @@ -8,8 +8,9 @@ ******************************************************************************/ package forestry.farming.logic; +import java.util.ArrayDeque; import java.util.Collection; -import java.util.Stack; +import java.util.Deque; import net.minecraft.init.Blocks; import net.minecraft.init.Items; @@ -99,7 +100,7 @@ public class FarmLogicReeds extends FarmLogic { public Collection harvest(int x, int y, int z, FarmDirection direction, int extent) { World world = getWorld(); - Stack crops = new Stack<>(); + Deque crops = new ArrayDeque<>(); for (int i = 0; i < extent; i++) { Vect position = translateWithOffset(x, y + 1, z, direction, i); for (IFarmable seed : germlings) { diff --git a/src/main/java/forestry/farming/logic/FarmLogicRubber.java b/src/main/java/forestry/farming/logic/FarmLogicRubber.java index 58398b2b0..e97b52553 100755 --- a/src/main/java/forestry/farming/logic/FarmLogicRubber.java +++ b/src/main/java/forestry/farming/logic/FarmLogicRubber.java @@ -8,12 +8,13 @@ ******************************************************************************/ package forestry.farming.logic; +import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Collection; +import java.util.Deque; import java.util.HashMap; import java.util.HashSet; import java.util.Set; -import java.util.Stack; import net.minecraft.block.Block; import net.minecraft.init.Items; @@ -28,6 +29,7 @@ import forestry.api.farming.ICrop; import forestry.api.farming.IFarmHousing; import forestry.core.utils.ItemStackUtil; import forestry.core.utils.Log; +import forestry.core.utils.vect.MutableVect; import forestry.core.utils.vect.Vect; import forestry.core.utils.vect.VectUtil; import forestry.plugins.compat.PluginIC2; @@ -123,7 +125,7 @@ public class FarmLogicRubber extends FarmLogic { private Collection getHarvestBlocks(Vect position) { Set seen = new HashSet<>(); - Stack crops = new Stack<>(); + Deque crops = new ArrayDeque<>(); World world = getWorld(); @@ -152,31 +154,33 @@ public class FarmLogicRubber extends FarmLogic { return crops; } - private ArrayList processHarvestBlock(Stack crops, Set seen, Vect position) { + private ArrayList processHarvestBlock(Deque crops, Set seen, Vect position) { World world = getWorld(); ArrayList candidates = new ArrayList<>(); // Get additional candidates to return + final MutableVect mutable = position.asMutable(); for (int j = 0; j < 2; j++) { - Vect candidate = new Vect(position.x, position.y + j, position.z); - if (candidate.equals(position)) { + mutable.y = position.y + j; + if (mutable.equals(position)) { continue; } // See whether the given position has already been processed - if (seen.contains(candidate)) { + if (seen.contains(mutable)) { continue; } - Block block = VectUtil.getBlock(world, candidate); + Block block = VectUtil.getBlock(world, mutable); if (ItemStackUtil.equals(block, PluginIC2.rubberwood)) { - int meta = VectUtil.getBlockMeta(world, candidate); + final Vect immutable = new Vect(mutable); + int meta = VectUtil.getBlockMeta(world, immutable); if (meta >= 2 && meta <= 5) { - crops.push(new CropRubber(world, block, meta, candidate)); + crops.push(new CropRubber(world, block, meta, immutable)); } - candidates.add(candidate); - seen.add(candidate); + candidates.add(immutable); + seen.add(immutable); } } diff --git a/src/main/java/forestry/farming/logic/FarmLogicSucculent.java b/src/main/java/forestry/farming/logic/FarmLogicSucculent.java index 11c7887eb..21d909a08 100755 --- a/src/main/java/forestry/farming/logic/FarmLogicSucculent.java +++ b/src/main/java/forestry/farming/logic/FarmLogicSucculent.java @@ -8,8 +8,9 @@ ******************************************************************************/ package forestry.farming.logic; +import java.util.ArrayDeque; import java.util.Collection; -import java.util.Stack; +import java.util.Deque; import net.minecraft.init.Blocks; import net.minecraft.init.Items; @@ -99,7 +100,7 @@ public class FarmLogicSucculent extends FarmLogic { public Collection harvest(int x, int y, int z, FarmDirection direction, int extent) { World world = getWorld(); - Stack crops = new Stack<>(); + Deque crops = new ArrayDeque<>(); for (int i = 0; i < extent; i++) { Vect position = translateWithOffset(x, y + 1, z, direction, i); for (IFarmable seed : germlings) { diff --git a/src/main/java/forestry/farming/multiblock/FarmController.java b/src/main/java/forestry/farming/multiblock/FarmController.java index 036a24ac4..99b912091 100644 --- a/src/main/java/forestry/farming/multiblock/FarmController.java +++ b/src/main/java/forestry/farming/multiblock/FarmController.java @@ -9,16 +9,17 @@ package forestry.farming.multiblock; import java.io.IOException; +import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.Deque; import java.util.EnumMap; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.Stack; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; @@ -110,8 +111,8 @@ public class FarmController extends RectangularMultiblockControllerBase private int allowedExtent = 0; private IFarmLogic harvestProvider; // The farm logic which supplied the pending crops. - private final Stack pendingCrops = new Stack<>(); - private final Stack pendingProduce = new Stack<>(); + private final Deque pendingCrops = new ArrayDeque<>(); + private final Deque pendingProduce = new ArrayDeque<>(); private Stage stage = Stage.CULTIVATE; diff --git a/src/main/java/forestry/farming/multiblock/InventoryFarm.java b/src/main/java/forestry/farming/multiblock/InventoryFarm.java index 5a1ed3e99..d311ecefc 100644 --- a/src/main/java/forestry/farming/multiblock/InventoryFarm.java +++ b/src/main/java/forestry/farming/multiblock/InventoryFarm.java @@ -8,7 +8,7 @@ ******************************************************************************/ package forestry.farming.multiblock; -import java.util.Stack; +import java.util.Deque; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; @@ -208,7 +208,7 @@ public class InventoryFarm extends InventoryAdapterRestricted implements IFarmIn produce.stackSize -= InventoryUtil.addStack(productInventory, produce, true); } - public void stowHarvest(Iterable harvested, Stack pendingProduce) { + public void stowHarvest(Iterable harvested, Deque pendingProduce) { for (ItemStack harvest : harvested) { if (harvest == null) { continue; @@ -232,7 +232,7 @@ public class InventoryFarm extends InventoryAdapterRestricted implements IFarmIn } } - public boolean tryAddPendingProduce(Stack pendingProduce) { + public boolean tryAddPendingProduce(Deque pendingProduce) { IInventory productInventory = getProductInventory(); ItemStack next = pendingProduce.peek();