aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/gregtech/api/enums/ItemList.java1
-rw-r--r--src/main/java/gregtech/common/covers/GT_Cover_FluidLimiter.java228
-rw-r--r--src/main/java/gregtech/common/items/GT_MetaGenerated_Item_01.java6
-rw-r--r--src/main/resources/assets/gregtech/textures/items/gt.metaitem.01/272.pngbin0 -> 236 bytes
4 files changed, 235 insertions, 0 deletions
diff --git a/src/main/java/gregtech/api/enums/ItemList.java b/src/main/java/gregtech/api/enums/ItemList.java
index 0df54f85b6..59641d16d7 100644
--- a/src/main/java/gregtech/api/enums/ItemList.java
+++ b/src/main/java/gregtech/api/enums/ItemList.java
@@ -551,6 +551,7 @@ public enum ItemList implements IItemContainer {
Upgrade_Muffler,
Upgrade_SteamEngine,
Upgrade_Lock,
+ Cover_FluidLimiter,
Cover_Controller,
Cover_ActivityDetector,
Cover_FluidDetector,
diff --git a/src/main/java/gregtech/common/covers/GT_Cover_FluidLimiter.java b/src/main/java/gregtech/common/covers/GT_Cover_FluidLimiter.java
new file mode 100644
index 0000000000..cff6c2dd7e
--- /dev/null
+++ b/src/main/java/gregtech/common/covers/GT_Cover_FluidLimiter.java
@@ -0,0 +1,228 @@
+package gregtech.common.covers;
+
+import com.google.common.io.ByteArrayDataInput;
+import gregtech.api.enums.GT_Values;
+import gregtech.api.gui.GT_GUICover;
+import gregtech.api.gui.widgets.GT_GuiIntegerTextBox;
+import gregtech.api.interfaces.tileentity.ICoverable;
+import gregtech.api.net.GT_Packet_TileEntityCoverNew;
+import gregtech.api.util.GT_CoverBehaviorBase;
+import gregtech.api.util.GT_Utility;
+import gregtech.api.util.ISerializableObject;
+import io.netty.buffer.ByteBuf;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.entity.player.EntityPlayerMP;
+import net.minecraft.nbt.NBTBase;
+import net.minecraft.nbt.NBTTagCompound;
+import net.minecraft.world.World;
+import net.minecraftforge.common.util.ForgeDirection;
+import net.minecraftforge.fluids.Fluid;
+import net.minecraftforge.fluids.FluidTankInfo;
+import net.minecraftforge.fluids.IFluidHandler;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+/***
+ * @author TrainerSnow#5086
+ */
+public class GT_Cover_FluidLimiter extends GT_CoverBehaviorBase<GT_Cover_FluidLimiter.FluidLimiterData> {
+
+
+ public GT_Cover_FluidLimiter() {
+ super(FluidLimiterData.class);
+ }
+
+ @Override
+ protected FluidLimiterData onCoverScrewdriverClickImpl(byte aSide, int aCoverID, FluidLimiterData aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) {
+ if(aTileEntity instanceof IFluidHandler) {
+ adjustThreshold(aCoverVariable, !aPlayer.isSneaking());
+ GT_Utility.sendChatToPlayer(aPlayer, String.format("Threshold: %f", aCoverVariable.threshold));
+ }
+ return aCoverVariable;
+ }
+
+ @Override
+ protected boolean letsFluidInImpl(byte aSide, int aCoverID, FluidLimiterData aCoverVariable, Fluid aFluid, ICoverable aTileEntity) {
+ return allowsFluidIn(aCoverVariable, aTileEntity);
+ }
+
+ @Override
+ protected boolean alwaysLookConnectedImpl(byte aSide, int aCoverID, FluidLimiterData aCoverVariable, ICoverable aTileEntity) {
+ return true;
+ }
+
+ /*
+ Helpers
+ */
+
+ private boolean allowsFluidIn(FluidLimiterData aCoverVariable, ICoverable c) {
+ if(c instanceof IFluidHandler) {
+ return aCoverVariable.threshold > getFillLevelInputSlots((IFluidHandler) c);
+ }
+ return false;
+ }
+
+
+ private void adjustThreshold(FluidLimiterData coverVariable, boolean way) {
+ if(way) {
+ if((coverVariable.threshold + 0.05f) > 1F) {
+ coverVariable.threshold = 0F;
+ return;
+ }
+ coverVariable.threshold += 0.05F;
+ } else {
+ if((Math.abs(coverVariable.threshold) - 0.05F) < 0F) {
+ coverVariable.threshold = 1F;
+ return;
+ }
+ coverVariable.threshold -= 0.05F;
+ }
+ }
+
+ private float getFillLevelInputSlots(IFluidHandler fh) {
+ FluidTankInfo[] tankInfo = fh.getTankInfo(ForgeDirection.UNKNOWN);
+ long tMax;
+ long tUsed;
+ if(tankInfo != null) {
+ //0 Because we acces first slot only
+ FluidTankInfo inputSlot = tankInfo[0];
+ if(inputSlot.fluid != null) {
+ tMax = inputSlot.capacity;
+ tUsed = inputSlot.fluid.amount;
+ return (float) tUsed / (float) tMax;
+ }
+ }
+ return 0F;
+ }
+
+
+ /*
+ Data
+ */
+
+ @Override
+ public FluidLimiterData createDataObject(int aLegacyData) {
+ return createDataObject();
+ }
+
+ @Override
+ public FluidLimiterData createDataObject() {
+ return new FluidLimiterData(1F);
+ }
+ public static class FluidLimiterData implements ISerializableObject {
+ private float threshold;
+
+ public FluidLimiterData(float threshold) {
+ this.threshold = threshold;
+ }
+
+ @Nonnull
+ @Override
+ public ISerializableObject copy() {
+ return new FluidLimiterData(threshold);
+ }
+
+ @Nonnull
+ @Override
+ public NBTBase saveDataToNBT() {
+ NBTTagCompound tag = new NBTTagCompound();
+ tag.setFloat("threshold", this.threshold);
+ return tag;
+ }
+
+ @Override
+ public void writeToByteBuf(ByteBuf aBuf) {
+ aBuf.writeFloat(this.threshold);
+ }
+
+ @Override
+ public void loadDataFromNBT(NBTBase aNBT) {
+ if(aNBT instanceof NBTTagCompound) {
+ NBTTagCompound tag = (NBTTagCompound) aNBT;
+ this.threshold = tag.getFloat("threshold");
+ }
+ }
+
+ @Nonnull
+ @Override
+ public ISerializableObject readFromPacket(ByteArrayDataInput aBuf, @Nullable EntityPlayerMP aPlayer) {
+ this.threshold = aBuf.readFloat();
+ return this;
+ }
+ }
+
+
+ /*
+ GUI
+ */
+
+ @Override
+ protected Object getClientGUIImpl(byte aSide, int aCoverID, FluidLimiterData aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, World aWorld) {
+ return new GUI(aSide, aCoverID, aCoverVariable, aTileEntity);
+ }
+
+ @Override
+ public boolean hasCoverGUI() {
+ return true;
+ }
+
+ private static class GUI extends GT_GUICover {
+ private static final int startX = 10;
+ private static final int startY = 25;
+ private static final int spaceX = 18;
+ private static final int spaceY = 18;
+ private final byte side;
+ private final int coverID;
+ private final FluidLimiterData coverVariable;
+ private final GT_GuiIntegerTextBox thresholdBox;
+
+
+
+ public GUI(byte aSide, int aCoverID, FluidLimiterData aCoverVariable, ICoverable aTileEntity) {
+ super(aTileEntity, 176, 107, GT_Utility.intToStack(aCoverID));
+ this.side = aSide;
+ this.coverID = aCoverID;
+ this.coverVariable = aCoverVariable;
+
+ thresholdBox = new GT_GuiIntegerTextBox(this, 2, startX, startY + spaceY * 2 - 24, spaceX * 4 - 3, 12) {
+ @Override
+ public boolean validChar(char c, int key) {
+ return super.validChar(c, key) || c == '-';
+ }
+ };
+ }
+
+ @Override
+ public void drawExtras(int mouseX, int mouseY, float parTicks) {
+ super.drawExtras(mouseX, mouseY, parTicks);
+ this.getFontRenderer().drawString("Percent threshold", startX, startY + spaceY * 2 - 35, 0xFF555555);
+ }
+
+ @Override
+ protected void onInitGui(int guiLeft, int guiTop, int gui_width, int gui_height) {
+ thresholdBox.setFocused(true);
+ String text;
+ text = this.coverVariable != null ? String.valueOf(Math.round(this.coverVariable.threshold * 100)) : "";
+ thresholdBox.setText(text);
+ }
+
+ @Override
+ public void applyTextBox(GT_GuiIntegerTextBox box) {
+ int percent;
+ try {
+ percent = Integer.parseInt(box.getText().trim());
+ } catch(NumberFormatException ignored) {
+ resetTextBox(thresholdBox);
+ return;
+ }
+
+ if(percent > 100 || percent <= 0) return;
+ this.coverVariable.threshold = percent / 100F;
+
+ box.setText(String.valueOf(percent));
+
+ GT_Values.NW.sendToServer(new GT_Packet_TileEntityCoverNew(side, coverID, coverVariable, tile));
+ }
+ }
+}
diff --git a/src/main/java/gregtech/common/items/GT_MetaGenerated_Item_01.java b/src/main/java/gregtech/common/items/GT_MetaGenerated_Item_01.java
index 9452218ca6..988038668b 100644
--- a/src/main/java/gregtech/common/items/GT_MetaGenerated_Item_01.java
+++ b/src/main/java/gregtech/common/items/GT_MetaGenerated_Item_01.java
@@ -651,6 +651,10 @@ public class GT_MetaGenerated_Item_01 extends GT_MetaGenerated_Item_X32 {
GregTech_API.registerCover(ItemList.ItemFilter_Export.get(1L), TextureFactory.of(MACHINE_CASINGS[5][0], TextureFactory.of(OVERLAY_CONVEYOR)), new GT_Cover_ItemFilter(true));
ItemList.ItemFilter_Import.set(addItem(271,"Item Filter Cover (Import)", "Right click with an item to set filter (Only supports Import Mode)"));
GregTech_API.registerCover(ItemList.ItemFilter_Import.get(1L), TextureFactory.of(MACHINE_CASINGS[5][0], TextureFactory.of(OVERLAY_CONVEYOR)), new GT_Cover_ItemFilter(false));
+ ItemList.Cover_FluidLimiter.set(addItem(272, "Fluid Limiter Cover", "Limits fluid input depending on fill level"));
+ GregTech_API.registerCover(ItemList.Cover_FluidLimiter.get(1L), TextureFactory.of(MACHINE_CASINGS[1][0], TextureFactory.of(OVERLAY_SHUTTER)), new GT_Cover_FluidLimiter());
+
+
ItemList.Conveyor_Module_LV.set(addItem(630, "Conveyor Module (LV)", "1 stack every 20 secs (as Cover)", new TC_Aspects.TC_AspectStack(TC_Aspects.ELECTRUM, 1L), new TC_Aspects.TC_AspectStack(TC_Aspects.MACHINA, 1L), new TC_Aspects.TC_AspectStack(TC_Aspects.ITER, 1L)));
ItemList.Conveyor_Module_MV.set(addItem(631, "Conveyor Module (MV)", "1 stack every 5 secs (as Cover)", new TC_Aspects.TC_AspectStack(TC_Aspects.ELECTRUM, 2L), new TC_Aspects.TC_AspectStack(TC_Aspects.MACHINA, 2L), new TC_Aspects.TC_AspectStack(TC_Aspects.ITER, 2L)));
@@ -851,10 +855,12 @@ public class GT_MetaGenerated_Item_01 extends GT_MetaGenerated_Item_X32 {
GregTech_API.registerCover(ItemList.Cover_PlayerDetector.get(1L), TextureFactory.of(MACHINE_CASINGS[2][0], TextureFactory.of(TextureFactory.of(OVERLAY_ACTIVITYDETECTOR), TextureFactory.builder().addIcon(OVERLAY_ACTIVITYDETECTOR_GLOW).glow().build())), new GT_Cover_PlayerDetector());
GregTech_API.registerCover(ItemList.Cover_FluidStorageMonitor.get(1L), TextureFactory.of(OVERLAY_FLUID_STORAGE_MONITOR0), new GT_Cover_FluidStorageMonitor());
+
ItemList.Cover_Screen.set(addItem(tLastID = 740, "Computer Monitor Cover", "Displays Data and GUI", new TC_Aspects.TC_AspectStack(TC_Aspects.COGNITIO, 2L), new TC_Aspects.TC_AspectStack(TC_Aspects.LUX, 2L), new TC_Aspects.TC_AspectStack(TC_Aspects.VITREUS, 1L)));
ItemList.Cover_Crafting.set(addItem(tLastID = 744, "Crafting Table Cover", "Better than a wooden Workbench", new TC_Aspects.TC_AspectStack(TC_Aspects.FABRICO, 4L)));
ItemList.Cover_Drain.set(addItem(tLastID = 745, "Drain Module Cover", "Absorbs Fluids and collects Rain", new TC_Aspects.TC_AspectStack(TC_Aspects.VACUOS, 2L), new TC_Aspects.TC_AspectStack(TC_Aspects.AQUA, 2L)));
+
ItemList.Cover_Shutter.set(addItem(tLastID = 749, "Shutter Module Cover", "Blocks Inventory/Tank Side. Use together with Machine Controller.", new TC_Aspects.TC_AspectStack(TC_Aspects.ORDO, 2L), new TC_Aspects.TC_AspectStack(TC_Aspects.ITER, 1L)));
GT_ModHandler.addCraftingRecipe(ItemList.Cover_Screen.get(1L), GT_ModHandler.RecipeBits.DISMANTLEABLE | GT_ModHandler.RecipeBits.NOT_REMOVABLE | GT_ModHandler.RecipeBits.REVERSIBLE, new Object[]{"AGA", "RPB", "ALA", 'A', OrePrefixes.plate.get(Materials.Aluminium), 'L', OrePrefixes.dust.get(Materials.Glowstone), 'R', Dyes.dyeRed, 'G', Dyes.dyeLime, 'B', Dyes.dyeBlue, 'P', OrePrefixes.plate.get(Materials.Glass)});
diff --git a/src/main/resources/assets/gregtech/textures/items/gt.metaitem.01/272.png b/src/main/resources/assets/gregtech/textures/items/gt.metaitem.01/272.png
new file mode 100644
index 0000000000..5afa99fc21
--- /dev/null
+++ b/src/main/resources/assets/gregtech/textures/items/gt.metaitem.01/272.png
Binary files differ