diff options
Diffstat (limited to 'src/main/java/gregtech/api')
17 files changed, 267 insertions, 73 deletions
diff --git a/src/main/java/gregtech/api/GregTech_API.java b/src/main/java/gregtech/api/GregTech_API.java index ff875c4884..12fc6b6814 100644 --- a/src/main/java/gregtech/api/GregTech_API.java +++ b/src/main/java/gregtech/api/GregTech_API.java @@ -19,7 +19,15 @@ import gregtech.api.objects.GT_HashSet; import gregtech.api.objects.GT_ItemStack; import gregtech.api.threads.GT_Runnable_Cable_Update; import gregtech.api.threads.GT_Runnable_MachineBlockUpdate; -import gregtech.api.util.*; +import gregtech.api.util.GT_CircuitryBehavior; +import gregtech.api.util.GT_Config; +import gregtech.api.util.GT_CoverBehavior; +import gregtech.api.util.GT_CoverBehaviorBase; +import gregtech.api.util.GT_CreativeTab; +import gregtech.api.util.GT_Log; +import gregtech.api.util.GT_ModHandler; +import gregtech.api.util.GT_OreDictUnificator; +import gregtech.api.util.GT_Utility; import gregtech.api.world.GT_Worldgen; import net.minecraft.block.Block; import net.minecraft.client.renderer.texture.IIconRegister; @@ -30,10 +38,19 @@ import net.minecraft.util.ChunkCoordinates; import net.minecraft.world.World; import net.minecraftforge.fluids.Fluid; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Locale; +import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import static gregtech.api.enums.GT_Values.*; +import static gregtech.api.enums.GT_Values.B; +import static gregtech.api.enums.GT_Values.L; +import static gregtech.api.enums.GT_Values.M; +import static gregtech.api.enums.GT_Values.MOD_ID_IC2; /** * Please do not include this File in your Mod-download as it ruins compatiblity, like with the IC2-API @@ -161,6 +178,8 @@ public class GregTech_API { sHeatHazmatList = new GT_HashSet<>(), sRadioHazmatList = new GT_HashSet<>(), sElectroHazmatList = new GT_HashSet<>(); + private static final List<ItemStack> sRealConfigurationList = new ArrayList<>(); + private static final List<ItemStack> sConfigurationList = Collections.unmodifiableList(sRealConfigurationList); /** * The List of Dimensions, which are Whitelisted for the Teleporter. This list should not contain other Planets. * Mystcraft Dimensions and other Dimensional Things should be allowed. @@ -614,6 +633,31 @@ public class GregTech_API { } } + /** + * Register a new ItemStack as configuration circuits. + * Duplicates or invalid stacks will be silently ignored. + */ + public static void registerConfigurationCircuit(ItemStack aStack) { + if (GT_Utility.isStackInvalid(aStack)) + return; + for (ItemStack tRegistered : sRealConfigurationList) + if (GT_Utility.areStacksEqual(tRegistered, aStack)) + return; + sRealConfigurationList.add(GT_Utility.copyAmount(0, aStack)); + } + + /** + * Get a list of Configuration circuits. All of these stacks will have a stack size of 0. + * Use {@link #registerConfigurationCircuit(ItemStack)} to add to this list. + * + * @return An unmodifiable view of actual list. + * It will reflect the changes to the underlying list as new circuits are registered. + * DO NOT MODIFY THE ItemStacks! + */ + public static List<ItemStack> getConfigurationCircuitList() { + return sConfigurationList; + } + public static void registerCover(ItemStack aStack, ITexture aCover, GT_CoverBehavior aBehavior) { registerCover(aStack, aCover, (GT_CoverBehaviorBase<?>) aBehavior); } @@ -812,5 +856,4 @@ public class GregTech_API { public static void setItemIconRegister(IIconRegister aIconRegister) { GregTech_API.sItemIcons = aIconRegister; } - } diff --git a/src/main/java/gregtech/api/graphs/consumers/NodeEnergyReceiver.java b/src/main/java/gregtech/api/graphs/consumers/NodeEnergyReceiver.java index a24c4acbcd..e1f3c3f0e0 100644 --- a/src/main/java/gregtech/api/graphs/consumers/NodeEnergyReceiver.java +++ b/src/main/java/gregtech/api/graphs/consumers/NodeEnergyReceiver.java @@ -73,7 +73,7 @@ public class NodeEnergyReceiver extends ConsumerNode { tWorld.setBlock(tX, tY, tZ, Blocks.air); if (GregTech_API.sMachineExplosions) if (GT_Mod.gregtechproxy.mPollution) - GT_Pollution.addPollution(tWorld.getChunkFromBlockCoords(tX, tZ), 100000); + GT_Pollution.addPollution(tWorld.getChunkFromBlockCoords(tX, tZ), GT_Mod.gregtechproxy.mPollutionOnExplosion); new WorldSpawnedEventBuilder.ExplosionEffectEventBuilder() .setStrength(tStrength) diff --git a/src/main/java/gregtech/api/gui/GT_Container_BasicMachine.java b/src/main/java/gregtech/api/gui/GT_Container_BasicMachine.java index fbae0b6752..3c1d35c771 100644 --- a/src/main/java/gregtech/api/gui/GT_Container_BasicMachine.java +++ b/src/main/java/gregtech/api/gui/GT_Container_BasicMachine.java @@ -11,7 +11,8 @@ import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; -import net.minecraftforge.fluids.FluidStack; + +import java.util.List; import static gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicMachine.OTHER_SLOT_COUNT; @@ -36,10 +37,13 @@ public class GT_Container_BasicMachine extends GT_Container_BasicTank { addSlotToContainer(new GT_Slot_Holo(mTileEntity, 0, 8, 63, false, true, 1)); addSlotToContainer(new GT_Slot_Holo(mTileEntity, 0, 26, 63, false, true, 1)); addSlotToContainer(new GT_Slot_Render(mTileEntity, 2, 107, 63)); + GT_MetaTileEntity_BasicMachine machine = (GT_MetaTileEntity_BasicMachine) mTileEntity.getMetaTileEntity(); + if (machine.allowSelectCircuit()) + addSlotToContainer(new GT_Slot_Render(mTileEntity, machine.getCircuitSlot(), 153, 63)); - int tStartIndex = ((GT_MetaTileEntity_BasicMachine) mTileEntity.getMetaTileEntity()).getInputSlot(); + int tStartIndex = machine.getInputSlot(); - switch (((GT_MetaTileEntity_BasicMachine) mTileEntity.getMetaTileEntity()).mInputSlotCount) { + switch (machine.mInputSlotCount) { case 0: break; case 1: @@ -107,9 +111,9 @@ public class GT_Container_BasicMachine extends GT_Container_BasicTank { break; } - tStartIndex = ((GT_MetaTileEntity_BasicMachine) mTileEntity.getMetaTileEntity()).getOutputSlot(); + tStartIndex = machine.getOutputSlot(); - switch (((GT_MetaTileEntity_BasicMachine) mTileEntity.getMetaTileEntity()).mOutputItems.length) { + switch (machine.mOutputItems.length) { case 0: break; case 1: @@ -182,8 +186,20 @@ public class GT_Container_BasicMachine extends GT_Container_BasicTank { addSlotToContainer(new GT_Slot_Render(mTileEntity, tStartIndex++, 53, 63)); } + private static int find(List<ItemStack> aStacks, ItemStack aStack) { + if (GT_Utility.isStackInvalid(aStack)) + return -1; + for (int i = 0, aStacksSize = aStacks.size(); i < aStacksSize; i++) { + ItemStack tStack = aStacks.get(i); + if (GT_Utility.areStacksEqual(aStack, tStack)) + return i; + } + return -1; + } + @Override public ItemStack slotClick(int aSlotIndex, int aMouseclick, int aShifthold, EntityPlayer aPlayer) { + if (mTileEntity.getMetaTileEntity() == null) return null; GT_MetaTileEntity_BasicMachine machine = (GT_MetaTileEntity_BasicMachine) mTileEntity.getMetaTileEntity(); if (machine == null) return null; ItemStack tResultStack; @@ -192,9 +208,36 @@ public class GT_Container_BasicMachine extends GT_Container_BasicTank { machine.mFluidTransfer = !machine.mFluidTransfer; return null; case 1: - if (mTileEntity.getMetaTileEntity() == null) return null; machine.mItemTransfer = !machine.mItemTransfer; return null; + case 3: + if (machine.allowSelectCircuit() && aMouseclick < 2) { + ItemStack newCircuit; + if (aMouseclick == 1 && aShifthold == 1) { + // clear + newCircuit = null; + } else { + ItemStack cursorStack = aPlayer.inventory.getItemStack(); + List<ItemStack> tCircuits = machine.getConfigurationCircuits(); + int index = find(tCircuits, cursorStack); + if (index < 0) { + int curIndex = find(tCircuits, machine.getStackInSlot(machine.getCircuitSlot())) + 1; + if (aMouseclick == 0) { + curIndex += 1; + } else { + curIndex -= 1; + } + curIndex = Math.floorMod(curIndex, tCircuits.size() + 1) - 1; + newCircuit = curIndex < 0 ? null : tCircuits.get(curIndex); + } else { + // set to whatever it is + newCircuit = tCircuits.get(index); + } + } + mTileEntity.setInventorySlotContents(machine.getCircuitSlot(), newCircuit); + return newCircuit; + } + return null; default: if (aSlotIndex == OTHER_SLOT_COUNT + 1 + machine.mInputSlotCount + machine.mOutputItems.length && aMouseclick < 2) { if (mTileEntity.isClientSide()) { @@ -255,12 +298,12 @@ public class GT_Container_BasicMachine extends GT_Container_BasicTank { @Override public int getSlotStartIndex() { - return 3; + return 4; } @Override public int getShiftClickStartIndex() { - return 3; + return 4; } @Override diff --git a/src/main/java/gregtech/api/gui/GT_Container_BasicTank.java b/src/main/java/gregtech/api/gui/GT_Container_BasicTank.java index e8810c14c0..79d3636068 100644 --- a/src/main/java/gregtech/api/gui/GT_Container_BasicTank.java +++ b/src/main/java/gregtech/api/gui/GT_Container_BasicTank.java @@ -28,6 +28,10 @@ public class GT_Container_BasicTank extends GT_ContainerMetaTile_Machine { super(aInventoryPlayer, aTileEntity); } + /** + * Subclasses must ensure third slot (aSlotIndex==2) is drainable fluid display item slot. + * Otherwise, subclasses must intercept the appropriate the slotClick event and call super.slotClick(2, xxx) if necessary + */ @Override public void addSlots(InventoryPlayer aInventoryPlayer) { addSlotToContainer(new Slot(mTileEntity, 0, 80, 17)); diff --git a/src/main/java/gregtech/api/interfaces/internal/IGT_RecipeAdder.java b/src/main/java/gregtech/api/interfaces/internal/IGT_RecipeAdder.java index 2267b6c241..9d66e38060 100644 --- a/src/main/java/gregtech/api/interfaces/internal/IGT_RecipeAdder.java +++ b/src/main/java/gregtech/api/interfaces/internal/IGT_RecipeAdder.java @@ -407,6 +407,8 @@ public interface IGT_RecipeAdder { */ boolean addOreWasherRecipe(ItemStack aInput, ItemStack aOutput1, ItemStack aOutput2, ItemStack aOutput3, FluidStack aFluidInput, int aDuration, int aEUt); + boolean addOreWasherRecipe(ItemStack aInput, ItemStack aOutput1, ItemStack aOutput2, ItemStack aOutput3, FluidStack aFluidInput, int[] aChances, int aDuration, int aEUt); + /** * Adds an Implosion Compressor Recipe * @@ -488,6 +490,8 @@ public interface IGT_RecipeAdder { */ boolean addThermalCentrifugeRecipe(ItemStack aInput, ItemStack aOutput1, ItemStack aOutput2, ItemStack aOutput3, int aDuration, int aEUt); + boolean addThermalCentrifugeRecipe(ItemStack aInput, ItemStack aOutput1, ItemStack aOutput2, ItemStack aOutput3, int[] aChances, int aDuration, int aEUt); + /** * Adds an Unboxing Recipe */ diff --git a/src/main/java/gregtech/api/interfaces/tileentity/IEnergyConnected.java b/src/main/java/gregtech/api/interfaces/tileentity/IEnergyConnected.java index 24d0576864..30a5230168 100644 --- a/src/main/java/gregtech/api/interfaces/tileentity/IEnergyConnected.java +++ b/src/main/java/gregtech/api/interfaces/tileentity/IEnergyConnected.java @@ -113,7 +113,7 @@ public interface IEnergyConnected extends IColoredTileEntity, IHasWorldObjectAnd tWorld.setBlock(tX, tY, tZ, Blocks.air); if (GregTech_API.sMachineExplosions) if (GT_Mod.gregtechproxy.mPollution) - GT_Pollution.addPollution(tWorld.getChunkFromBlockCoords(tX, tZ), 100000); + GT_Pollution.addPollution(tWorld.getChunkFromBlockCoords(tX, tZ), GT_Mod.gregtechproxy.mPollutionOnExplosion); new WorldSpawnedEventBuilder.ExplosionEffectEventBuilder() .setStrength(tStrength) diff --git a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java index 9176d063ce..f2514f1290 100644 --- a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java @@ -270,7 +270,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE for (int i = 0; i < tItemList.tagCount(); i++) { NBTTagCompound tTag = tItemList.getCompoundTagAt(i); int tSlot = tTag.getInteger("IntSlot"); - tSlot = shiftInventoryIndex(tSlot, nbtVersion); + tSlot = migrateInventoryIndex(tSlot, nbtVersion); if (tSlot >= 0 && tSlot < mMetaTileEntity.getRealInventory().length) { mMetaTileEntity.getRealInventory()[tSlot] = GT_Utility.loadItem(tTag); } @@ -481,7 +481,8 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE if (mMetaTileEntity.isEnetOutput() && oOutput > 0) { - long tOutputVoltage = Math.max(oOutput, oOutput + (1 << GT_Utility.getTier(oOutput))), tUsableAmperage = Math.min(getOutputAmperage(), (getStoredEU() - mMetaTileEntity.getMinimumStoredEU()) / tOutputVoltage); + long tOutputVoltage = Math.max(oOutput, oOutput + (1L << Math.max(0, GT_Utility.getTier(oOutput) - 1))), + tUsableAmperage = Math.min(getOutputAmperage(), (getStoredEU() - mMetaTileEntity.getMinimumStoredEU()) / tOutputVoltage); if (tUsableAmperage > 0) { long tEU = tOutputVoltage * IEnergyConnected.Util.emitEnergyToNetwork(oOutput, tUsableAmperage, this); mAverageEUOutput[mAverageEUOutputIndex] += tEU; @@ -1403,7 +1404,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE } } - GT_Pollution.addPollution(this, 100000); + GT_Pollution.addPollution(this, GT_Mod.gregtechproxy.mPollutionOnExplosion); mMetaTileEntity.doExplosion(aAmount); } } @@ -2308,9 +2309,13 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE * @param nbtVersion The GregTech version in which the original Inventory Index was saved. * @return The corrected Inventory index */ - private int shiftInventoryIndex(int slotIndex, int nbtVersion){ + private int migrateInventoryIndex(int slotIndex, int nbtVersion){ int oldInputSize, newInputSize, oldOutputSize, newOutputSize; int chemistryUpdateVersion = GT_Mod.calculateTotalGTVersion(509, 31); + int configCircuitAdditionVersion = GT_Mod.calculateTotalGTVersion(509, 40); + // 4 is old GT_MetaTileEntity_BasicMachine.OTHER_SLOT_COUNT + if (nbtVersion < configCircuitAdditionVersion && getMetaTileEntity() instanceof GT_MetaTileEntity_BasicMachine && slotIndex >= 4) + slotIndex += 1; if (mID >= 211 && mID <= 218) {//Assembler if (nbtVersion < chemistryUpdateVersion) { oldInputSize = 2; diff --git a/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java index b3c25ff345..3c499aea53 100644 --- a/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java @@ -5,6 +5,8 @@ import appeng.me.helpers.AENetworkProxy; import cpw.mods.fml.common.Optional; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import gnu.trove.list.TIntList; +import gnu.trove.list.array.TIntArrayList; import gregtech.api.GregTech_API; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicGenerator.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicGenerator.java index bb7b795c36..289a43fdd8 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicGenerator.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicGenerator.java @@ -117,7 +117,7 @@ public abstract class GT_MetaTileEntity_BasicGenerator extends GT_MetaTileEntity @Override public boolean isFacingValid(byte aSide) { - return aSide > 1; + return true; } @Override @@ -214,7 +214,8 @@ public abstract class GT_MetaTileEntity_BasicGenerator extends GT_MetaTileEntity long tFluidAmountToUse = Math.min(mFluid.amount / tConsumed, (maxEUStore() - aBaseMetaTileEntity.getUniversalEnergyStored()) / tFuelValue); //long tFluidAmountToUse = Math.min(mFluid.amount / tConsumed, (maxEUOutput() * 20 + getMinimumStoredEU() - aBaseMetaTileEntity.getUniversalEnergyStored()) / tFuelValue);//TODO CHECK if (tFluidAmountToUse > 0 && aBaseMetaTileEntity.increaseStoredEnergyUnits(tFluidAmountToUse * tFuelValue, true)) { - GT_Pollution.addPollution(getBaseMetaTileEntity(),10 * getPollution()); + // divided by two because this is called every 10 ticks, not 20 + GT_Pollution.addPollution(getBaseMetaTileEntity(),getPollution()/2); mFluid.amount -= tFluidAmountToUse * tConsumed; } } @@ -229,7 +230,8 @@ public abstract class GT_MetaTileEntity_BasicGenerator extends GT_MetaTileEntity if (aBaseMetaTileEntity.addStackToSlot(getOutputSlot(), tEmptyContainer)) { aBaseMetaTileEntity.increaseStoredEnergyUnits(tFuelValue, true); aBaseMetaTileEntity.decrStackSize(getInputSlot(), 1); - GT_Pollution.addPollution(getBaseMetaTileEntity(),10 * getPollution()); + // divided by two because this is called every 10 ticks, not 20 + GT_Pollution.addPollution(getBaseMetaTileEntity(),getPollution()/2); } } } diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java index e8cac808dd..8f77b6ac5a 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java @@ -31,6 +31,7 @@ import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.IFluidHandler; import java.util.Arrays; +import java.util.List; import static gregtech.api.enums.GT_Values.V; import static gregtech.api.enums.GT_Values.debugCleanroom; @@ -53,7 +54,7 @@ public abstract class GT_MetaTileEntity_BasicMachine extends GT_MetaTileEntity_B DID_NOT_FIND_RECIPE = 0, FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS = 1, FOUND_AND_SUCCESSFULLY_USED_RECIPE = 2; - public static final int OTHER_SLOT_COUNT = 4; + public static final int OTHER_SLOT_COUNT = 5; public final ItemStack[] mOutputItems; public final int mInputSlotCount, mAmperage; public boolean mAllowInputFromOutputSide = false, mFluidTransfer = false, mItemTransfer = false, mHasBeenUpdated = false, mStuttering = false, mCharge = false, mDecharge = false; @@ -694,8 +695,11 @@ public abstract class GT_MetaTileEntity_BasicMachine extends GT_MetaTileEntity_B } protected ItemStack[] getAllInputs() { - ItemStack[] rInputs = new ItemStack[mInputSlotCount]; + int tRealInputSlotCount = this.mInputSlotCount + (allowSelectCircuit() ? 1 : 0); + ItemStack[] rInputs = new ItemStack[tRealInputSlotCount]; for (int i = 0; i < mInputSlotCount; i++) rInputs[i] = getInputAt(i); + if (allowSelectCircuit()) + rInputs[mInputSlotCount] = getStackInSlot(getCircuitSlot()); return rInputs; } @@ -850,6 +854,26 @@ public abstract class GT_MetaTileEntity_BasicMachine extends GT_MetaTileEntity_B return mInventory[aIndex] == null; } + public boolean allowSelectCircuit() { + return false; + } + + /** + * This might be non-final in the future, but for now, no, don't change this. + */ + public final int getCircuitSlot() { + return 4; + } + + /** + * Return a list of possible configuration circuit this machine expects. + * + * This list is unmodifiable. Its elements are not supposed to be modified in any way! + */ + public List<ItemStack> getConfigurationCircuits() { + return GregTech_API.getConfigurationCircuitList(); + } + /** * @return the Recipe List which is used for this Machine, this is a useful Default Handler */ diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine_GT_Recipe.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine_GT_Recipe.java index 281d0f6541..7cd9fe65e1 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine_GT_Recipe.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine_GT_Recipe.java @@ -813,6 +813,10 @@ public class GT_MetaTileEntity_BasicMachine_GT_Recipe extends GT_MetaTileEntity_ } } + @Override + public boolean allowSelectCircuit() { + return true; + } @Override public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicTank.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicTank.java index 7b99d78009..552d3d6587 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicTank.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicTank.java @@ -16,7 +16,7 @@ import net.minecraftforge.fluids.FluidTankInfo; /** * NEVER INCLUDE THIS FILE IN YOUR MOD!!! - * <p/> + * * This is the main construct for my generic Tanks. Filling and emptying behavior have to be implemented manually */ public abstract class GT_MetaTileEntity_BasicTank extends GT_MetaTileEntity_TieredMachineBlock implements IHasFluidDisplayItem { diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java index 6369c48f8e..f7b15f2c44 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java @@ -398,7 +398,17 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity { /** * Gets the pollution this Device outputs to a Muffler per tick (10000 = one Pullution Block) */ - public abstract int getPollutionPerTick(ItemStack aStack); + public int getPollutionPerTick(ItemStack aStack){ + return getPollutionPerSecond(aStack)/20; + } + + /** + * Gets the pollution produced per second by this multiblock, default to 0. Override this with + * its actual value in the code of the multiblock. + */ + public int getPollutionPerSecond(ItemStack aStack){ + return 0; + } /** * Gets the damage to the ItemStack, usually 0 or 1. @@ -539,7 +549,7 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity { GT_Log.exp.println("MultiBlockExplosion at: " +this.getBaseMetaTileEntity().getXCoord()+" | "+this.getBaseMetaTileEntity().getYCoord()+" | "+this.getBaseMetaTileEntity().getZCoord()+" DIMID: "+ this.getBaseMetaTileEntity().getWorld().provider.dimensionId+"."); - GT_Pollution.addPollution(getBaseMetaTileEntity(), 300000); + GT_Pollution.addPollution(getBaseMetaTileEntity(), GT_Mod.gregtechproxy.mPollutionOnExplosion); mInventory[1] = null; for (MetaTileEntity tTileEntity : mInputBusses) tTileEntity.getBaseMetaTileEntity().doExplosion(V[8]); for (MetaTileEntity tTileEntity : mOutputBusses) tTileEntity.getBaseMetaTileEntity().doExplosion(V[8]); 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; + } } /** |