Merge pull request #1153 from JohannesGaessler/MultiblockFluidIOFix

Multiblock Fluid IO fix
This commit is contained in:
Blood-Asp 2017-08-11 14:24:37 +02:00 committed by GitHub
commit 4ae02f55c8
12 changed files with 147 additions and 42 deletions

View file

@ -145,6 +145,7 @@ public abstract class GT_MetaTileEntity_BasicTank extends GT_MetaTileEntity_Tier
if (isFluidInputAllowed(tFluid) && tFluid.amount <= getCapacity()) {
if (aBaseMetaTileEntity.addStackToSlot(getOutputSlot(), GT_Utility.getContainerItem(mInventory[getInputSlot()], true), 1)) {
setFillableStack(tFluid.copy());
this.onEmptyingContainerWhenEmpty();
aBaseMetaTileEntity.decrStackSize(getInputSlot(), 1);
}
}
@ -256,4 +257,8 @@ public abstract class GT_MetaTileEntity_BasicTank extends GT_MetaTileEntity_Tier
public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) {
return aIndex == getInputSlot();
}
protected void onEmptyingContainerWhenEmpty(){
//Do nothing
}
}

View file

@ -13,6 +13,10 @@ public abstract class GT_MetaTileEntity_Hatch extends GT_MetaTileEntity_BasicTan
super(aID, aName, aNameRegional, aTier, aInvSlotCount, aDescription, aTextures);
}
public GT_MetaTileEntity_Hatch(int aID, String aName, String aNameRegional, int aTier, int aInvSlotCount, String[] aDescription, ITexture... aTextures) {
super(aID, aName, aNameRegional, aTier, aInvSlotCount, aDescription, aTextures);
}
public GT_MetaTileEntity_Hatch(String aName, int aTier, int aInvSlotCount, String aDescription, ITexture[][][] aTextures) {
super(aName, aTier, aInvSlotCount, aDescription, aTextures);
}

View file

