aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/core
diff options
context:
space:
mode:
authorAlkalus <Draknyte1@hotmail.com>2020-05-26 23:30:18 +0100
committerAlkalus <Draknyte1@hotmail.com>2020-05-26 23:30:18 +0100
commit527f3c0e675ed99b82f36108b29884711b3e1a55 (patch)
treee5ddd38d2aee10c539de2e45f08328ef2657cae1 /src/Java/gtPlusPlus/core
parentc5970457e812661b3b8cb6ffe0054df797197679 (diff)
downloadGT5-Unofficial-527f3c0e675ed99b82f36108b29884711b3e1a55.tar.gz
GT5-Unofficial-527f3c0e675ed99b82f36108b29884711b3e1a55.tar.bz2
GT5-Unofficial-527f3c0e675ed99b82f36108b29884711b3e1a55.zip
$ VFS now handles fluids.
$ Fixed crash due to multiple key listeners running. (codechicken.nei.guihook.GuiContainerManager.lastKeyTyped(GuiContainerManager.java:306))
Diffstat (limited to 'src/Java/gtPlusPlus/core')
-rw-r--r--src/Java/gtPlusPlus/core/gui/machine/GUI_VolumetricFlaskSetter.java127
-rw-r--r--src/Java/gtPlusPlus/core/tileentities/general/TileEntityVolumetricFlaskSetter.java46
2 files changed, 111 insertions, 62 deletions
diff --git a/src/Java/gtPlusPlus/core/gui/machine/GUI_VolumetricFlaskSetter.java b/src/Java/gtPlusPlus/core/gui/machine/GUI_VolumetricFlaskSetter.java
index 8df6a8a18e..b0c1e8b6ff 100644
--- a/src/Java/gtPlusPlus/core/gui/machine/GUI_VolumetricFlaskSetter.java
+++ b/src/Java/gtPlusPlus/core/gui/machine/GUI_VolumetricFlaskSetter.java
@@ -20,6 +20,7 @@ import net.minecraft.util.ResourceLocation;
public class GUI_VolumetricFlaskSetter extends GuiContainer {
private GuiTextField mText;
+ private boolean mIsOpen = false;
private TileEntityVolumetricFlaskSetter mTile;
private Container_VolumetricFlaskSetter mContainer;
private static final ResourceLocation mGuiTextures = new ResourceLocation(CORE.MODID, "textures/gui/VolumetricFlaskSetter.png");
@@ -32,6 +33,7 @@ public class GUI_VolumetricFlaskSetter extends GuiContainer {
public void initGui(){
super.initGui();
+ mIsOpen = true;
this.mText = new GuiValueField(this.fontRendererObj, 26, 31, this.width / 2 - 62, this.height/2-52, 106, 14);
mText.setMaxStringLength(5);
mText.setText("0");
@@ -39,47 +41,82 @@ public class GUI_VolumetricFlaskSetter extends GuiContainer {
}
protected void keyTyped(char par1, int par2){
- if (!isNumber(par1) && par2 != Keyboard.KEY_BACK && par2 != Keyboard.KEY_RETURN) {
- mText.setFocused(false);
- super.keyTyped(par1, par2);
- }
- else {
- if (par2 == Keyboard.KEY_RETURN) {
- if (mText.isFocused()) {
- mText.setFocused(false);
+ if (mIsOpen) {
+ if (mText.isFocused()) {
+ if (par2 == Keyboard.KEY_RETURN) {
+ if (mText.isFocused()) {
+ mText.setFocused(false);
+ }
}
- }
- else if (par2 == Keyboard.KEY_BACK) {
- String aCurrentText = getText();
- if (aCurrentText.length() > 0) {
- this.mText.setText(aCurrentText.substring(0, aCurrentText.length() - 1));
- if (getText().length() <= 0) {
- this.mText.setText("0");
+ else if (par2 == Keyboard.KEY_BACK) {
+ String aCurrentText = getText();
+ if (aCurrentText.length() > 0) {
+ this.mText.setText(aCurrentText.substring(0, aCurrentText.length() - 1));
+ if (getText().length() <= 0) {
+ this.mText.setText("0");
+ }
+ sendUpdateToServer();
}
}
+ else {
+ if (isNumber(par1)) {
+ if (this.mText.getText().equals("0")) {
+ this.mText.setText(""+par1);
+ sendUpdateToServer();
+ }
+ else {
+ this.mText.textboxKeyTyped(par1, par2);
+ sendUpdateToServer();
+ }
+ }
+ else {
+ super.keyTyped(par1, par2);
+ }
+ }
}
else {
- if (this.mText.getText().equals("0")) {
- this.mText.setText(""+par1);
- }
- else {
- this.mText.textboxKeyTyped(par1, par2);
- }
- }
- sendUpdateToServer();
+ super.keyTyped(par1, par2);
+ }
}
}
+ @Override
+ public void onGuiClosed() {
+ mIsOpen = false;
+ super.onGuiClosed();
+ }
+
public void updateScreen(){
super.updateScreen();
+ // Update Textbox to 0 if Empty
+ if (getText().length() <= 0) {
+ this.mText.setText("0");
+ sendUpdateToServer();
+ }
this.mText.updateCursorCounter();
+
+ // Check TextBox Value is correct
+ short aCustomValue = 0;
+ if (getText().length() > 0) {
+ try {
+ aCustomValue = Short.parseShort(getText());
+ short aTileValue = ((Container_VolumetricFlaskSetter) mContainer).mCustomValue;
+ if (mContainer != null) {
+ if (aTileValue != aCustomValue){
+ this.mText.setText(""+aTileValue);
+ }
+ }
+ } catch (NumberFormatException ex) {
+
+ }
+ }
}
public void drawScreen(int par1, int par2, float par3){
this.drawDefaultBackground();
super.drawScreen(par1, par2, par3);
-
-
+
+
}
protected void mouseClicked(int x, int y, int btn) {
@@ -104,23 +141,7 @@ public class GUI_VolumetricFlaskSetter extends GuiContainer {
this.fontRendererObj.drawString(I18n.format("6 = 864l", new Object[0]), 64, aYVal, 4210752);
this.fontRendererObj.drawString(I18n.format("3 = 432l", new Object[0]), 8, aYVal+=8, 4210752);
this.fontRendererObj.drawString(I18n.format("-> = Custom", new Object[0]), 59, aYVal, 4210752);
-
-
- // Check TextBox Value is correct
- short aCustomValue = 0;
- if (getText().length() > 0) {
- try {
- aCustomValue = Short.parseShort(getText());
- short aTileValue = ((Container_VolumetricFlaskSetter) mContainer).mCustomValue;
- if (mContainer != null) {
- if (aTileValue != aCustomValue){
- this.mText.setText(""+aTileValue);
- }
- }
- } catch (NumberFormatException ex) {
-
- }
- }
+
}
@Override
@@ -140,16 +161,16 @@ public class GUI_VolumetricFlaskSetter extends GuiContainer {
return this.mText.getText();
}
- protected void sendUpdateToServer() {
- short aCustomValue = 0;
- if (getText().length() > 0) {
- try {
- aCustomValue = Short.parseShort(getText());
- PacketHandler.sendToServer(new Packet_VolumetricFlaskGui(mTile, aCustomValue));
- } catch (NumberFormatException ex) {
-
- }
- }
- }
+ protected void sendUpdateToServer() {
+ short aCustomValue = 0;
+ if (getText().length() > 0) {
+ try {
+ aCustomValue = Short.parseShort(getText());
+ PacketHandler.sendToServer(new Packet_VolumetricFlaskGui(mTile, aCustomValue));
+ } catch (NumberFormatException ex) {
+
+ }
+ }
+ }
} \ No newline at end of file
diff --git a/src/Java/gtPlusPlus/core/tileentities/general/TileEntityVolumetricFlaskSetter.java b/src/Java/gtPlusPlus/core/tileentities/general/TileEntityVolumetricFlaskSetter.java
index fb2a7843aa..6ced7ac7f7 100644
--- a/src/Java/gtPlusPlus/core/tileentities/general/TileEntityVolumetricFlaskSetter.java
+++ b/src/Java/gtPlusPlus/core/tileentities/general/TileEntityVolumetricFlaskSetter.java
@@ -15,6 +15,7 @@ import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
+import net.minecraftforge.fluids.FluidStack;
public class TileEntityVolumetricFlaskSetter extends TileEntity implements ISidedInventory {
@@ -39,7 +40,7 @@ public class TileEntityVolumetricFlaskSetter extends TileEntity implements ISide
public void setCustomValue(int aVal) {
Logger.INFO("Old Value: "+this.aCustomValue);
- this.aCustomValue = (short) MathUtils.balance(aVal, 1, Short.MAX_VALUE);
+ this.aCustomValue = (short) MathUtils.balance(aVal, 0, Short.MAX_VALUE);
Logger.INFO("New Value: "+this.aCustomValue);
markDirty();
}
@@ -58,14 +59,14 @@ public class TileEntityVolumetricFlaskSetter extends TileEntity implements ISide
//Rename to hasCircuitToConfigure
public final boolean hasFlask() {
- for (ItemStack i : this.getInventory().getInventory()) {
- if (i == null) {
+ for (int i=0;i<this.getInventory().getInventory().length-1;i++) {
+ if (i == Container_VolumetricFlaskSetter.SLOT_OUTPUT) {
continue;
}
- else {
+ if (this.getInventory().getInventory()[i] != null) {
return true;
}
- }
+ }
return false;
}
@@ -105,10 +106,17 @@ public class TileEntityVolumetricFlaskSetter extends TileEntity implements ISide
case 7: //Custom
return getCustomValue();
}
- return 0;
+ return 1000;
}
- public boolean addOutput() {
+ public boolean addOutput() {
+
+ // Don't do anything unless we have items
+ if (!hasFlask()) {
+ Logger.INFO("No Flasks.");
+ return false;
+ }
+
ItemStack[] aInputs = this.getInventory().getInventory().clone();
//Check if there is output in slot.
Boolean hasOutput = false;
@@ -124,8 +132,16 @@ public class TileEntityVolumetricFlaskSetter extends TileEntity implements ISide
aSlotCount++;
}
for (int e : aValidSlots) {
+
+ // Skip slot 7 (Custom) unless it has a value > 0
+ if (e == 7 && getCustomValue() <= 0) {
+ Logger.INFO("Skipping Custom slot as value <= 0");
+ continue;
+ }
+
boolean doAdd = false;
ItemStack g = this.getStackInSlot(e);
+ FluidStack aInputFluidStack = VolumetricFlaskHelper.getFlaskFluid(g);
int aSize = 0;
ItemStack aInputStack = null;
int aTypeInSlot = getFlaskType(g);
@@ -138,10 +154,11 @@ public class TileEntityVolumetricFlaskSetter extends TileEntity implements ISide
// Existing Output
else {
ItemStack f = this.getStackInSlot(8);
+ FluidStack aFluidInCheckedSlot = VolumetricFlaskHelper.getFlaskFluid(f);
int aTypeInCheckedSlot = getFlaskType(f);
// Check that the Circuit in the Output slot is not null and the same type as the circuit input.
if (aTypeInCheckedSlot > 0 && (aTypeInSlot == aTypeInCheckedSlot) && f != null) {
- if (g.getItem() == f.getItem() && VolumetricFlaskHelper.getFlaskCapacity(f) == getCapacityForSlot(e)) {
+ if (g.getItem() == f.getItem() && VolumetricFlaskHelper.getFlaskCapacity(f) == getCapacityForSlot(e) && ((aInputFluidStack == null && aFluidInCheckedSlot == null) || aInputFluidStack.isFluidEqual(aFluidInCheckedSlot))) {
aSize = f.stackSize + g.stackSize;
if (aSize > 64) {
aInputStack = g.copy();
@@ -154,6 +171,10 @@ public class TileEntityVolumetricFlaskSetter extends TileEntity implements ISide
if (doAdd) {
// Check Circuit Type
ItemStack aOutput;
+ FluidStack aOutputFluid = null;
+ if (!VolumetricFlaskHelper.isFlaskEmpty(g)) {
+ aOutputFluid = aInputFluidStack.copy();
+ }
if (aTypeInSlot == 1) {
aOutput = VolumetricFlaskHelper.getVolumetricFlask(1);
}
@@ -168,7 +189,14 @@ public class TileEntityVolumetricFlaskSetter extends TileEntity implements ISide
}
if (aOutput != null) {
aOutput.stackSize = aSize;
- VolumetricFlaskHelper.setNewFlaskCapacity(aOutput, getCapacityForSlot(e));
+ int aCapacity = getCapacityForSlot(e);
+ VolumetricFlaskHelper.setNewFlaskCapacity(aOutput, aCapacity);
+ if (aOutputFluid != null) {
+ if (aOutputFluid.amount > aCapacity) {
+ aOutputFluid.amount = aCapacity;
+ }
+ VolumetricFlaskHelper.setFluid(aOutput, aOutputFluid);
+ }
this.setInventorySlotContents(e, aInputStack);
this.setInventorySlotContents(Container_VolumetricFlaskSetter.SLOT_OUTPUT, aOutput);
return true;