diff options
author | Alkalus <Draknyte1@hotmail.com> | 2020-05-26 23:30:18 +0100 |
---|---|---|
committer | Alkalus <Draknyte1@hotmail.com> | 2020-05-26 23:30:18 +0100 |
commit | 527f3c0e675ed99b82f36108b29884711b3e1a55 (patch) | |
tree | e5ddd38d2aee10c539de2e45f08328ef2657cae1 /src | |
parent | c5970457e812661b3b8cb6ffe0054df797197679 (diff) | |
download | GT5-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')
4 files changed, 167 insertions, 85 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; diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/helpers/VolumetricFlaskHelper.java b/src/Java/gtPlusPlus/xmod/gregtech/common/helpers/VolumetricFlaskHelper.java index 61d0797ccf..e85a78b8aa 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/common/helpers/VolumetricFlaskHelper.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/common/helpers/VolumetricFlaskHelper.java @@ -10,9 +10,10 @@ import gtPlusPlus.xmod.gregtech.common.Meta_GT_Proxy; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.fluids.FluidStack; public class VolumetricFlaskHelper { - + private static final Class sClassVolumetricFlask; private static final Method sMethodGetFlaskMaxCapacity; private static Item mFlask; @@ -32,24 +33,24 @@ public class VolumetricFlaskHelper { ItemStack aFlask = ItemUtils.getValueOfItemList("VOLUMETRIC_FLASK", aAmount, (ItemStack) null); return aFlask; } - + public static ItemStack getLargeVolumetricFlask(int aAmount) { ItemStack aFlask = GregtechItemList.VOLUMETRIC_FLASK_8k.get(aAmount); return aFlask; } - + public static ItemStack getGiganticVolumetricFlask(int aAmount) { ItemStack aFlask = GregtechItemList.VOLUMETRIC_FLASK_32k.get(aAmount); return aFlask; } - + public static boolean isVolumetricFlask(ItemStack aStack) { if (isNormalVolumetricFlask(aStack) || isLargeVolumetricFlask(aStack) || isGiganticVolumetricFlask(aStack)) { return true; } return false; } - + public static boolean isNormalVolumetricFlask(ItemStack aStack) { if (mFlask == null) { ItemStack aFlask = ItemUtils.getValueOfItemList("VOLUMETRIC_FLASK", 1, (ItemStack) null); @@ -62,21 +63,21 @@ public class VolumetricFlaskHelper { } return false; } - + public static boolean isLargeVolumetricFlask(ItemStack aStack) { if (GregtechItemList.VOLUMETRIC_FLASK_8k.getItem() == aStack.getItem()) { return true; } return false; } - + public static boolean isGiganticVolumetricFlask(ItemStack aStack) { if (GregtechItemList.VOLUMETRIC_FLASK_32k.getItem() == aStack.getItem()) { return true; } return false; } - + public static int getMaxFlaskCapacity(ItemStack aStack) { if (aStack != null && sMethodGetFlaskMaxCapacity != null) { Item aItem = aStack.getItem(); @@ -87,28 +88,59 @@ public class VolumetricFlaskHelper { } return 0; } + + public static boolean isFlaskEmpty(ItemStack aStack) { + return getFlaskFluid(aStack) == null; + } + + public static FluidStack getFlaskFluid(ItemStack aStack) { + if (aStack.hasTagCompound()) { + NBTTagCompound nbt = aStack.getTagCompound(); + if (nbt.hasKey("Fluid", 10)) + return FluidStack.loadFluidStackFromNBT(nbt.getCompoundTag("Fluid")); + } + return null; + } - public static int getFlaskCapacity(ItemStack aStack) { - int capacity = 1000; - if (aStack.hasTagCompound()) { - NBTTagCompound nbt = aStack.getTagCompound(); - if (nbt.hasKey("Capacity", 3)) - capacity = nbt.getInteger("Capacity"); + public static void setFluid(ItemStack stack, FluidStack fluidStack) { + boolean removeFluid = (fluidStack == null) || (fluidStack.amount <= 0); + NBTTagCompound nbt = stack.getTagCompound(); + if (nbt == null) { + if (removeFluid) + return; + stack.setTagCompound(nbt = new NBTTagCompound()); + } + if (removeFluid) { + nbt.removeTag("Fluid"); + if (nbt.hasNoTags()) { + stack.setTagCompound(null); + } + } else { + nbt.setTag("Fluid", fluidStack.writeToNBT(new NBTTagCompound())); } - return Math.min(getMaxFlaskCapacity(aStack), capacity); + } + + public static int getFlaskCapacity(ItemStack aStack) { + int capacity = 1000; + if (aStack.hasTagCompound()) { + NBTTagCompound nbt = aStack.getTagCompound(); + if (nbt.hasKey("Capacity", 3)) + capacity = nbt.getInteger("Capacity"); + } + return Math.min(getMaxFlaskCapacity(aStack), capacity); } - + public static boolean setNewFlaskCapacity(ItemStack aStack, int aCapacity) { if (aStack == null || aCapacity <= 0) { return false; } aCapacity = Math.min(aCapacity, getMaxFlaskCapacity(aStack)); - NBTTagCompound nbt = aStack.getTagCompound(); - if (nbt == null) { - aStack.setTagCompound(nbt = new NBTTagCompound()); - } - nbt.setInteger("Capacity", aCapacity); - return true; + NBTTagCompound nbt = aStack.getTagCompound(); + if (nbt == null) { + aStack.setTagCompound(nbt = new NBTTagCompound()); + } + nbt.setInteger("Capacity", aCapacity); + return true; } public static Item generateNewFlask(String unlocalized, String english, int maxCapacity) { @@ -122,5 +154,5 @@ public class VolumetricFlaskHelper { } return null; } - + } diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaAtmosphericReconditioner.java b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaAtmosphericReconditioner.java index 33c6bacbd4..04d37e8c1e 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaAtmosphericReconditioner.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaAtmosphericReconditioner.java @@ -268,6 +268,7 @@ public class GregtechMetaAtmosphericReconditioner extends GT_MetaTileEntity_Basi //We are good to clean if (toRemove > 0){ if (damageTurbineRotor() && damageAirFilter()){ + Logger.INFO("Removing "+toRemove+" pollution"); removePollution(mSaveRotor ? (toRemove/2) : toRemove); Logger.WARNING("mNewPollution[4]:"+getCurrentChunkPollution()); } |