diff options
author | Jakub <53441451+kuba6000@users.noreply.github.com> | 2023-01-03 17:53:10 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-03 17:53:10 +0100 |
commit | 9e023c309dbd8ed04375923db1080406b1380efd (patch) | |
tree | 9b1a59b7555243c170f552010cb0ab6efd313941 /src | |
parent | de6ee59646975b4353dd839185d1e166526fed19 (diff) | |
download | GT5-Unofficial-9e023c309dbd8ed04375923db1080406b1380efd.tar.gz GT5-Unofficial-9e023c309dbd8ed04375923db1080406b1380efd.tar.bz2 GT5-Unofficial-9e023c309dbd8ed04375923db1080406b1380efd.zip |
Add enchanced GUI to EIG (#255)
* Add enchanced GUI to EIG
* Spawn 1 render entity instead of 8
* Spawn 1 render entity instead of 5 in EIC
* Spelling
* Dont overshot
Former-commit-id: e99544ed0539a5f04084c4f9d693ca63442a9b3d
Diffstat (limited to 'src')
6 files changed, 474 insertions, 46 deletions
diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/client/renderer/BW_CropVisualizer.java b/src/main/java/com/github/bartimaeusnek/bartworks/client/renderer/BW_CropVisualizer.java index ed710e18de..58ef11827a 100644 --- a/src/main/java/com/github/bartimaeusnek/bartworks/client/renderer/BW_CropVisualizer.java +++ b/src/main/java/com/github/bartimaeusnek/bartworks/client/renderer/BW_CropVisualizer.java @@ -13,16 +13,16 @@ import org.lwjgl.opengl.GL11; @SideOnly(Side.CLIENT) public class BW_CropVisualizer extends EntityFX { - int meta; + int[] meta = new int[8]; static Field tessellatorHasBrightnessField = null; - public BW_CropVisualizer(World world, int x, int y, int z, int meta, int age) { + public BW_CropVisualizer(World world, int x, int y, int z, int age) { super(world, (double) x, ((double) y - 0.0625d), (double) z); this.prevPosX = this.posX; this.prevPosY = this.posY; this.prevPosZ = this.posZ; this.particleMaxAge = age; - this.meta = meta; + for (int i = 0; i < 8; i++) this.meta[i] = this.rand.nextInt(8); } @Override @@ -42,9 +42,6 @@ public class BW_CropVisualizer extends EntityFX { Tessellator tessellator = Tessellator.instance; GL11.glDisable(GL11.GL_CULL_FACE); GL11.glDepthMask(false); - double f11 = this.prevPosX + (this.posX - this.prevPosX) * (double) p_70539_2_ - interpPosX; - double f12 = this.prevPosY + (this.posY - this.prevPosY) * (double) p_70539_2_ - interpPosY; - double f13 = this.prevPosZ + (this.posZ - this.prevPosZ) * (double) p_70539_2_ - interpPosZ; try { if (tessellatorHasBrightnessField == null) { tessellatorHasBrightnessField = Tessellator.class.getDeclaredField( @@ -58,7 +55,16 @@ public class BW_CropVisualizer extends EntityFX { throw new RuntimeException(e); } tessellator.setColorRGBA(255, 255, 255, 255); - RenderBlocks.getInstance().renderBlockCropsImpl(Blocks.wheat, meta, f11, f12, f13); + double f12 = this.posY - interpPosY; + int i = 0; + for (int x = -1; x <= 1; x++) + for (int z = -1; z <= 1; z++) { + if (x == 0 && z == 0) continue; + double f11 = (this.posX + (double) x) - interpPosX; + double f13 = (this.posZ + (double) z) - interpPosZ; + RenderBlocks.getInstance().renderBlockCropsImpl(Blocks.wheat, meta[i++], f11, f12, f13); + } + GL11.glEnable(GL11.GL_CULL_FACE); GL11.glDepthMask(true); } diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/client/renderer/BW_EICPistonVisualizer.java b/src/main/java/com/github/bartimaeusnek/bartworks/client/renderer/BW_EICPistonVisualizer.java index 4aebcab47a..01a08ed8a2 100644 --- a/src/main/java/com/github/bartimaeusnek/bartworks/client/renderer/BW_EICPistonVisualizer.java +++ b/src/main/java/com/github/bartimaeusnek/bartworks/client/renderer/BW_EICPistonVisualizer.java @@ -6,6 +6,7 @@ import gregtech.api.GregTech_API; import net.minecraft.client.particle.EntityFX; import net.minecraft.client.renderer.RenderBlocks; import net.minecraft.client.renderer.Tessellator; +import net.minecraft.util.IIcon; import net.minecraft.world.World; import org.lwjgl.opengl.GL11; @@ -37,20 +38,49 @@ public class BW_EICPistonVisualizer extends EntityFX { Tessellator tessellator = Tessellator.instance; GL11.glDisable(GL11.GL_CULL_FACE); GL11.glDepthMask(false); - double f11 = this.prevPosX + (this.posX - this.prevPosX) * (double) p_70539_2_ - interpPosX; - double f12 = this.prevPosY + (this.posY - this.prevPosY) * (double) p_70539_2_ - interpPosY; - double f13 = this.prevPosZ + (this.posZ - this.prevPosZ) * (double) p_70539_2_ - interpPosZ; RenderBlocks.getInstance().blockAccess = this.worldObj; - tessellator.setTranslation(f11 - this.posX, f12 - this.posY, f13 - this.posZ); RenderBlocks.getInstance().setRenderFromInside(false); + + IIcon icon = GregTech_API.sBlockMetal5.getIcon(0, 2); + + double x = this.posX + 1; + double z = this.posZ; + + double f11 = x - interpPosX; + double f12 = this.posY - interpPosY; + double f13 = z - interpPosZ; + tessellator.setTranslation(f11 - x, f12 - this.posY, f13 - z); RenderBlocks.getInstance() - .renderBlockUsingTexture( - GregTech_API.sBlockMetal5, - (int) this.posX, - (int) this.posY, - (int) this.posZ, - GregTech_API.sBlockMetal5.getIcon(0, 2)); + .renderBlockUsingTexture(GregTech_API.sBlockMetal5, (int) x, (int) this.posY, (int) z, icon); + + x = this.posX - 1; + z = this.posZ; + + f11 = x - interpPosX; + f13 = z - interpPosZ; + tessellator.setTranslation(f11 - x, f12 - this.posY, f13 - z); + RenderBlocks.getInstance() + .renderBlockUsingTexture(GregTech_API.sBlockMetal5, (int) x, (int) this.posY, (int) z, icon); + + x = this.posX; + z = this.posZ + 1; + + f11 = x - interpPosX; + f13 = z - interpPosZ; + tessellator.setTranslation(f11 - x, f12 - this.posY, f13 - z); + RenderBlocks.getInstance() + .renderBlockUsingTexture(GregTech_API.sBlockMetal5, (int) x, (int) this.posY, (int) z, icon); + + x = this.posX; + z = this.posZ - 1; + + f11 = x - interpPosX; + f13 = z - interpPosZ; + tessellator.setTranslation(f11 - x, f12 - this.posY, f13 - z); + RenderBlocks.getInstance() + .renderBlockUsingTexture(GregTech_API.sBlockMetal5, (int) x, (int) this.posY, (int) z, icon); + tessellator.setTranslation(0d, 0d, 0d); GL11.glEnable(GL11.GL_CULL_FACE); diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/common/net/BW_Network.java b/src/main/java/com/github/bartimaeusnek/bartworks/common/net/BW_Network.java index 611c208456..212cc0ae20 100644 --- a/src/main/java/com/github/bartimaeusnek/bartworks/common/net/BW_Network.java +++ b/src/main/java/com/github/bartimaeusnek/bartworks/common/net/BW_Network.java @@ -64,7 +64,8 @@ public class BW_Network extends MessageToMessageCodec<FMLProxyPacket, GT_Packet> new MetaBlockPacket(), new OreDictCachePacket(), new ServerJoinedPackage(), - new EICPacket() + new EICPacket(), + new EIGPacket() }; } diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/common/net/EIGPacket.java b/src/main/java/com/github/bartimaeusnek/bartworks/common/net/EIGPacket.java new file mode 100644 index 0000000000..c65568530b --- /dev/null +++ b/src/main/java/com/github/bartimaeusnek/bartworks/common/net/EIGPacket.java @@ -0,0 +1,56 @@ +package com.github.bartimaeusnek.bartworks.common.net; + +import com.github.bartimaeusnek.bartworks.API.SideReference; +import com.github.bartimaeusnek.bartworks.common.tileentities.multis.GT_TileEntity_ExtremeIndustrialGreenhouse; +import com.github.bartimaeusnek.bartworks.util.Coords; +import com.google.common.io.ByteArrayDataInput; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.net.GT_Packet_New; +import io.netty.buffer.ByteBuf; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.IBlockAccess; + +public class EIGPacket extends GT_Packet_New { + private Coords coords; + private int mMaxSlots; + + public EIGPacket() { + super(true); + } + + public EIGPacket(Coords coords, int mMaxSlots) { + super(false); + this.coords = coords; + this.mMaxSlots = mMaxSlots; + } + + @Override + public byte getPacketID() { + return 6; + } + + @Override + public void encode(ByteBuf aOut) { + aOut.writeInt(coords.x); + aOut.writeInt(coords.y); + aOut.writeInt(coords.z); + aOut.writeInt(mMaxSlots); + } + + @Override + public GT_Packet_New decode(ByteArrayDataInput aData) { + return new EIGPacket(new Coords(aData.readInt(), aData.readInt(), aData.readInt()), aData.readInt()); + } + + @Override + public void process(IBlockAccess aWorld) { + if (SideReference.Side.Client) { + TileEntity te = aWorld.getTileEntity(coords.x, coords.y, coords.z); + if (!(te instanceof IGregTechTileEntity)) return; + IMetaTileEntity mte = ((IGregTechTileEntity) te).getMetaTileEntity(); + if (!(mte instanceof GT_TileEntity_ExtremeIndustrialGreenhouse)) return; + ((GT_TileEntity_ExtremeIndustrialGreenhouse) mte).mMaxSlots = this.mMaxSlots; + } + } +} diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/GT_TileEntity_ElectricImplosionCompressor.java b/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/GT_TileEntity_ElectricImplosionCompressor.java index c3ef47c98a..17ddf53248 100644 --- a/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/GT_TileEntity_ElectricImplosionCompressor.java +++ b/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/GT_TileEntity_ElectricImplosionCompressor.java @@ -356,13 +356,16 @@ public class GT_TileEntity_ElectricImplosionCompressor chunkCoordinates.get(0).posX, chunkCoordinates.get(0).posY, chunkCoordinates.get(0).posZ); - chunkCoordinates.forEach(c -> { - spawnVisualPistonBlock(aBaseMetaTileEntity.getWorld(), c.posX, c.posY, c.posZ, 10); - }); + spawnVisualPistonBlocks( + aBaseMetaTileEntity.getWorld(), + chunkCoordinates.get(2).posX, + chunkCoordinates.get(2).posY, + chunkCoordinates.get(2).posZ, + 10); } @SideOnly(Side.CLIENT) - private void spawnVisualPistonBlock(World world, int x, int y, int z, int age) { + private void spawnVisualPistonBlocks(World world, int x, int y, int z, int age) { BW_EICPistonVisualizer pistonVisualizer = new BW_EICPistonVisualizer(world, x, y, z, age); Minecraft.getMinecraft().effectRenderer.addEffect(pistonVisualizer); } diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/GT_TileEntity_ExtremeIndustrialGreenhouse.java b/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/GT_TileEntity_ExtremeIndustrialGreenhouse.java index 020137ea39..e51b099e49 100644 --- a/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/GT_TileEntity_ExtremeIndustrialGreenhouse.java +++ b/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/GT_TileEntity_ExtremeIndustrialGreenhouse.java @@ -25,12 +25,24 @@ import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; import com.github.bartimaeusnek.bartworks.API.BorosilicateGlass; import com.github.bartimaeusnek.bartworks.API.LoaderReference; +import com.github.bartimaeusnek.bartworks.MainMod; import com.github.bartimaeusnek.bartworks.client.renderer.BW_CropVisualizer; +import com.github.bartimaeusnek.bartworks.common.net.EIGPacket; import com.github.bartimaeusnek.bartworks.util.BW_Tooltip_Reference; import com.github.bartimaeusnek.bartworks.util.ChatColorHelper; +import com.github.bartimaeusnek.bartworks.util.Coords; import com.gtnewhorizon.structurelib.alignment.IAlignmentLimits; import com.gtnewhorizon.structurelib.structure.IStructureDefinition; import com.gtnewhorizon.structurelib.structure.StructureDefinition; +import com.gtnewhorizons.modularui.api.ModularUITextures; +import com.gtnewhorizons.modularui.api.drawable.IDrawable; +import com.gtnewhorizons.modularui.api.drawable.ItemDrawable; +import com.gtnewhorizons.modularui.api.drawable.Text; +import com.gtnewhorizons.modularui.api.math.Color; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; +import com.gtnewhorizons.modularui.api.widget.Widget; +import com.gtnewhorizons.modularui.common.widget.*; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -38,6 +50,7 @@ import gregtech.api.GregTech_API; import gregtech.api.enums.GT_Values; import gregtech.api.enums.ItemList; import gregtech.api.enums.Textures; +import gregtech.api.gui.modularui.GT_UITextures; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; @@ -54,12 +67,16 @@ import ic2.api.crops.CropCard; import ic2.api.crops.Crops; import ic2.core.Ic2Items; import ic2.core.crop.TileEntityCrop; +import java.io.IOException; import java.util.*; +import java.util.function.Function; +import java.util.stream.Collectors; import net.minecraft.block.Block; import net.minecraft.block.BlockFlower; import net.minecraft.block.BlockStem; import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.inventory.InventoryCrafting; @@ -79,10 +96,11 @@ public class GT_TileEntity_ExtremeIndustrialGreenhouse private static final boolean debug = false; private static final int EIG_MATH_VERSION = 0; + private static final int CONFIGURATION_WINDOW_ID = 999; private int oldVersion = 0; private int mCasing = 0; - private int mMaxSlots = 0; + public int mMaxSlots = 0; private int setupphase = 1; private boolean isIC2Mode = false; private byte glasTier = 0; @@ -161,18 +179,18 @@ public class GT_TileEntity_ExtremeIndustrialGreenhouse public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { if (aPlayer.isSneaking()) { if (this.mMaxProgresstime > 0) { - GT_Utility.sendChatToPlayer(aPlayer, "You cant change IC2 mode if the machine is working!"); + GT_Utility.sendChatToPlayer(aPlayer, "You can't change IC2 mode if the machine is working!"); return; } if (!mStorage.isEmpty()) { - GT_Utility.sendChatToPlayer(aPlayer, "You cant change IC2 mode if there are seeds inside!"); + GT_Utility.sendChatToPlayer(aPlayer, "You can't change IC2 mode if there are seeds inside!"); return; } this.isIC2Mode = !this.isIC2Mode; GT_Utility.sendChatToPlayer(aPlayer, "IC2 mode is now " + (this.isIC2Mode ? "enabled" : "disabled.")); } else { if (this.mMaxProgresstime > 0) { - GT_Utility.sendChatToPlayer(aPlayer, "You cant enable/disable setup if the machine is working!"); + GT_Utility.sendChatToPlayer(aPlayer, "You can't enable/disable setup if the machine is working!"); return; } this.setupphase++; @@ -302,8 +320,8 @@ public class GT_TileEntity_ExtremeIndustrialGreenhouse } @SideOnly(Side.CLIENT) - public void spawnVisualCrop(World world, int x, int y, int z, int meta, int age) { - BW_CropVisualizer crop = new BW_CropVisualizer(world, x, y, z, meta, age); + public void spawnVisualCrops(World world, int x, int y, int z, int age) { + BW_CropVisualizer crop = new BW_CropVisualizer(world, x, y, z, age); Minecraft.getMinecraft().effectRenderer.addEffect(crop); } @@ -312,25 +330,27 @@ public class GT_TileEntity_ExtremeIndustrialGreenhouse super.onPostTick(aBaseMetaTileEntity, aTick); if (aBaseMetaTileEntity.isClientSide()) { if (aBaseMetaTileEntity.isActive() && aTick % 40 == 0) { - for (int x = -1; x <= 1; x++) - for (int z = -1; z <= 1; z++) { - if (x == 0 && z == 0) continue; - int[] abc = new int[] {x, -2, z + 2}; - int[] xyz = new int[] {0, 0, 0}; - this.getExtendedFacing().getWorldOffset(abc, xyz); - xyz[0] += aBaseMetaTileEntity.getXCoord(); - xyz[1] += aBaseMetaTileEntity.getYCoord(); - xyz[2] += aBaseMetaTileEntity.getZCoord(); - spawnVisualCrop( - aBaseMetaTileEntity.getWorld(), - xyz[0], - xyz[1], - xyz[2], - aBaseMetaTileEntity.getRandomNumber(8), - 40); - } + int[] abc = new int[] {0, -2, 2}; + int[] xyz = new int[] {0, 0, 0}; + this.getExtendedFacing().getWorldOffset(abc, xyz); + xyz[0] += aBaseMetaTileEntity.getXCoord(); + xyz[1] += aBaseMetaTileEntity.getYCoord(); + xyz[2] += aBaseMetaTileEntity.getZCoord(); + spawnVisualCrops(aBaseMetaTileEntity.getWorld(), xyz[0], xyz[1], xyz[2], 40); } } + if (aBaseMetaTileEntity.isServerSide()) { + MainMod.BW_Network_instance.sendPacketToAllPlayersInRange( + aBaseMetaTileEntity.getWorld(), + new EIGPacket( + new Coords( + aBaseMetaTileEntity.getXCoord(), + aBaseMetaTileEntity.getYCoord(), + aBaseMetaTileEntity.getZCoord()), + mMaxSlots), + aBaseMetaTileEntity.getXCoord(), + aBaseMetaTileEntity.getZCoord()); + } } @Override @@ -369,7 +389,10 @@ public class GT_TileEntity_ExtremeIndustrialGreenhouse if (setupphase == 1) { List<ItemStack> inputs = getStoredInputs(); - for (ItemStack input : inputs) addCrop(input); + for (ItemStack input : inputs) { + addCrop(input); + if (mStorage.size() >= mMaxSlots) break; + } } else if (setupphase == 2) { int emptySlots = 0; boolean ignoreEmptiness = false; @@ -515,6 +538,315 @@ public class GT_TileEntity_ExtremeIndustrialGreenhouse } @Override + public boolean useModularUI() { + return true; + } + + private final Function<Widget, Boolean> isFixed = widget -> getIdealStatus() == getRepairStatus() && mMachine; + + private static final Function<Integer, IDrawable[]> toggleButtonBackgroundGetter = val -> { + if (val == 0) return new IDrawable[] {GT_UITextures.BUTTON_STANDARD, GT_UITextures.OVERLAY_BUTTON_CROSS}; + else return new IDrawable[] {GT_UITextures.BUTTON_STANDARD, GT_UITextures.OVERLAY_BUTTON_CHECKMARK}; + }; + + @Override + public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { + builder.widget(new DrawableWidget() + .setDrawable(GT_UITextures.PICTURE_SCREEN_BLACK) + .setPos(7, 4) + .setSize(143, 75) + .setEnabled(widget -> !isFixed.apply(widget))); + + buildContext.addSyncedWindow(CONFIGURATION_WINDOW_ID, this::createConfigurationWindow); + EntityPlayer player = buildContext.getPlayer(); + + // Slot is not needed + + builder.widget(new DynamicPositionedColumn() + .setSynced(false) + .widget(new CycleButtonWidget() + .setToggle(() -> getBaseMetaTileEntity().isAllowedToWork(), works -> { + if (works) getBaseMetaTileEntity().enableWorking(); + else getBaseMetaTileEntity().disableWorking(); + + if (!(player instanceof EntityPlayerMP)) return; + String tChat = GT_Utility.trans("090", "Machine Processing: ") + + (works + ? GT_Utility.trans("088", "Enabled") + : GT_Utility.trans("087", "Disabled")); + if (hasAlternativeModeText()) tChat = getAlternativeModeText(); + GT_Utility.sendChatToPlayer(player, tChat); + }) + .addTooltip(0, new Text("Disabled").color(Color.RED.dark(3))) + .addTooltip(1, new Text("Enabled").color(Color.GREEN.dark(3))) + .setVariableBackgroundGetter(toggleButtonBackgroundGetter) + .setSize(18, 18) + .addTooltip("Working status")) + .widget(new ButtonWidget() + .setOnClick((clickData, widget) -> { + if (!widget.isClient()) widget.getContext().openSyncedWindow(CONFIGURATION_WINDOW_ID); + }) + .setBackground(GT_UITextures.BUTTON_STANDARD, GT_UITextures.OVERLAY_BUTTON_CYCLIC) + .addTooltip("Configuration") + .setSize(18, 18)) + .setPos(151, 4)); + + final List<ItemStack> drawables = new ArrayList<>(mMaxSlots); + final int perRow = 7; + + Scrollable cropsContainer = new Scrollable().setVerticalScroll(); + + if (mMaxSlots > 0) + for (int i = 0, imax = ((mMaxSlots - 1) / perRow); i <= imax; i++) { + DynamicPositionedRow row = new DynamicPositionedRow().setSynced(false); + for (int j = 0, jmax = (i == imax ? (mMaxSlots - 1) % perRow : (perRow - 1)); j <= jmax; j++) { + final int finalI = i * perRow; + final int finalJ = j; + final int ID = finalI + finalJ; + row.widget(new ButtonWidget() + .setOnClick((clickData, widget) -> { + if (!(player instanceof EntityPlayerMP)) return; + if (mStorage.size() <= ID) return; + if (this.mMaxProgresstime > 0) { + GT_Utility.sendChatToPlayer(player, "Can't eject while running !"); + return; + } + GreenHouseSlot removed = mStorage.remove(ID); + addOutput(removed.input); + GT_Utility.sendChatToPlayer(player, "Crop ejected !"); + }) + .setBackground(() -> new IDrawable[] { + getBaseMetaTileEntity().getGUITextureSet().getItemSlot(), + new ItemDrawable(drawables.size() > ID ? drawables.get(ID) : null) + .withFixedSize(16, 16, 1, 1) + }) + .dynamicTooltip(() -> { + if (drawables.size() > ID) + return Arrays.asList( + drawables.get(ID).getDisplayName(), + "Amount: " + drawables.get(ID).stackSize, + EnumChatFormatting.GRAY + "Left click to eject"); + return Collections.emptyList(); + }) + .setSize(18, 18)); + } + cropsContainer.widget(row.setPos(0, i * 18).setEnabled(widget -> { + int y = widget.getPos().y; + int cy = cropsContainer.getVerticalScrollOffset(); + int ch = cropsContainer.getVisibleHeight(); + return y >= cy - ch && y <= cy + ch; + })); + } + cropsContainer.attachSyncer( + new FakeSyncWidget.ListSyncer<>( + () -> mStorage.stream().map(s -> s.input).collect(Collectors.toList()), + l -> { + drawables.clear(); + drawables.addAll(l); + }, + (buffer, i) -> { + try { + buffer.writeItemStackToBuffer(i); + } catch (IOException e) { + throw new RuntimeException(e); + } + }, + buffer -> { + try { + return buffer.readItemStackFromBuffer(); + } catch (IOException e) { + throw new RuntimeException(e); + } + }), + builder); + + builder.widget(cropsContainer.setPos(10, 16).setSize(128, 60)); + + final DynamicPositionedColumn screenElements = new DynamicPositionedColumn(); + drawTexts(screenElements, null); + builder.widget(screenElements); + } + + protected ModularWindow createConfigurationWindow(final EntityPlayer player) { + ModularWindow.Builder builder = ModularWindow.builder(200, 100); + builder.setBackground(ModularUITextures.VANILLA_BACKGROUND); + builder.widget(new DrawableWidget() + .setDrawable(GT_UITextures.OVERLAY_BUTTON_CYCLIC) + .setPos(5, 5) + .setSize(16, 16)) + .widget(new TextWidget("Configuration").setPos(25, 9)) + .widget(ButtonWidget.closeWindowButton(true).setPos(185, 3)) + .widget(new Column() + .widget(new CycleButtonWidget() + .setLength(3) + .setGetter(() -> setupphase) + .setSetter(val -> { + if (!(player instanceof EntityPlayerMP)) return; + if (this.mMaxProgresstime > 0) { + GT_Utility.sendChatToPlayer( + player, "You can't enable/disable setup if the machine is working!"); + return; + } + this.setupphase = val; + GT_Utility.sendChatToPlayer( + player, + "EIG is now running in " + + (this.setupphase == 1 + ? "setup mode (input)." + : (this.setupphase == 2 + ? "setup mode (output)." + : "normal operation."))); + }) + .addTooltip(0, new Text("Operating").color(Color.GREEN.dark(3))) + .addTooltip(1, new Text("Input").color(Color.YELLOW.dark(3))) + .addTooltip(2, new Text("Output").color(Color.YELLOW.dark(3))) + .setVariableBackgroundGetter(i -> new IDrawable[] { + ModularUITextures.VANILLA_BACKGROUND, + GT_UITextures.OVERLAY_BUTTON_CYCLIC.withFixedSize(18, 18), + i == 0 + ? new Text("Operating") + .color(Color.GREEN.dark(3)) + .withFixedSize(70 - 18, 18, 15, 0) + : i == 1 + ? new Text("Input") + .color(Color.YELLOW.dark(3)) + .withFixedSize(70 - 18, 18, 15, 0) + : new Text("Output") + .color(Color.YELLOW.dark(3)) + .withFixedSize(70 - 18, 18, 15, 0) + }) + .setSize(70, 18) + .addTooltip("Setup mode")) + .widget(new CycleButtonWidget() + .setLength(2) + .setGetter(() -> isIC2Mode ? 1 : 0) + .setSetter(val -> { + if (!(player instanceof EntityPlayerMP)) return; + if (this.mMaxProgresstime > 0) { + GT_Utility.sendChatToPlayer( + player, "You can't change IC2 mode if the machine is working!"); + return; + } + if (!mStorage.isEmpty()) { + GT_Utility.sendChatToPlayer( + player, "You can't change IC2 mode if there are seeds inside!"); + return; + } + this.isIC2Mode = val == 1; + GT_Utility.sendChatToPlayer( + player, "IC2 mode is now " + (this.isIC2Mode ? "enabled" : "disabled.")); + }) + .addTooltip(0, new Text("Disabled").color(Color.RED.dark(3))) + .addTooltip(1, new Text("Enabled").color(Color.GREEN.dark(3))) + .setVariableBackgroundGetter(i -> new IDrawable[] { + ModularUITextures.VANILLA_BACKGROUND, + GT_UITextures.OVERLAY_BUTTON_CYCLIC.withFixedSize(18, 18), + i == 0 + ? new Text("Disabled") + .color(Color.RED.dark(3)) + .withFixedSize(70 - 18, 18, 15, 0) + : new Text("Enabled") + .color(Color.GREEN.dark(3)) + .withFixedSize(70 - 18, 18, 15, 0) + }) + .setSize(70, 18) + .addTooltip("IC2 mode")) + .widget(new CycleButtonWidget() + .setLength(2) + .setGetter(() -> isNoHumidity ? 1 : 0) + .setSetter(val -> { + if (!(player instanceof EntityPlayerMP)) return; + isNoHumidity = val == 1; + GT_Utility.sendChatToPlayer( + player, "Give incoming crops no humidity " + isNoHumidity); + }) + .addTooltip(0, new Text("Disabled").color(Color.RED.dark(3))) + .addTooltip(1, new Text("Enabled").color(Color.GREEN.dark(3))) + .setVariableBackgroundGetter(i -> new IDrawable[] { + ModularUITextures.VANILLA_BACKGROUND, + GT_UITextures.OVERLAY_BUTTON_CYCLIC.withFixedSize(18, 18), + i == 0 + ? new Text("Disabled") + .color(Color.RED.dark(3)) + .withFixedSize(70 - 18, 18, 15, 0) + : new Text("Enabled") + .color(Color.GREEN.dark(3)) + .withFixedSize(70 - 18, 18, 15, 0) + }) + .setSize(70, 18) + .addTooltip("No Humidity mode")) + .setEnabled(widget -> !getBaseMetaTileEntity().isActive()) + .setPos(10, 30)) + .widget(new Column() + .widget(new TextWidget("Setup mode").setSize(100, 18)) + .widget(new TextWidget("IC2 mode").setSize(100, 18)) + .widget(new TextWidget("No Humidity mode").setSize(100, 18)) + .setEnabled(widget -> !getBaseMetaTileEntity().isActive()) + .setPos(80, 30)) + .widget(new DrawableWidget() + .setDrawable(GT_UITextures.OVERLAY_BUTTON_CROSS) + .setSize(18, 18) + .setPos(10, 30) + .addTooltip(new Text("Can't change configuration when running !").color(Color.RED.dark(3))) + .setEnabled(widget -> getBaseMetaTileEntity().isActive())); + return builder.build(); + } + + @Override + protected void drawTexts(DynamicPositionedColumn screenElements, SlotWidget inventorySlot) { + screenElements.setSynced(false).setSpace(0).setPos(10, 7); + + screenElements.widget(new DynamicPositionedRow() + .setSynced(false) + .widget(new TextWidget("Status: ").setDefaultColor(COLOR_TEXT_GRAY.get())) + .widget(new DynamicTextWidget(() -> { + if (getBaseMetaTileEntity().isActive()) return new Text("Working !").color(Color.GREEN.dark(3)); + else if (getBaseMetaTileEntity().isAllowedToWork()) + return new Text("Enabled").color(Color.GREEN.dark(3)); + else if (getBaseMetaTileEntity().wasShutdown()) + return new Text("Shutdown (CRITICAL)").color(Color.RED.dark(3)); + else return new Text("Disabled").color(Color.RED.dark(3)); + })) + .setEnabled(isFixed)); + + screenElements + .widget(new TextWidget(GT_Utility.trans("132", "Pipe is loose.")) + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setEnabled(widget -> !mWrench)) + .widget(new FakeSyncWidget.BooleanSyncer(() -> mWrench, val -> mWrench = val)); + screenElements + .widget(new TextWidget(GT_Utility.trans("133", "Screws are loose.")) + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setEnabled(widget -> !mScrewdriver)) + .widget(new FakeSyncWidget.BooleanSyncer(() -> mScrewdriver, val -> mScrewdriver = val)); + screenElements + .widget(new TextWidget(GT_Utility.trans("134", "Something is stuck.")) + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setEnabled(widget -> !mSoftHammer)) + .widget(new FakeSyncWidget.BooleanSyncer(() -> mSoftHammer, val -> mSoftHammer = val)); + screenElements + .widget(new TextWidget(GT_Utility.trans("135", "Platings are dented.")) + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setEnabled(widget -> !mHardHammer)) + .widget(new FakeSyncWidget.BooleanSyncer(() -> mHardHammer, val -> mHardHammer = val)); + screenElements + .widget(new TextWidget(GT_Utility.trans("136", "Circuitry burned out.")) + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setEnabled(widget -> !mSolderingTool)) + .widget(new FakeSyncWidget.BooleanSyncer(() -> mSolderingTool, val -> mSolderingTool = val)); + screenElements + .widget(new TextWidget(GT_Utility.trans("137", "That doesn't belong there.")) + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setEnabled(widget -> !mCrowbar)) + .widget(new FakeSyncWidget.BooleanSyncer(() -> mCrowbar, val -> mCrowbar = val)); + screenElements + .widget(new TextWidget(GT_Utility.trans("138", "Incomplete Structure.")) + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setEnabled(widget -> !mMachine)) + .widget(new FakeSyncWidget.BooleanSyncer(() -> mMachine, val -> mMachine = val)); + } + + @Override public String[] getInfoData() { List<String> info = new ArrayList<>(Arrays.asList( "Running in mode: " + EnumChatFormatting.GREEN |