@ -12,7 +12,9 @@ import net.minecraft.item.ItemStack;
public class GT_MetaTileEntity_Hatch_DataAccess extends GT_MetaTileEntity_Hatch {
public GT_MetaTileEntity_Hatch_DataAccess(int aID, String aName, String aNameRegional, int aTier) {
super(aID, aName, aNameRegional, aTier, 16, "Data Access for Multiblocks");
super(aID, aName, aNameRegional, aTier, 16, new String[]{
"Data Access for Multiblocks",
"Adds " + (aTier == 4 ? 4 : 16) + " extra slots for Data Sticks"});
}
public GT_MetaTileEntity_Hatch_DataAccess(String aName, int aTier, String aDescription, ITexture[][][] aTextures) {

View file

@ -11,7 +11,7 @@ import static gregtech.api.enums.GT_Values.V;
public class GT_MetaTileEntity_Hatch_Dynamo extends GT_MetaTileEntity_Hatch {
public GT_MetaTileEntity_Hatch_Dynamo(int aID, String aName, String aNameRegional, int aTier) {
super(aID, aName, aNameRegional, aTier, 0, "Generating electric Energy from Multiblocks");
super(aID, aName, aNameRegional, aTier, 0, new String[]{"Generating electric Energy from Multiblocks", "Puts out up to 1 Amp"});
}
public GT_MetaTileEntity_Hatch_Dynamo(String aName, int aTier, String aDescription, ITexture[][][] aTextures) {

View file

@ -11,7 +11,7 @@ import static gregtech.api.enums.GT_Values.V;
public class GT_MetaTileEntity_Hatch_Energy extends GT_MetaTileEntity_Hatch {
public GT_MetaTileEntity_Hatch_Energy(int aID, String aName, String aNameRegional, int aTier) {
super(aID, aName, aNameRegional, aTier, 0, "Energy Injector for Multiblocks");
super(aID, aName, aNameRegional, aTier, 0, new String[]{"Energy Injector for Multiblocks", "Accepts up to 2 Amps"});
}
public GT_MetaTileEntity_Hatch_Energy(String aName, int aTier, String aDescription, ITexture[][][] aTextures) {

View file

@ -15,7 +15,7 @@ public class GT_MetaTileEntity_Hatch_Input extends GT_MetaTileEntity_Hatch {
public GT_Recipe_Map mRecipeMap = null;
public GT_MetaTileEntity_Hatch_Input(int aID, String aName, String aNameRegional, int aTier) {
super(aID, aName, aNameRegional, aTier, 3, "Fluid Input for Multiblocks (" + 8000 * (aTier + 1) + "L)");
super(aID, aName, aNameRegional, aTier, 3, new String[]{"Fluid Input for Multiblocks", "Capacity: "+ 8000 * (aTier + 1) + "L"});
}
public GT_MetaTileEntity_Hatch_Input(String aName, int aTier, String aDescription, ITexture[][][] aTextures) {

View file

@ -16,7 +16,8 @@ public class GT_MetaTileEntity_Hatch_InputBus extends GT_MetaTileEntity_Hatch {
public GT_Recipe_Map mRecipeMap = null;
public GT_MetaTileEntity_Hatch_InputBus(int aID, String aName, String aNameRegional, int aTier) {
super(aID, aName, aNameRegional, aTier, getSlots(aTier), "Item Input for Multiblocks (" + getSlots(aTier) + " slot" + (getSlots(aTier) >= 2 ? "s" : "") + ")");
super(aID, aName, aNameRegional, aTier, getSlots(aTier), new String[]{"Item Input for Multiblocks",
"Capacity: " + getSlots(aTier) + " stack" + (getSlots(aTier) >= 2 ? "s" : "")});
}
public GT_MetaTileEntity_Hatch_InputBus(String aName, int aTier, String aDescription, ITexture[][][] aTextures) {

View file

@ -15,10 +15,17 @@ import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidHandler;
public class GT_MetaTileEntity_Hatch_Output extends GT_MetaTileEntity_Hatch {
private String lockedFluidName = null;
private EntityPlayer playerThatLockedfluid = null;
public byte mMode = 0;
public GT_MetaTileEntity_Hatch_Output(int aID, String aName, String aNameRegional, int aTier) {
super(aID, aName, aNameRegional, aTier, 3, "Fluid Output for Multiblocks (" + 8000 * (aTier + 1) + "L) (Screwdriver for output type)");
super(aID, aName, aNameRegional, aTier, 3, new String[]{
"Fluid Output for Multiblocks",
"Capacity: " + 8000 * (aTier + 1) + "L",
"Right click with screwdriver to restrict output",
"Can be restricted to put out Items and/or Steam/No Steam/1 specific Fluid",
"Restricted Output Hatches are given priority for Multiblock Fluid output"});
}
public GT_MetaTileEntity_Hatch_Output(String aName, int aTier, String aDescription, ITexture[][][] aTextures) {
@ -96,12 +103,15 @@ public class GT_MetaTileEntity_Hatch_Output extends GT_MetaTileEntity_Hatch {
public void saveNBTData(NBTTagCompound aNBT) {
super.saveNBTData(aNBT);
aNBT.setByte("mMode", mMode);
aNBT.setString("lockedFluidName", lockedFluidName);
}
@Override
public void loadNBTData(NBTTagCompound aNBT) {
super.loadNBTData(aNBT);
mMode = aNBT.getByte("mMode");
lockedFluidName = aNBT.getString("lockedFluidName");
lockedFluidName = lockedFluidName.length() == 0 ? null : lockedFluidName;
}
@Override
@ -153,31 +163,66 @@ public class GT_MetaTileEntity_Hatch_Output extends GT_MetaTileEntity_Hatch {
public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) {
if (!getBaseMetaTileEntity().getCoverBehaviorAtSide(aSide).isGUIClickable(aSide, getBaseMetaTileEntity().getCoverIDAtSide(aSide), getBaseMetaTileEntity().getCoverDataAtSide(aSide), getBaseMetaTileEntity()))
return;
mMode = (byte) ((mMode + 1) % 8);
if (aPlayer.isSneaking()) {
mMode = (byte) ((mMode + 9) % 10);
} else {
mMode = (byte) ((mMode + 1) % 10);
}
String inBrackets;
switch (mMode) {
case 0:
GT_Utility.sendChatToPlayer(aPlayer, trans("108","Outputs Liquids, Steam and Items"));
GT_Utility.sendChatToPlayer(aPlayer, trans("108","Outputs misc. Fluids, Steam and Items"));
this.setLockedFluidName(null);
break;
case 1:
GT_Utility.sendChatToPlayer(aPlayer, trans("109","Outputs Steam and Items"));
this.setLockedFluidName(null);
break;
case 2:
GT_Utility.sendChatToPlayer(aPlayer, trans("110","Outputs Steam and Liquids"));
GT_Utility.sendChatToPlayer(aPlayer, trans("110","Outputs Steam and misc. Fluids"));
this.setLockedFluidName(null);
break;
case 3:
GT_Utility.sendChatToPlayer(aPlayer, trans("111","Outputs Steam"));
this.setLockedFluidName(null);
break;
case 4:
GT_Utility.sendChatToPlayer(aPlayer, trans("112","Outputs Liquids and Items"));
GT_Utility.sendChatToPlayer(aPlayer, trans("112","Outputs misc. Fluids and Items"));
this.setLockedFluidName(null);
break;
case 5:
GT_Utility.sendChatToPlayer(aPlayer, trans("113","Outputs only Items"));
this.setLockedFluidName(null);
break;
case 6:
GT_Utility.sendChatToPlayer(aPlayer, trans("114","Outputs only Liquids"));
GT_Utility.sendChatToPlayer(aPlayer, trans("114","Outputs only misc. Fluids"));
this.setLockedFluidName(null);
break;
case 7:
GT_Utility.sendChatToPlayer(aPlayer, trans("115","Outputs nothing"));
this.setLockedFluidName(null);
break;
case 8:
playerThatLockedfluid = aPlayer;
if (mFluid == null) {
this.setLockedFluidName(null);
inBrackets = trans("115.3","currently none, will be locked to the next that is put in");
} else {
this.setLockedFluidName(this.getDrainableStack().getUnlocalizedName());
inBrackets = this.getDrainableStack().getLocalizedName();
}
GT_Utility.sendChatToPlayer(aPlayer, String.format("%s (%s)", trans("151.1", "Outputs items and 1 specific Fluid"), inBrackets));
break;
case 9:
playerThatLockedfluid = aPlayer;
if (mFluid == null) {
this.setLockedFluidName(null);
inBrackets = trans("115.3","currently none, will be locked to the next that is put in");
} else {
this.setLockedFluidName(this.getDrainableStack().getUnlocalizedName());
inBrackets = this.getDrainableStack().getLocalizedName();
}
GT_Utility.sendChatToPlayer(aPlayer, String.format("%s (%s)", trans("151.2", "Outputs 1 specific Fluid"), inBrackets));
break;
}
}
@ -191,15 +236,35 @@ public class GT_MetaTileEntity_Hatch_Output extends GT_MetaTileEntity_Hatch {
}
public boolean outputsLiquids() {
return mMode % 2 == 0;
return mMode % 2 == 0 || mMode == 9;
}
public boolean outputsItems() {
return mMode % 4 < 2;
return mMode % 4 < 2 && mMode != 9;
}
public boolean isFluidLocked(){
return mMode == 8 || mMode == 9;
}
public String getLockedFluidName() {
return lockedFluidName;
}
public void setLockedFluidName(String lockedFluidName) {
this.lockedFluidName = lockedFluidName;
}
@Override
public int getTankPressure() {
return +100;
}
@Override
protected void onEmptyingContainerWhenEmpty() {
if (this.lockedFluidName == null && this.mFluid != null) {
this.setLockedFluidName(this.mFluid.getUnlocalizedName());
GT_Utility.sendChatToPlayer(playerThatLockedfluid, String.format(trans("151.4","Sucessfully locked Fluid to %s"), mFluid.getLocalizedName()));
}
}
}

View file

@ -12,7 +12,8 @@ import net.minecraft.item.ItemStack;
public class GT_MetaTileEntity_Hatch_OutputBus extends GT_MetaTileEntity_Hatch {
public GT_MetaTileEntity_Hatch_OutputBus(int aID, String aName, String aNameRegional, int aTier) {
super(aID, aName, aNameRegional, aTier, getSlots(aTier), "Item Output for Multiblocks (" + getSlots(aTier) + " slot" + (getSlots(aTier) >= 2 ? "s" : "") + ")");
super(aID, aName, aNameRegional, aTier, getSlots(aTier), new String[]{"Item Output for Multiblocks",
"Capacity: " + getSlots(aTier) + " stack" + (getSlots(aTier) >= 2 ? "s" : "")});
}
public GT_MetaTileEntity_Hatch_OutputBus(String aName, int aTier, String aDescription, ITexture[][][] aTextures) {

View file

@ -263,13 +263,8 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity {
}
addOutput(tStack);
}
if (mOutputFluids != null && mOutputFluids.length == 1) {
for (FluidStack tStack : mOutputFluids)
if (tStack != null) {
addOutput(tStack);
}
} else if (mOutputFluids != null && mOutputFluids.length > 1) {
addFluidOutputs(mOutputFluids);
if (mOutputFluids != null) {
addFluidOutputs(mOutputFluids);
}
mEfficiency = Math.max(0, Math.min(mEfficiency + mEfficiencyIncrease, getMaxEfficiency(mInventory[1]) - ((getIdealStatus() - getRepairStatus()) * 1000)));
mOutputItems = null;
@ -537,29 +532,49 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity {
return false;
}
private boolean dumpFluid(FluidStack copiedFluidStack, boolean restrictiveHatchesOnly){
for (GT_MetaTileEntity_Hatch_Output tHatch : mOutputHatches) {
if (!isValidMetaTileEntity(tHatch) || (restrictiveHatchesOnly && tHatch.mMode == 0)) {
continue;
}
if (GT_ModHandler.isSteam(copiedFluidStack)) {
if (!tHatch.outputsSteam()) {
continue;
}
} else {
if (!tHatch.outputsLiquids()) {
continue;
}
if (tHatch.isFluidLocked() && tHatch.getLockedFluidName() != null && !tHatch.getLockedFluidName().equals(copiedFluidStack.getUnlocalizedName())) {
continue;
}
}
int tAmount = tHatch.fill(copiedFluidStack, false);
if (tAmount >= copiedFluidStack.amount) {
boolean filled = tHatch.fill(copiedFluidStack, true) >= copiedFluidStack.amount;
tHatch.onEmptyingContainerWhenEmpty();
return filled;
} else if (tAmount > 0) {
copiedFluidStack.amount = copiedFluidStack.amount - tHatch.fill(copiedFluidStack, true);
tHatch.onEmptyingContainerWhenEmpty();
}
}
return false;
}
public boolean addOutput(FluidStack aLiquid) {
if (aLiquid == null) return false;
FluidStack tLiquid = aLiquid.copy();
for (GT_MetaTileEntity_Hatch_Output tHatch : mOutputHatches) {
if (isValidMetaTileEntity(tHatch) && GT_ModHandler.isSteam(aLiquid) ? tHatch.outputsSteam() : tHatch.outputsLiquids()) {
int tAmount = tHatch.fill(tLiquid, false);
if (tAmount >= tLiquid.amount) {
return tHatch.fill(tLiquid, true) >= tLiquid.amount;
} else if (tAmount > 0) {
tLiquid.amount = tLiquid.amount - tHatch.fill(tLiquid, true);
}
}
FluidStack copiedFluidStack = aLiquid.copy();
if (!dumpFluid(copiedFluidStack, true)){
dumpFluid(copiedFluidStack, false);
}
return false;
}
protected void addFluidOutputs(FluidStack[] mOutputFluids2) {
for (int i = 0; i < mOutputFluids2.length; i++) {
if (mOutputHatches.size() > i && mOutputHatches.get(i) != null && mOutputFluids2[i] != null && isValidMetaTileEntity(mOutputHatches.get(i))) {
mOutputHatches.get(i).fill(mOutputFluids2[i], true);
}
for (FluidStack outputFluidStack : mOutputFluids2) {
addOutput(outputFluidStack);
}
}
public boolean depleteInput(FluidStack aLiquid) {

View file

@ -730,23 +730,35 @@ public class GT_Recipe implements Comparable<GT_Recipe> {
return findRecipe(aTileEntity, null, aNotUnificated, aVoltage, aFluids, null, aInputs);
}
public GT_Recipe findRecipe(IHasWorldObjectAndCoords aTileEntity, boolean aNotUnificated, boolean aDontCheckStackSizes, long aVoltage, FluidStack[] aFluids, ItemStack... aInputs) {
return findRecipe(aTileEntity, null, aNotUnificated, aDontCheckStackSizes, aVoltage, aFluids, null, aInputs);
}
public GT_Recipe findRecipe(IHasWorldObjectAndCoords aTileEntity, GT_Recipe aRecipe, boolean aNotUnificated, long aVoltage, FluidStack[] aFluids, ItemStack... aInputs) {
return findRecipe(aTileEntity, aRecipe, aNotUnificated, aVoltage, aFluids, null, aInputs);
}
public GT_Recipe findRecipe(IHasWorldObjectAndCoords aTileEntity, GT_Recipe aRecipe, boolean aNotUnificated, boolean aDontCheckStackSizes, long aVoltage, FluidStack[] aFluids, ItemStack... aInputs) {
return findRecipe(aTileEntity, aRecipe, aNotUnificated, aDontCheckStackSizes, aVoltage, aFluids, null, aInputs);
}
public GT_Recipe findRecipe(IHasWorldObjectAndCoords aTileEntity, GT_Recipe aRecipe, boolean aNotUnificated, long aVoltage, FluidStack[] aFluids, ItemStack aSpecialSlot, ItemStack... aInputs) {
return findRecipe(aTileEntity, aRecipe, aNotUnificated, true, aVoltage, aFluids, aSpecialSlot, aInputs);
}
/**
* finds a Recipe matching the aFluid and ItemStack Inputs.
*
* @param aTileEntity an Object representing the current coordinates of the executing Block/Entity/Whatever. This may be null, especially during Startup.
* @param aRecipe in case this is != null it will try to use this Recipe first when looking things up.
* @param aNotUnificated if this is T the Recipe searcher will unificate the ItemStack Inputs
* @param aDontCheckStackSizes if set to false will only return recipes that can be executed at least once with the provided input
* @param aVoltage Voltage of the Machine or Long.MAX_VALUE if it has no Voltage
* @param aFluids the Fluid Inputs
* @param aSpecialSlot the content of the Special Slot, the regular Manager doesn't do anything with this, but some custom ones do.
* @param aInputs the Item Inputs
* @return the Recipe it has found or null for no matching Recipe
*/
public GT_Recipe findRecipe(IHasWorldObjectAndCoords aTileEntity, GT_Recipe aRecipe, boolean aNotUnificated, long aVoltage, FluidStack[] aFluids, ItemStack aSpecialSlot, ItemStack... aInputs) {
public GT_Recipe findRecipe(IHasWorldObjectAndCoords aTileEntity, GT_Recipe aRecipe, boolean aNotUnificated, boolean aDontCheckStackSizes, long aVoltage, FluidStack[] aFluids, ItemStack aSpecialSlot, ItemStack... aInputs) {
// No Recipes? Well, nothing to be found then.
if (mRecipeList.isEmpty()) return null;
@ -772,7 +784,7 @@ public class GT_Recipe implements Comparable<GT_Recipe> {
// Check the Recipe which has been used last time in order to not have to search for it again, if possible.
if (aRecipe != null)
if (!aRecipe.mFakeRecipe && aRecipe.mCanBeBuffered && aRecipe.isRecipeInputEqual(false, true, aFluids, aInputs))
if (!aRecipe.mFakeRecipe && aRecipe.mCanBeBuffered && aRecipe.isRecipeInputEqual(false, aDontCheckStackSizes, aFluids, aInputs))
return aRecipe.mEnabled && aVoltage * mAmperage >= aRecipe.mEUt ? aRecipe : null;
// Now look for the Recipes inside the Item HashMaps, but only when the Recipes usually have Items.
@ -781,11 +793,11 @@ public class GT_Recipe implements Comparable<GT_Recipe> {
Collection<GT_Recipe>
tRecipes = mRecipeItemMap.get(new GT_ItemStack(tStack));
if (tRecipes != null) for (GT_Recipe tRecipe : tRecipes)
if (!tRecipe.mFakeRecipe && tRecipe.isRecipeInputEqual(false, true, aFluids, aInputs))
if (!tRecipe.mFakeRecipe && tRecipe.isRecipeInputEqual(false, aDontCheckStackSizes, aFluids, aInputs))
return tRecipe.mEnabled && aVoltage * mAmperage >= tRecipe.mEUt ? tRecipe : null;
tRecipes = mRecipeItemMap.get(new GT_ItemStack(GT_Utility.copyMetaData(W, tStack)));
if (tRecipes != null) for (GT_Recipe tRecipe : tRecipes)
if (!tRecipe.mFakeRecipe && tRecipe.isRecipeInputEqual(false, true, aFluids, aInputs))
if (!tRecipe.mFakeRecipe && tRecipe.isRecipeInputEqual(false, aDontCheckStackSizes, aFluids, aInputs))
return tRecipe.mEnabled && aVoltage * mAmperage >= tRecipe.mEUt ? tRecipe : null;
}
@ -795,7 +807,7 @@ public class GT_Recipe implements Comparable<GT_Recipe> {
Collection<GT_Recipe>
tRecipes = mRecipeFluidMap.get(aFluid.getFluid());
if (tRecipes != null) for (GT_Recipe tRecipe : tRecipes)
if (!tRecipe.mFakeRecipe && tRecipe.isRecipeInputEqual(false, true, aFluids, aInputs))
if (!tRecipe.mFakeRecipe && tRecipe.isRecipeInputEqual(false, aDontCheckStackSizes, aFluids, aInputs))
return tRecipe.mEnabled && aVoltage * mAmperage >= tRecipe.mEUt ? tRecipe : null;
}

View file

@ -111,7 +111,7 @@ public class GT_MetaTileEntity_LargeChemicalReactor extends GT_MetaTileEntity_Mu
long voltage = getMaxInputVoltage();
byte tier = (byte) Math.max(1, GT_Utility.getTier(voltage));
GT_Recipe recipe = GT_Recipe.GT_Recipe_Map.sMultiblockChemicalRecipes.findRecipe(getBaseMetaTileEntity(), false,
gregtech.api.enums.GT_Values.V[tier], fluids, inputs);
false, gregtech.api.enums.GT_Values.V[tier], fluids, inputs);
if (recipe != null && recipe.isRecipeInputEqual(true, fluids, inputs)) {
this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000);
this.mEfficiencyIncrease = 10000;