Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fluid Input and Output in single-block machines #1575

Open
wants to merge 4 commits into
base: unstable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/java/gregtech/GT_Mod.java
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ public void onPreLoad(FMLPreInitializationEvent aEvent) {
gregtechproxy.ic2EnergySourceCompat = tMainConfig.get("general", "Ic2EnergySourceCompat", true).getBoolean(true);
gregtechproxy.costlyCableConnection = tMainConfig.get("general", "CableConnectionRequiresSolderingMaterial", false).getBoolean(false);
gregtechproxy.mHardRadonRecipe = tMainConfig.get("general","HardRadonRecipe",false).getBoolean(false);
gregtechproxy.mHardCoreInputTanks = tMainConfig.get("general", "HardCoreInputTanks",false).getBoolean(false);
GT_LanguageManager.i18nPlaceholder = tMainConfig.get("general", "UsePlaceholderForMaterialNamesInLangFile", true).getBoolean(true);

Materials[] tDisableOres = new Materials[]{Materials.Chrome, Materials.Naquadria, Materials.Silicon, Materials.Cobalt, Materials.Cadmium, Materials.Indium, Materials.Tungsten,
Expand Down
87 changes: 87 additions & 0 deletions src/main/java/gregtech/api/gui/GT_Container_BasicMachine.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import gregtech.GT_Mod;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicMachine;
import gregtech.api.util.GT_Utility;
import net.minecraft.entity.player.EntityPlayer;
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.Iterator;

Expand Down Expand Up @@ -187,7 +190,91 @@ public ItemStack slotClick(int aSlotIndex, int aMouseclick, int aShifthold, Enti
if (mTileEntity.getMetaTileEntity() == null) return null;
((GT_MetaTileEntity_BasicMachine) mTileEntity.getMetaTileEntity()).mItemTransfer = !((GT_MetaTileEntity_BasicMachine) mTileEntity.getMetaTileEntity()).mItemTransfer;
return null;
case 2:
// fluid output tank
if (mTileEntity.getMetaTileEntity() == null) return null;
GT_MetaTileEntity_BasicMachine tMachine = (GT_MetaTileEntity_BasicMachine) mTileEntity.getMetaTileEntity();
ItemStack tStack = aPlayer.inventory.getItemStack();
if (tStack != null) {
FluidStack tFluid = GT_Utility.getFluidForFilledItem(tStack, true);
if (tFluid != null) {
if (tMachine.getDrainableStack() == null) {
if (tFluid.amount <= tMachine.getCapacity()) {
if (aPlayer.inventory.addItemStackToInventory(GT_Utility.getContainerItem(tStack, true))) {
tMachine.setDrainableStack(tFluid.copy());
tStack.stackSize--;
if (tStack.stackSize <= 0) aPlayer.inventory.setItemStack(null);
aPlayer.inventoryContainer.detectAndSendChanges();
}
}
} else {
if (tFluid.isFluidEqual(tMachine.getDrainableStack()) && tFluid.amount + tMachine.getDrainableStack().amount <= tMachine.getCapacity()) {
if (aPlayer.inventory.addItemStackToInventory(GT_Utility.getContainerItem(tStack, true))) {
tMachine.getDrainableStack().amount += tFluid.amount;
tStack.stackSize--;
if (tStack.stackSize <= 0) aPlayer.inventory.setItemStack(null);
aPlayer.inventoryContainer.detectAndSendChanges();
}
}
}
return tStack;
}
ItemStack tOutput = GT_Utility.fillFluidContainer(tMachine.getDrainableStack(), tStack, false, true);
if (tOutput != null && aPlayer.inventory.addItemStackToInventory(tOutput)) {
tFluid = GT_Utility.getFluidForFilledItem(tOutput, true);
tStack.stackSize--;
if (tStack.stackSize <= 0) aPlayer.inventory.setItemStack(null);
if (tFluid != null) tMachine.getDrainableStack().amount -= tFluid.amount;
if (tMachine.getDrainableStack().amount <= 0 && tMachine.isFluidChangingAllowed()) tMachine.setDrainableStack(null);
aPlayer.inventoryContainer.detectAndSendChanges();
return tStack;
}
}
return null;
default:
if (aSlotIndex == getAllSlotCount() - 1) {
// fluid input tank
if (mTileEntity.getMetaTileEntity() == null) return null;
tMachine = (GT_MetaTileEntity_BasicMachine) mTileEntity.getMetaTileEntity();
tStack = aPlayer.inventory.getItemStack();
if (tStack != null) {
FluidStack tFluid = GT_Utility.getFluidForFilledItem(tStack, true);
if (tFluid != null) {
if (tMachine.getFillableStack() == null) {
if (tFluid.amount <= tMachine.getCapacity()) {
if (aPlayer.inventory.addItemStackToInventory(GT_Utility.getContainerItem(tStack, true))) {
tMachine.setFillableStack(tFluid.copy());
tStack.stackSize--;
if (tStack.stackSize <= 0) aPlayer.inventory.setItemStack(null);
aPlayer.inventoryContainer.detectAndSendChanges();
}
}
} else {
if (tFluid.isFluidEqual(tMachine.getFillableStack()) && tFluid.amount + tMachine.getFillableStack().amount <= tMachine.getCapacity()) {
if (aPlayer.inventory.addItemStackToInventory(GT_Utility.getContainerItem(tStack, true))) {
tMachine.getFillableStack().amount += tFluid.amount;
tStack.stackSize--;
if (tStack.stackSize <= 0) aPlayer.inventory.setItemStack(null);
aPlayer.inventoryContainer.detectAndSendChanges();
}
}
}
return tStack;
}
if (GT_Mod.gregtechproxy.mHardCoreInputTanks) return null;
ItemStack tOutput = GT_Utility.fillFluidContainer(tMachine.getFillableStack(), tStack, false, true);
if (tOutput != null && aPlayer.inventory.addItemStackToInventory(tOutput)) {
tFluid = GT_Utility.getFluidForFilledItem(tOutput, true);
tStack.stackSize--;
if (tStack.stackSize <= 0) aPlayer.inventory.setItemStack(null);
if (tFluid != null) tMachine.getFillableStack().amount -= tFluid.amount;
if (tMachine.getFillableStack().amount <= 0 && tMachine.isFluidChangingAllowed()) tMachine.setFillableStack(null);
aPlayer.inventoryContainer.detectAndSendChanges();
return tStack;
}
}
return null;
}
return super.slotClick(aSlotIndex, aMouseclick, aShifthold, aPlayer);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/gregtech/common/GT_Proxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ public abstract class GT_Proxy implements IGT_Mod, IGuiHandler, IFuelHandler {
public boolean costlyCableConnection = false;
public boolean mMoreComplicatedChemicalRecipes = false;
public boolean mHardRadonRecipe = true;
public boolean mHardCoreInputTanks = false;

public GT_Proxy() {
GameRegistry.registerFuelHandler(this);
Expand Down