diff options
Diffstat (limited to 'src/main/java/gregtech/api/util')
4 files changed, 100 insertions, 47 deletions
diff --git a/src/main/java/gregtech/api/util/GT_AssemblyLineUtils.java b/src/main/java/gregtech/api/util/GT_AssemblyLineUtils.java index f35f1962d1..62238a8112 100644 --- a/src/main/java/gregtech/api/util/GT_AssemblyLineUtils.java +++ b/src/main/java/gregtech/api/util/GT_AssemblyLineUtils.java @@ -2,6 +2,7 @@ package gregtech.api.util; import static gregtech.GT_Mod.GT_FML_LOGGER; +import java.util.Arrays; import java.util.HashMap; import cpw.mods.fml.common.FMLCommonHandler; @@ -14,7 +15,6 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.nbt.NBTTagString; import net.minecraftforge.fluids.FluidStack; -import scala.actors.threadpool.Arrays; public class GT_AssemblyLineUtils { @@ -159,7 +159,7 @@ public class GT_AssemblyLineUtils { for (GT_Recipe_AssemblyLine aRecipe : GT_Recipe.GT_Recipe_AssemblyLine.sAssemblylineRecipes) { if (aRecipe.mEUt == aEU && aRecipe.mDuration == aTime) { if (GT_Utility.areStacksEqual(aOutputs[0], aRecipe.mOutput, true)) { - if (Arrays.equals(aRecipe.mInputs, aInputs) && Arrays.equals(aRecipe.mFluidInputs, aFluidInputs)) { + if (Arrays.equals(aRecipe.mInputs, aInputs) && Arrays.equals(aRecipe.mFluidInputs, aFluidInputs)) { // Cache it String aRecipeHash = generateRecipeHash(aRecipe); sRecipeCacheByRecipeHash.put(aRecipeHash, aRecipe); diff --git a/src/main/java/gregtech/api/util/GT_ChunkAssociatedData.java b/src/main/java/gregtech/api/util/GT_ChunkAssociatedData.java index bd9148b516..184f6f1011 100644 --- a/src/main/java/gregtech/api/util/GT_ChunkAssociatedData.java +++ b/src/main/java/gregtech/api/util/GT_ChunkAssociatedData.java @@ -104,7 +104,7 @@ public abstract class GT_ChunkAssociatedData<T extends GT_ChunkAssociatedData.ID } private ChunkCoordIntPair getRegionID(int aChunkX, int aChunkZ) { - return new ChunkCoordIntPair(aChunkX / regionLength, aChunkZ / regionLength); + return new ChunkCoordIntPair(Math.floorDiv(aChunkX, regionLength), Math.floorDiv(aChunkZ, regionLength)); } /** @@ -168,7 +168,7 @@ public abstract class GT_ChunkAssociatedData<T extends GT_ChunkAssociatedData.ID } private void saveRegions(Stream<SuperRegion> stream) { - stream.filter(r -> !r.isDirty()) + stream.filter(r -> r.isDirty()) .map(c -> (Runnable) c::save) .map(r -> CompletableFuture.runAsync(r, IO_WORKERS)) .reduce(CompletableFuture::allOf) @@ -242,7 +242,12 @@ public abstract class GT_ChunkAssociatedData<T extends GT_ChunkAssociatedData.ID } protected File getSaveDirectory(World w) { - return new File(w.getSaveHandler().getWorldDirectory(), "gregtech"); + File base; + if (w.provider.getSaveFolder() == null) + base = w.getSaveHandler().getWorldDirectory(); + else + base = new File(w.getSaveHandler().getWorldDirectory(), w.provider.getSaveFolder()); + return new File(base, "gregtech"); } public interface IData { @@ -256,20 +261,23 @@ public abstract class GT_ChunkAssociatedData<T extends GT_ChunkAssociatedData.ID private final T[] data = createData(); private final File backingStorage; private final WeakReference<World> world; + /** + * Be aware, this means region coord, not bottom-left chunk coord + */ private final ChunkCoordIntPair coord; - private SuperRegion(World world, int chunkX, int chunkZ) { + private SuperRegion(World world, int regionX, int regionZ) { this.world = new WeakReference<>(world); - this.coord = new ChunkCoordIntPair(chunkX, chunkZ); - backingStorage = new File(getSaveDirectory(world), String.format("%s.%d.%d.dat", mId, chunkX, chunkZ)); + this.coord = new ChunkCoordIntPair(regionX, regionZ); + backingStorage = new File(getSaveDirectory(world), String.format("%s.%d.%d.dat", mId, regionX, regionZ)); if (backingStorage.isFile()) load(); } - private SuperRegion(World world, ChunkCoordIntPair coord) { + private SuperRegion(World world, ChunkCoordIntPair regionCoord) { this.world = new WeakReference<>(world); - this.coord = coord; - backingStorage = new File(getSaveDirectory(world), String.format("%s.%d.%d.dat", mId, coord.chunkXPos, coord.chunkZPos)); + this.coord = regionCoord; + backingStorage = new File(getSaveDirectory(world), String.format("%s.%d.%d.dat", mId, regionCoord.chunkXPos, regionCoord.chunkZPos)); if (backingStorage.isFile()) load(); } @@ -296,7 +304,7 @@ public abstract class GT_ChunkAssociatedData<T extends GT_ChunkAssociatedData.ID } public boolean isCreated(int subRegionX, int subRegionZ) { - return this.data[getIndex(subRegionX, subRegionZ)] == null; + return this.data[getIndex(subRegionX, subRegionZ)] != null; } public ChunkCoordIntPair getCoord() { @@ -308,16 +316,16 @@ public abstract class GT_ChunkAssociatedData<T extends GT_ChunkAssociatedData.ID } private int getChunkX(int index) { - return index / regionLength + coord.chunkXPos; + return index / regionLength + coord.chunkXPos * regionLength; } private int getChunkZ(int index) { - return index % regionLength + coord.chunkZPos; + return index % regionLength + coord.chunkZPos * regionLength; } public boolean isDirty() { for (T datum : data) { - if (datum != null && datum.isSameAsDefault()) + if (datum != null && !datum.isSameAsDefault()) return true; } return false; @@ -333,8 +341,6 @@ public abstract class GT_ChunkAssociatedData<T extends GT_ChunkAssociatedData.ID } private void save0() throws IOException { - if (!isDirty()) - return; //noinspection ResultOfMethodCallIgnored backingStorage.getParentFile().mkdirs(); File tmpFile = getTmpFile(); @@ -392,19 +398,32 @@ public abstract class GT_ChunkAssociatedData<T extends GT_ChunkAssociatedData.ID private void loadFromFile(File file) throws IOException { World world = Objects.requireNonNull(this.world.get(), "Attempting to load region of another world!"); try (DataInputStream input = new DataInputStream(new FileInputStream(file))) { - boolean nullRange = input.readBoolean(); - int ptr = 0; - while (ptr != data.length) { - int rangeEnd = ptr + input.readUnsignedShort(); - if (!nullRange) { - for (; ptr < rangeEnd; ptr++) { - data[ptr] = readElement(input, version, world, getChunkX(ptr), getChunkZ(ptr)); - } - } else { - Arrays.fill(data, ptr, rangeEnd, null); - ptr = rangeEnd; + byte b = input.readByte(); + switch (b) { + case 0: + loadV0(input, world); + break; + default: + GT_Log.err.printf("Unknown ChunkAssociatedData version %d\n", b); + } + } + } + + private void loadV0(DataInput input, World world) throws IOException { + int version = input.readByte(); + boolean nullRange = input.readBoolean(); + int ptr = 0; + while (ptr != data.length) { + int rangeEnd = ptr + input.readUnsignedShort(); + if (!nullRange) { + for (; ptr < rangeEnd; ptr++) { + data[ptr] = readElement(input, version, world, getChunkX(ptr), getChunkZ(ptr)); } + } else { + Arrays.fill(data, ptr, rangeEnd, null); + ptr = rangeEnd; } + nullRange = !nullRange; } } diff --git a/src/main/java/gregtech/api/util/GT_ModHandler.java b/src/main/java/gregtech/api/util/GT_ModHandler.java index 810a204c40..acd9a294f9 100644 --- a/src/main/java/gregtech/api/util/GT_ModHandler.java +++ b/src/main/java/gregtech/api/util/GT_ModHandler.java @@ -797,6 +797,13 @@ public class GT_ModHandler { /** * IC2-ThermalCentrifuge Recipe. Overloads old Recipes automatically */ + public static boolean addThermalCentrifugeRecipe(ItemStack aInput, int[] aChances, int aHeat, Object... aOutput) { + if (aInput == null || aOutput == null || aOutput.length <= 0 || aOutput[0] == null) return false; + if (!GregTech_API.sRecipeFile.get(ConfigCategories.Machines.thermalcentrifuge, aInput, true)) return false; + RA.addThermalCentrifugeRecipe(aInput, aOutput.length >= 1 ? (ItemStack)aOutput[0] : null, aOutput.length >= 2 ? (ItemStack)aOutput[1] : null, aOutput.length >= 3 ? (ItemStack)aOutput[2] : null, aChances, 500, 48); + return true; + } + public static boolean addThermalCentrifugeRecipe(ItemStack aInput, int aHeat, Object... aOutput) { if (aInput == null || aOutput == null || aOutput.length <= 0 || aOutput[0] == null) return false; if (!GregTech_API.sRecipeFile.get(ConfigCategories.Machines.thermalcentrifuge, aInput, true)) return false; @@ -807,11 +814,19 @@ public class GT_ModHandler { /** * IC2-OreWasher Recipe. Overloads old Recipes automatically */ + public static boolean addOreWasherRecipe(ItemStack aInput, int[] aChances, int aWaterAmount, Object... aOutput) { + if (aInput == null || aOutput == null || aOutput.length <= 0 || aOutput[0] == null) return false; + if (!GregTech_API.sRecipeFile.get(ConfigCategories.Machines.orewashing, aInput, true)) return false; + RA.addOreWasherRecipe(aInput, (ItemStack)aOutput[0], (ItemStack)aOutput[1], (ItemStack)aOutput[2], GT_ModHandler.getWater(aWaterAmount), aChances, 500, 16); + RA.addOreWasherRecipe(aInput, (ItemStack)aOutput[0], (ItemStack)aOutput[1], (ItemStack)aOutput[2], GT_ModHandler.getDistilledWater(aWaterAmount / 5), aChances, 300, 16); + return true; + } + public static boolean addOreWasherRecipe(ItemStack aInput, int aWaterAmount, Object... aOutput) { if (aInput == null || aOutput == null || aOutput.length <= 0 || aOutput[0] == null) return false; if (!GregTech_API.sRecipeFile.get(ConfigCategories.Machines.orewashing, aInput, true)) return false; - RA.addOreWasherRecipe(aInput, (ItemStack)aOutput[0], (ItemStack)aOutput[1], (ItemStack)aOutput[2], GT_ModHandler.getWater(1000L), 500, 16); - RA.addOreWasherRecipe(aInput, (ItemStack)aOutput[0], (ItemStack)aOutput[1], (ItemStack)aOutput[2], GT_ModHandler.getDistilledWater(200L), 300, 16); + RA.addOreWasherRecipe(aInput, (ItemStack)aOutput[0], (ItemStack)aOutput[1], (ItemStack)aOutput[2], GT_ModHandler.getWater(aWaterAmount), 500, 16); + RA.addOreWasherRecipe(aInput, (ItemStack)aOutput[0], (ItemStack)aOutput[1], (ItemStack)aOutput[2], GT_ModHandler.getDistilledWater(aWaterAmount / 5), 300, 16); return true; } diff --git a/src/main/java/gregtech/api/util/GT_Recipe.java b/src/main/java/gregtech/api/util/GT_Recipe.java index c0ea06af07..6e12a3d36c 100644 --- a/src/main/java/gregtech/api/util/GT_Recipe.java +++ b/src/main/java/gregtech/api/util/GT_Recipe.java @@ -1585,23 +1585,8 @@ public class GT_Recipe implements Comparable<GT_Recipe> { GT_Recipe rRecipe = super.findRecipe(aTileEntity, aRecipe, aNotUnificated, aVoltage, aFluids, aSpecialSlot, aInputs); if (aInputs == null || aInputs.length < 2 || aInputs[0] == null || aInputs[1] == null || !GregTech_API.sPostloadFinished) return rRecipe; - if (rRecipe == null) { - if (ItemList.Shape_Mold_Name.isStackEqual(aInputs[0], false, true)) { - ItemStack tOutput = GT_Utility.copyAmount(1, aInputs[1]); - tOutput.setStackDisplayName(aInputs[0].getDisplayName()); - rRecipe = new GT_Recipe(false, new ItemStack[]{ItemList.Shape_Mold_Name.get(0), GT_Utility.copyAmount(1, aInputs[1])}, new ItemStack[]{tOutput}, null, null, null, null, 128, 8, 0); - rRecipe.mCanBeBuffered = false; - return rRecipe; - } - if (ItemList.Shape_Mold_Name.isStackEqual(aInputs[1], false, true)) { - ItemStack tOutput = GT_Utility.copyAmount(1, aInputs[0]); - tOutput.setStackDisplayName(aInputs[1].getDisplayName()); - rRecipe = new GT_Recipe(false, new ItemStack[]{ItemList.Shape_Mold_Name.get(0), GT_Utility.copyAmount(1, aInputs[0])}, new ItemStack[]{tOutput}, null, null, null, null, 128, 8, 0); - rRecipe.mCanBeBuffered = false; - return rRecipe; - } - return null; - } + if (rRecipe == null) + return findRenamingRecipe(aInputs); for (ItemStack aMold : aInputs) { if (ItemList.Shape_Mold_Credit.isStackEqual(aMold, false, true)) { NBTTagCompound tNBT = aMold.getTagCompound(); @@ -1617,6 +1602,40 @@ public class GT_Recipe implements Comparable<GT_Recipe> { } return rRecipe; } + + private ItemStack findNameMoldIndex(ItemStack[] inputs) { + for (ItemStack stack: inputs) { + if (ItemList.Shape_Mold_Name.isStackEqual(stack, false, true)) + return stack; + } + return null; + } + + private ItemStack findStackToRename(ItemStack[] inputs, ItemStack mold) { + for (ItemStack stack: inputs) { + if (stack == mold || stack == null) + continue; + return stack; + } + return null; + } + + private GT_Recipe findRenamingRecipe(ItemStack[] inputs) { + ItemStack mold = findNameMoldIndex(inputs); + if (mold == null) + return null; + ItemStack input = findStackToRename(inputs, mold); + if (input == null) + return null; + ItemStack output = GT_Utility.copyAmount(1, input); + output.setStackDisplayName(mold.getDisplayName()); + GT_Recipe recipe = new GT_Recipe(false, + new ItemStack[]{ ItemList.Shape_Mold_Name.get(0), GT_Utility.copyAmount(1, input) }, + new ItemStack[]{ output }, + null, null, null, null, 128, 8, 0); + recipe.mCanBeBuffered = false; + return recipe; + } } /** |