From 9a2741128a78bb52eba50a631126e090a5a2abd8 Mon Sep 17 00:00:00 2001 From: miozune Date: Sat, 26 Nov 2022 01:45:28 +0900 Subject: Rewrite GUIs with ModularUI (#1381) * Base work for ModularUI compat * Remove useless interface * Add almost all the widgets * Invert method * Refactor NEI stack placement positions * NEI handlers on ModularUI * Add some more docs * AdvDebugStructureWriter * Fix NEI progressbar not working * PrimitiveBlastFurnace * clean * derp * clean * spotlessApply * Boilers * Buffers * clean * N by N slots containers * Fix boilers not having bucket interaction Put opening UI to individual MetaTEs * Maintenance Hatch * clean * spotlessApply * Add dependency * IndustrialApiary * Adapt to ModularUI change * Base work for covers & fix crash with MP * Fix crash with server * Rewrite base work for covers * Send initial cover data on cover GUI open so that the time of showing incorrect data will be eliminated * Covers part 1 * Rename package: ModularUI -> modularui * Rename class: GT_UIInfo -> GT_UIInfos * Fix build * Covers part2 * Fix missing client check with tile UI & fix title overlap * CoverTabLine * Move cover window creators to inner class * Fix crash with null base TE * Close GUI when tile is broken * Color cover window with tile colorization * Change signature of addUIWidgets * FluidFilter cover, FluidDisplaySlotWidget, BasicTank, BasicGenerator, Output Hatch, MicrowaveEnergyTransmitter, Teleporter, DigitalChest, DigitalTank * Add title tab * Move package: modularui -> modularui/widget * Programmed circuit + IConfigurationCircuitSupport * clean * VolumetricFlask * Remove integrated circuit overlay from recipe input slots * Input Hatch & Quadruple Input Hatch * Multiblock * Deprecate old cover GUI * BasicMachines * Finish BasicMachine & NEI * Expand DTPF NEI to 9 slots * Fix ME input bus on MP * Move AESlotWidget to public class * Move GT_Recipe_Map constructors with mNEIUnificateOutput to setter method * Move SteamTexture.Variant to outer enum * Switch to remote repository * oops * Update MUI * Update MUI * Minor refactor for change amount buttons * Display items and fluids that exceed usual count * blah * use +=, why didn't I do this * Update MUI * Move ModularUI to Base (#1510) * Move ModularUI to Base * Move most of the ModularUI functionality to `BaseTileEntity` (and `CoverableTileEntity`) * `CommonMetaTileEntity` delegates ato the MetaTileEntity * Added several interfaces (with defaults) to indicate if a tile/metatile override/implement certain behaviors. * Moved `IConfigurationCircuitSupport` interface such that it will work with BaseTileEntity or a MetaTileEntity * Address reviews Co-authored-by: miozune * Update MUI * Minor changes to NEI * Return :facepalm: * IGetTabIconSet override * Some more changes to NEI * Merge texture getter interfaces to new class GUITextureSet * Remove BBF structure picture as it's auto-buildable now * Make unified title tab style of texture angular * Expose some boiler texture getters for addon * Fix crash with cover GUI on pipe * Lower the number of recipe per page for DTPF & update MUI * Update MUI * Fix crash with middle-clicking slot on circuit selection GUI * Fix circuit selection window not syncing item from base machine * Merge GT_NEI_AssLineHandler into GT_NEI_DefaultHandler * Update MUI * Add in TecTech multi message * Allow changing the way of binding player inventory * Update MUI * Update MUI * Update MUI * Update MUI * Update MUI * Make MUI non-transitive to allow addons to use their own version * Force enable mixin * Format fluid amount tooltip * Add GUITextureSet.STEAM * Add guard against null ModularWindow creation * Add constructors for Muffler Hatch with inventory * Fix output slot on digital chest and tank allowing insertion * Don't log null ModularWindow * Add default implementation for IHasWorldObjectAndCoords#openGUI * Make openGTTileEntityUI accept MultiTE & cleanup Co-authored-by: Jason Mitchell --- .../api/metatileentity/BaseMetaTileEntity.java | 1 + .../api/metatileentity/BaseTileEntity.java | 412 ++++++++++++++++++++- .../api/metatileentity/CommonMetaTileEntity.java | 128 +++++++ .../api/metatileentity/CoverableTileEntity.java | 151 ++++++++ .../api/metatileentity/MetaPipeEntity.java | 14 + .../api/metatileentity/MetaTileEntity.java | 166 ++++++--- .../GT_MetaTileEntity_BasicBatteryBuffer.java | 65 ++-- .../GT_MetaTileEntity_BasicGenerator.java | 9 +- .../GT_MetaTileEntity_BasicMachine.java | 323 +++++++++++++++- .../GT_MetaTileEntity_BasicMachine_Bronze.java | 12 + .../GT_MetaTileEntity_BasicMachine_Steel.java | 15 +- .../GT_MetaTileEntity_BasicTank.java | 92 ++++- .../implementations/GT_MetaTileEntity_Buffer.java | 95 ++++- .../GT_MetaTileEntity_Hatch_DataAccess.java | 56 ++- .../GT_MetaTileEntity_Hatch_Input.java | 9 +- .../GT_MetaTileEntity_Hatch_InputBus.java | 67 ++-- .../GT_MetaTileEntity_Hatch_Maintenance.java | 75 ++-- .../GT_MetaTileEntity_Hatch_Muffler.java | 18 +- .../GT_MetaTileEntity_Hatch_MultiInput.java | 117 +++++- .../GT_MetaTileEntity_Hatch_Output.java | 85 ++++- .../GT_MetaTileEntity_Hatch_OutputBus.java | 65 ++-- .../GT_MetaTileEntity_MultiBlockBase.java | 154 +++++++- .../GT_MetaTileEntity_SpecialFilter.java | 111 +++++- .../GT_MetaTileEntity_TieredMachineBlock.java | 38 ++ 24 files changed, 1974 insertions(+), 304 deletions(-) (limited to 'src/main/java/gregtech/api/metatileentity') diff --git a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java index ebf0672815..395c73570c 100644 --- a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java @@ -1671,6 +1671,7 @@ public class BaseMetaTileEntity extends CommonMetaTileEntity GT_Log.err.println( "Encountered Exception while rightclicking TileEntity, the Game should've crashed now, but I prevented that. Please report immediately to GregTech Intergalactical!!!"); e.printStackTrace(GT_Log.err); + e.printStackTrace(); } return false; diff --git a/src/main/java/gregtech/api/metatileentity/BaseTileEntity.java b/src/main/java/gregtech/api/metatileentity/BaseTileEntity.java index 1f6fb0c68d..23a247468a 100644 --- a/src/main/java/gregtech/api/metatileentity/BaseTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/BaseTileEntity.java @@ -7,25 +7,61 @@ import static gregtech.api.enums.GT_Values.NW; import static gregtech.api.enums.GT_Values.SIDE_DOWN; import static gregtech.api.enums.GT_Values.SIDE_UP; +import com.gtnewhorizons.modularui.api.drawable.IDrawable; +import com.gtnewhorizons.modularui.api.drawable.ItemDrawable; +import com.gtnewhorizons.modularui.api.forge.ItemStackHandler; +import com.gtnewhorizons.modularui.api.math.Alignment; +import com.gtnewhorizons.modularui.api.screen.ITileWithModularUI; +import com.gtnewhorizons.modularui.api.screen.ModularUIContext; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; +import com.gtnewhorizons.modularui.common.internal.network.NetworkUtils; +import com.gtnewhorizons.modularui.common.internal.wrapper.BaseSlot; +import com.gtnewhorizons.modularui.common.widget.DrawableWidget; +import com.gtnewhorizons.modularui.common.widget.MultiChildWidget; +import com.gtnewhorizons.modularui.common.widget.SlotGroup; +import com.gtnewhorizons.modularui.common.widget.SlotWidget; +import com.gtnewhorizons.modularui.common.widget.TextWidget; +import gregtech.GT_Mod; +import gregtech.api.enums.Dyes; +import gregtech.api.enums.GT_Values; +import gregtech.api.gui.modularui.GT_UITextures; +import gregtech.api.gui.modularui.GUITextureSet; +import gregtech.api.interfaces.IConfigurationCircuitSupport; +import gregtech.api.interfaces.modularui.IAddGregtechLogo; +import gregtech.api.interfaces.modularui.IAddInventorySlots; +import gregtech.api.interfaces.modularui.IGetGUITextureSet; import gregtech.api.interfaces.tileentity.IGTEnet; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.interfaces.tileentity.IHasWorldObjectAndCoords; import gregtech.api.interfaces.tileentity.IIC2Enet; import gregtech.api.net.GT_Packet_Block_Event; +import gregtech.api.net.GT_Packet_SetConfigurationCircuit; +import gregtech.api.util.GT_TooltipDataCache; +import gregtech.api.util.GT_Util; import gregtech.api.util.GT_Utility; +import gregtech.common.gui.modularui.uifactory.SelectItemUIFactory; import ic2.api.energy.event.EnergyTileLoadEvent; import ic2.api.energy.event.EnergyTileUnloadEvent; import java.util.Arrays; +import java.util.List; import java.util.concurrent.ThreadLocalRandom; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.function.Supplier; import net.minecraft.block.Block; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ChunkCoordinates; +import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.MathHelper; +import net.minecraft.util.StatCollector; import net.minecraft.world.World; import net.minecraft.world.biome.BiomeGenBase; import net.minecraft.world.chunk.Chunk; @@ -38,7 +74,14 @@ import net.minecraftforge.fluids.IFluidHandler; *

* Basically everything a TileEntity should have. */ -public abstract class BaseTileEntity extends TileEntity implements IHasWorldObjectAndCoords, IIC2Enet, IGTEnet { +public abstract class BaseTileEntity extends TileEntity + implements IHasWorldObjectAndCoords, + IIC2Enet, + IGTEnet, + ITileWithModularUI, + IAddGregtechLogo, + IGetGUITextureSet, + IAddInventorySlots { protected boolean mInventoryChanged = false; /** @@ -138,11 +181,13 @@ public abstract class BaseTileEntity extends TileEntity implements IHasWorldObje } @Override + @Deprecated public final boolean openGUI(EntityPlayer aPlayer) { return openGUI(aPlayer, 0); } @Override + @Deprecated public final boolean openGUI(EntityPlayer aPlayer, int aID) { if (aPlayer == null) return false; aPlayer.openGui(GT, aID, worldObj, xCoord, yCoord, zCoord); @@ -536,6 +581,37 @@ public abstract class BaseTileEntity extends TileEntity implements IHasWorldObje return GT_Utility.trans(aKey, aEnglish); } + protected Supplier getValidator() { + return () -> !this.isDead(); + } + + public boolean useModularUI() { + return false; + } + + @Override + public ModularWindow createWindow(UIBuildContext buildContext) { + if (!useModularUI()) return null; + + buildContext.setValidator(getValidator()); + final ModularWindow.Builder builder = ModularWindow.builder(getGUIWidth(), getGUIHeight()); + builder.setBackground(getGUITextureSet().getMainBackground()); + builder.setGuiTint(getGUIColorization()); + if (doesBindPlayerInventory()) { + bindPlayerInventoryUI(builder, buildContext); + } + addUIWidgets(builder, buildContext); + addTitleToUI(builder); + addCoverTabs(builder, buildContext); + final IConfigurationCircuitSupport csc = getConfigurationCircuitSupport(); + if (csc != null && csc.allowSelectCircuit()) { + addConfigurationCircuitSlot(builder); + } else { + addGregTechLogo(builder); + } + return builder.build(); + } + /* * IC2 Energy Compat */ @@ -571,4 +647,338 @@ public abstract class BaseTileEntity extends TileEntity implements IHasWorldObje MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(ic2EnergySink)); } } + + // === GUI stuff === + + public ItemStackHandler getInventoryHandler() { + return null; + } + + protected GT_TooltipDataCache mTooltipCache = new GT_TooltipDataCache(); + + // Tooltip localization keys + public static final String BATTERY_SLOT_TOOLTIP = "GT5U.machines.battery_slot.tooltip", + BATTERY_SLOT_TOOLTIP_ALT = "GT5U.machines.battery_slot.tooltip.alternative", + UNUSED_SLOT_TOOLTIP = "GT5U.machines.unused_slot.tooltip", + SPECIAL_SLOT_TOOLTIP = "GT5U.machines.special_slot.tooltip", + FLUID_INPUT_TOOLTIP = "GT5U.machines.fluid_input_slot.tooltip", + FLUID_OUTPUT_TOOLTIP = "GT5U.machines.fluid_output_slot.tooltip", + STALLED_STUTTERING_TOOLTIP = "GT5U.machines.stalled_stuttering.tooltip", + STALLED_VENT_TOOLTIP = "GT5U.machines.stalled_vent.tooltip", + FLUID_TRANSFER_TOOLTIP = "GT5U.machines.fluid_transfer.tooltip", + ITEM_TRANSFER_TOOLTIP = "GT5U.machines.item_transfer.tooltip", + POWER_SOURCE_KEY = "GT5U.machines.powersource.", + NEI_TRANSFER_STEAM_TOOLTIP = "GT5U.machines.nei_transfer.steam.tooltip", + NEI_TRANSFER_VOLTAGE_TOOLTIP = "GT5U.machines.nei_transfer.voltage.tooltip"; + + public static final int TOOLTIP_DELAY = 5; + + /** + * Override this to add {@link com.gtnewhorizons.modularui.api.widget.Widget}s for your UI. + */ + public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) {} + + public void bindPlayerInventoryUI(ModularWindow.Builder builder, UIBuildContext buildContext) { + builder.bindPlayerInventory( + buildContext.getPlayer(), 7, getGUITextureSet().getItemSlot()); + } + + public String getLocalName() { + return "Unknown"; + } + + protected void addTitleToUI(ModularWindow.Builder builder) { + addTitleToUI(builder, getLocalName()); + } + + protected void addTitleToUI(ModularWindow.Builder builder, String title) { + if (GT_Mod.gregtechproxy.mTitleTabStyle == 2) { + addTitleItemIconStyle(builder, title); + } else { + addTitleTextStyle(builder, title); + } + } + + protected void addTitleTextStyle(ModularWindow.Builder builder, String title) { + final int TAB_PADDING = 3; + final int TITLE_PADDING = 2; + int titleWidth = 0, titleHeight = 0; + if (NetworkUtils.isClient()) { + final FontRenderer fontRenderer = Minecraft.getMinecraft().fontRenderer; + //noinspection unchecked + final List titleLines = + fontRenderer.listFormattedStringToWidth(title, getGUIWidth() - (TAB_PADDING + TITLE_PADDING) * 2); + titleWidth = titleLines.size() > 1 + ? getGUIWidth() - (TAB_PADDING + TITLE_PADDING) * 2 + : fontRenderer.getStringWidth(title); + //noinspection PointlessArithmeticExpression + titleHeight = titleLines.size() * fontRenderer.FONT_HEIGHT + (titleLines.size() - 1) * 1; + } + + final DrawableWidget tab = new DrawableWidget(); + final TextWidget text = new TextWidget(title) + .setDefaultColor(getTitleColor()) + .setTextAlignment(Alignment.CenterLeft) + .setMaxWidth(titleWidth); + if (GT_Mod.gregtechproxy.mTitleTabStyle == 1) { + tab.setDrawable(getGUITextureSet().getTitleTabAngular()) + .setPos(0, -(titleHeight + TAB_PADDING) + 1) + .setSize(getGUIWidth(), titleHeight + TAB_PADDING * 2); + text.setPos(TAB_PADDING + TITLE_PADDING, -titleHeight + TAB_PADDING); + } else { + tab.setDrawable(getGUITextureSet().getTitleTabDark()) + .setPos(0, -(titleHeight + TAB_PADDING * 2) + 1) + .setSize(titleWidth + (TAB_PADDING + TITLE_PADDING) * 2, titleHeight + TAB_PADDING * 2 - 1); + text.setPos(TAB_PADDING + TITLE_PADDING, -titleHeight); + } + builder.widget(tab).widget(text); + } + + protected void addTitleItemIconStyle(ModularWindow.Builder builder, String title) { + builder.widget(new MultiChildWidget() + .addChild(new DrawableWidget() + .setDrawable(getGUITextureSet().getTitleTabNormal()) + .setPos(0, 0) + .setSize(24, 24)) + .addChild(new ItemDrawable(getStackForm(1)).asWidget().setPos(4, 4)) + .addTooltip(title) + .setTooltipShowUpDelay(TOOLTIP_DELAY) + .setPos(0, -24 + 3)); + } + + @Override + public GUITextureSet getGUITextureSet() { + return GUITextureSet.DEFAULT; + } + + protected int getTitleColor() { + return COLOR_TITLE.get(); + } + + @Override + public void addGregTechLogo(ModularWindow.Builder builder) { + builder.widget(new DrawableWidget() + .setDrawable(getGUITextureSet().getGregTechLogo()) + .setSize(17, 17) + .setPos(152, 63)); + } + + protected int getGUIWidth() { + return 176; + } + + protected int getGUIHeight() { + return 166; + } + + protected boolean doesBindPlayerInventory() { + return true; + } + + @Override + public void add1by1Slot(ModularWindow.Builder builder, IDrawable... background) { + final ItemStackHandler inventoryHandler = getInventoryHandler(); + if (inventoryHandler == null) return; + + if (background.length == 0) { + background = new IDrawable[] {getGUITextureSet().getItemSlot()}; + } + builder.widget(SlotGroup.ofItemHandler(inventoryHandler, 1) + .startFromSlot(0) + .endAtSlot(0) + .background(background) + .build() + .setPos(79, 34)); + } + + @Override + public void add2by2Slots(ModularWindow.Builder builder, IDrawable... background) { + final ItemStackHandler inventoryHandler = getInventoryHandler(); + if (inventoryHandler == null) return; + + if (background.length == 0) { + background = new IDrawable[] {getGUITextureSet().getItemSlot()}; + } + builder.widget(SlotGroup.ofItemHandler(inventoryHandler, 2) + .startFromSlot(0) + .endAtSlot(3) + .background(background) + .build() + .setPos(70, 25)); + } + + @Override + public void add3by3Slots(ModularWindow.Builder builder, IDrawable... background) { + final ItemStackHandler inventoryHandler = getInventoryHandler(); + if (inventoryHandler == null) return; + + if (background.length == 0) { + background = new IDrawable[] {getGUITextureSet().getItemSlot()}; + } + builder.widget(SlotGroup.ofItemHandler(inventoryHandler, 3) + .startFromSlot(0) + .endAtSlot(8) + .background(background) + .build() + .setPos(61, 16)); + } + + @Override + public void add4by4Slots(ModularWindow.Builder builder, IDrawable... background) { + final ItemStackHandler inventoryHandler = getInventoryHandler(); + if (inventoryHandler == null) return; + + if (background.length == 0) { + background = new IDrawable[] {getGUITextureSet().getItemSlot()}; + } + builder.widget(SlotGroup.ofItemHandler(inventoryHandler, 4) + .startFromSlot(0) + .endAtSlot(15) + .background(background) + .build() + .setPos(52, 7)); + } + + public void addCoverTabs(ModularWindow.Builder builder, UIBuildContext buildContext) { + /* Do nothing */ + } + + public IConfigurationCircuitSupport getConfigurationCircuitSupport() { + if (!(this instanceof IConfigurationCircuitSupport)) return null; + return (IConfigurationCircuitSupport) this; + } + + protected void addConfigurationCircuitSlot(ModularWindow.Builder builder) { + final ItemStackHandler inventoryHandler = getInventoryHandler(); + if (inventoryHandler == null) return; + + if (!(this instanceof IInventory)) return; + final IInventory inv = (IInventory) this; + + final IConfigurationCircuitSupport ccs = getConfigurationCircuitSupport(); + if (ccs == null) return; + + final AtomicBoolean dialogOpened = new AtomicBoolean(false); + builder.widget( + new SlotWidget(new BaseSlot(inventoryHandler, ccs.getCircuitSlot(), true)) { + @Override + protected void phantomClick(ClickData clickData, ItemStack cursorStack) { + final ItemStack newCircuit; + if (clickData.shift) { + if (clickData.mouseButton == 0) { + if (NetworkUtils.isClient() && !dialogOpened.get()) { + openSelectCircuitDialog(getContext(), dialogOpened); + } + return; + } else { + newCircuit = null; + } + } else { + final List tCircuits = ccs.getConfigurationCircuits(); + final int index = GT_Utility.findMatchingStackInList(tCircuits, cursorStack); + if (index < 0) { + int curIndex = GT_Utility.findMatchingStackInList( + tCircuits, inv.getStackInSlot(ccs.getCircuitSlot())) + + 1; + if (clickData.mouseButton == 0) { + curIndex += 1; + } else { + curIndex -= 1; + } + curIndex = Math.floorMod(curIndex, tCircuits.size() + 1) - 1; + newCircuit = curIndex < 0 ? null : tCircuits.get(curIndex); + } else { + // set to whatever it is + newCircuit = tCircuits.get(index); + } + } + inv.setInventorySlotContents(ccs.getCircuitSlot(), newCircuit); + } + + @Override + protected void phantomScroll(int direction) { + phantomClick(new ClickData(direction > 0 ? 1 : 0, false, false, false)); + } + + @Override + public List getExtraTooltip() { + return Arrays.asList( + EnumChatFormatting.DARK_GRAY + + EnumChatFormatting.getTextWithoutFormattingCodes( + StatCollector.translateToLocal( + "GT5U.machines.select_circuit.tooltip.1")), + EnumChatFormatting.DARK_GRAY + + EnumChatFormatting.getTextWithoutFormattingCodes( + StatCollector.translateToLocal( + "GT5U.machines.select_circuit.tooltip.2")), + EnumChatFormatting.DARK_GRAY + + EnumChatFormatting.getTextWithoutFormattingCodes( + StatCollector.translateToLocal( + "GT5U.machines.select_circuit.tooltip.3"))); + } + }.setOverwriteItemStackTooltip(list -> { + list.removeIf(line -> + line.contains(StatCollector.translateToLocal("gt.integrated_circuit.tooltip.0")) + || line.contains( + StatCollector.translateToLocal("gt.integrated_circuit.tooltip.1"))); + return list; + }) + .disableShiftInsert() + .setHandlePhantomActionClient(true) + .setBackground(getGUITextureSet().getItemSlot(), GT_UITextures.OVERLAY_SLOT_INT_CIRCUIT) + .setGTTooltip(() -> mTooltipCache.getData("GT5U.machines.select_circuit.tooltip")) + .setTooltipShowUpDelay(TOOLTIP_DELAY) + .setPos(ccs.getCircuitSlotX() - 1, ccs.getCircuitSlotY() - 1)); + } + + protected void openSelectCircuitDialog(ModularUIContext uiContext, AtomicBoolean dialogOpened) { + final IConfigurationCircuitSupport ccs = getConfigurationCircuitSupport(); + if (ccs == null) return; + + if (!(this instanceof IInventory)) return; + final IInventory inv = (IInventory) this; + + final List circuits = ccs.getConfigurationCircuits(); + uiContext.openClientWindow(player -> new SelectItemUIFactory( + StatCollector.translateToLocal("GT5U.machines.select_circuit"), + getStackForm(0), + this::onCircuitSelected, + circuits, + GT_Utility.findMatchingStackInList(circuits, inv.getStackInSlot(ccs.getCircuitSlot()))) + .setAnotherWindow(true, dialogOpened) + .setGuiTint(getGUIColorization()) + .setCurrentGetter(() -> inv.getStackInSlot(ccs.getCircuitSlot())) + .createWindow(new UIBuildContext(player))); + } + + protected void onCircuitSelected(ItemStack selected) { + final IConfigurationCircuitSupport ccs = getConfigurationCircuitSupport(); + if (ccs == null) return; + + if (!(this instanceof IInventory)) return; + final IInventory inv = (IInventory) this; + + GT_Values.NW.sendToServer(new GT_Packet_SetConfigurationCircuit(this, selected)); + // we will not do any validation on client side + // it doesn't get to actually decide what inventory contains anyway + inv.setInventorySlotContents(ccs.getCircuitSlot(), selected); + } + + protected int getTextColorOrDefault(String textType, int defaultColor) { + return defaultColor; + } + + protected Supplier COLOR_TITLE = () -> getTextColorOrDefault("title", 0x404040); + protected Supplier COLOR_TITLE_WHITE = () -> getTextColorOrDefault("title_white", 0xfafaff); + protected Supplier COLOR_TEXT_WHITE = () -> getTextColorOrDefault("text_white", 0xfafaff); + protected Supplier COLOR_TEXT_GRAY = () -> getTextColorOrDefault("text_gray", 0x404040); + protected Supplier COLOR_TEXT_RED = () -> getTextColorOrDefault("text_red", 0xff0000); + + public int getGUIColorization() { + return GT_Util.getRGBaInt(Dyes.dyeWhite.getRGBA()); + } + + public ItemStack getStackForm(long aAmount) { + return null; + } } diff --git a/src/main/java/gregtech/api/metatileentity/CommonMetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/CommonMetaTileEntity.java index bf835b51bb..e2860d6292 100644 --- a/src/main/java/gregtech/api/metatileentity/CommonMetaTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/CommonMetaTileEntity.java @@ -2,9 +2,18 @@ package gregtech.api.metatileentity; import static gregtech.GT_Mod.GT_FML_LOGGER; +import com.gtnewhorizons.modularui.api.forge.ItemStackHandler; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; import gregtech.GT_Mod; import gregtech.api.GregTech_API; +import gregtech.api.gui.modularui.GUITextureSet; +import gregtech.api.interfaces.IConfigurationCircuitSupport; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.modularui.IAddGregtechLogo; +import gregtech.api.interfaces.modularui.IAddUIWidgets; +import gregtech.api.interfaces.modularui.IBindPlayerInventoryUI; +import gregtech.api.interfaces.modularui.IGetTitleColor; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.objects.GT_ItemStack; import gregtech.api.util.GT_Log; @@ -167,4 +176,123 @@ public abstract class CommonMetaTileEntity extends CoverableTileEntity implement final IMetaTileEntity meta = getMetaTileEntity(); return meta != null && meta.shouldJoinIc2Enet(); } + + /* + * Modular UI Support + */ + + @Override + public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { + if (hasValidMetaTileEntity() && getMetaTileEntity() instanceof IAddUIWidgets) { + ((IAddUIWidgets) getMetaTileEntity()).addUIWidgets(builder, buildContext); + return; + } + super.addUIWidgets(builder, buildContext); + } + + @Override + public void bindPlayerInventoryUI(ModularWindow.Builder builder, UIBuildContext buildContext) { + if (hasValidMetaTileEntity() && getMetaTileEntity() instanceof IBindPlayerInventoryUI) { + ((IBindPlayerInventoryUI) getMetaTileEntity()).bindPlayerInventoryUI(builder, buildContext); + return; + } + super.bindPlayerInventoryUI(builder, buildContext); + } + + @Override + public IConfigurationCircuitSupport getConfigurationCircuitSupport() { + if (hasValidMetaTileEntity() && getMetaTileEntity() instanceof IConfigurationCircuitSupport) { + return (IConfigurationCircuitSupport) getMetaTileEntity(); + } + return null; + } + + @Override + public ItemStackHandler getInventoryHandler() { + if (hasValidMetaTileEntity()) { + return getMetaTileEntity().getInventoryHandler(); + } + return null; + } + + @Override + public boolean useModularUI() { + return hasValidMetaTileEntity() && getMetaTileEntity().useModularUI(); + } + + @Override + public String getLocalName() { + if (hasValidMetaTileEntity()) return getMetaTileEntity().getLocalName(); + return super.getLocalName(); + } + + @Override + protected int getGUIWidth() { + if (hasValidMetaTileEntity()) return getMetaTileEntity().getGUIWidth(); + + return super.getGUIWidth(); + } + + @Override + protected int getGUIHeight() { + if (hasValidMetaTileEntity()) return getMetaTileEntity().getGUIHeight(); + + return super.getGUIHeight(); + } + + @Override + protected boolean doesBindPlayerInventory() { + if (hasValidMetaTileEntity()) return getMetaTileEntity().doesBindPlayerInventory(); + + return super.doesBindPlayerInventory(); + } + + @Override + public void addGregTechLogo(ModularWindow.Builder builder) { + if (hasValidMetaTileEntity() && getMetaTileEntity() instanceof IAddGregtechLogo) { + ((IAddGregtechLogo) getMetaTileEntity()).addGregTechLogo(builder); + return; + } + super.addGregTechLogo(builder); + } + + @Override + public ItemStack getStackForm(long aAmount) { + if (hasValidMetaTileEntity()) { + return getMetaTileEntity().getStackForm(aAmount); + } + return super.getStackForm(aAmount); + } + + @Override + public int getTitleColor() { + if (hasValidMetaTileEntity() && getMetaTileEntity() instanceof IGetTitleColor) { + return ((IGetTitleColor) getMetaTileEntity()).getTitleColor(); + } + return super.getTitleColor(); + } + + @Override + public int getGUIColorization() { + if (hasValidMetaTileEntity()) { + return getMetaTileEntity().getGUIColorization(); + } + return super.getGUIColorization(); + } + + @Override + protected int getTextColorOrDefault(String textType, int defaultColor) { + if (hasValidMetaTileEntity()) { + return getMetaTileEntity().getTextColorOrDefault(textType, defaultColor); + } + return defaultColor; + } + + @Override + public GUITextureSet getGUITextureSet() { + if (hasValidMetaTileEntity()) { + return getMetaTileEntity().getGUITextureSet(); + } + return super.getGUITextureSet(); + } } diff --git a/src/main/java/gregtech/api/metatileentity/CoverableTileEntity.java b/src/main/java/gregtech/api/metatileentity/CoverableTileEntity.java index 9511488a3f..580fc136e6 100644 --- a/src/main/java/gregtech/api/metatileentity/CoverableTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/CoverableTileEntity.java @@ -6,31 +6,52 @@ import static gregtech.api.enums.GT_Values.NW; import static gregtech.api.util.GT_LanguageManager.FACES; import static gregtech.api.util.GT_LanguageManager.getTranslation; +import com.gtnewhorizons.modularui.api.drawable.IDrawable; +import com.gtnewhorizons.modularui.api.drawable.ItemDrawable; +import com.gtnewhorizons.modularui.api.math.MainAxisAlignment; +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.ButtonWidget; +import com.gtnewhorizons.modularui.common.widget.Column; +import com.gtnewhorizons.modularui.common.widget.MultiChildWidget; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; import gregtech.GT_Mod; import gregtech.api.GregTech_API; +import gregtech.api.enums.GT_Values; import gregtech.api.enums.Textures; +import gregtech.api.gui.modularui.GT_CoverUIBuildContext; +import gregtech.api.gui.modularui.GUITextureSet; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.ICoverable; import gregtech.api.interfaces.tileentity.IGregtechWailaProvider; import gregtech.api.net.GT_Packet_RequestCoverData; import gregtech.api.net.GT_Packet_SendCoverData; +import gregtech.api.net.GT_Packet_TileEntityCoverGUI; import gregtech.api.objects.GT_ItemStack; import gregtech.api.util.GT_CoverBehavior; import gregtech.api.util.GT_CoverBehaviorBase; import gregtech.api.util.ISerializableObject; import gregtech.common.GT_Client; import gregtech.common.covers.GT_Cover_Fluidfilter; +import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.stream.IntStream; import mcp.mobius.waila.api.IWailaConfigHandler; import mcp.mobius.waila.api.IWailaDataAccessor; +import net.minecraft.client.Minecraft; import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.StatCollector; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.FluidRegistry; @@ -526,4 +547,134 @@ public abstract class CoverableTileEntity extends BaseTileEntity implements ICov } } } + + protected ModularWindow createCoverWindow(EntityPlayer player, byte side) { + final GT_CoverBehaviorBase coverBehavior = getCoverBehaviorAtSideNew(side); + final GT_CoverUIBuildContext buildContext = + new GT_CoverUIBuildContext(player, getCoverIDAtSide(side), side, this, true); + return coverBehavior.createWindow(buildContext); + } + + protected static final int COVER_WINDOW_ID_START = 1; + + @Override + public void addCoverTabs(ModularWindow.Builder builder, UIBuildContext buildContext) { + final int COVER_TAB_LEFT = -16, + COVER_TAB_TOP = 1, + COVER_TAB_HEIGHT = 20, + COVER_TAB_WIDTH = 18, + COVER_TAB_SPACING = 2, + ICON_SIZE = 16; + final boolean flipHorizontally = GT_Mod.gregtechproxy.mCoverTabsFlipped; + + final Column columnWidget = new Column(); + builder.widget(columnWidget); + final int xPos = flipHorizontally ? (getGUIWidth() - COVER_TAB_LEFT - COVER_TAB_WIDTH) : COVER_TAB_LEFT; + if (GT_Mod.gregtechproxy.mCoverTabsVisible) { + columnWidget.setPos(xPos, COVER_TAB_TOP).setEnabled(widget -> ((Column) widget) + .getChildren().stream().anyMatch(Widget::isEnabled)); + } else { + columnWidget.setEnabled(false); + } + columnWidget.setAlignment(MainAxisAlignment.SPACE_BETWEEN).setSpace(COVER_TAB_SPACING); + + for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) { + final byte side = (byte) direction.ordinal(); + buildContext.addSyncedWindow(side + COVER_WINDOW_ID_START, player -> createCoverWindow(player, side)); + columnWidget.addChild(new MultiChildWidget() + .addChild( + new ButtonWidget() { + @Override + public IDrawable[] getBackground() { + final List backgrounds = new ArrayList<>(); + final GUITextureSet tabIconSet = getGUITextureSet(); + + if (getCoverBehaviorAtSideNew(side).hasCoverGUI()) { + if (isHovering()) { + backgrounds.add( + flipHorizontally + ? tabIconSet.getCoverTabHighlightFlipped() + : tabIconSet.getCoverTabHighlight()); + } else { + backgrounds.add( + flipHorizontally + ? tabIconSet.getCoverTabNormalFlipped() + : tabIconSet.getCoverTabNormal()); + } + } else { + backgrounds.add( + flipHorizontally + ? tabIconSet.getCoverTabDisabledFlipped() + : tabIconSet.getCoverTabDisabled()); + } + return backgrounds.toArray(new IDrawable[] {}); + } + }.setOnClick((clickData, widget) -> onTabClicked(clickData, widget, side)) + .dynamicTooltip(() -> getCoverTabTooltip(side)) + .setSize(COVER_TAB_WIDTH, COVER_TAB_HEIGHT)) + .addChild(new ItemDrawable(() -> { + return getCoverItemAtSide(side); + }) + .asWidget() + .setPos( + (COVER_TAB_WIDTH - ICON_SIZE) / 2 + (flipHorizontally ? -1 : 1), + (COVER_TAB_HEIGHT - ICON_SIZE) / 2)) + .setEnabled(widget -> { + return getCoverItemAtSide(side) != null; + })); + } + } + + @SideOnly(Side.CLIENT) + protected List getCoverTabTooltip(byte side) { + final String[] SIDE_TOOLTIPS = new String[] { + "GT5U.interface.coverTabs.down", + "GT5U.interface.coverTabs.up", + "GT5U.interface.coverTabs.north", + "GT5U.interface.coverTabs.south", + "GT5U.interface.coverTabs.west", + "GT5U.interface.coverTabs.east" + }; + final ItemStack coverItem = getCoverItemAtSide(side); + if (coverItem == null) return Collections.emptyList(); + boolean coverHasGUI = getCoverBehaviorAtSideNew(side).hasCoverGUI(); + + //noinspection unchecked + List tooltip = coverItem.getTooltip(Minecraft.getMinecraft().thePlayer, true); + for (int i = 0; i < tooltip.size(); i++) { + if (i == 0) { + tooltip.set( + 0, + (coverHasGUI ? EnumChatFormatting.UNDERLINE : EnumChatFormatting.DARK_GRAY) + + StatCollector.translateToLocal(SIDE_TOOLTIPS[side]) + + (coverHasGUI ? EnumChatFormatting.RESET + ": " : ": " + EnumChatFormatting.RESET) + + tooltip.get(0)); + } else { + tooltip.set(i, EnumChatFormatting.GRAY + tooltip.get(i)); + } + } + return tooltip; + } + + protected void onTabClicked(Widget.ClickData clickData, Widget widget, byte side) { + if (isClientSide()) return; + + final GT_CoverBehaviorBase coverBehavior = getCoverBehaviorAtSideNew(side); + if (coverBehavior.useModularUI()) { + widget.getContext().openSyncedWindow(side + COVER_WINDOW_ID_START); + } else { + final GT_Packet_TileEntityCoverGUI packet = new GT_Packet_TileEntityCoverGUI( + getXCoord(), + getYCoord(), + getZCoord(), + side, + getCoverIDAtSide(side), + getComplexCoverDataAtSide(side), + getWorld().provider.dimensionId, + widget.getContext().getPlayer().getEntityId(), + 0); + GT_Values.NW.sendToPlayer( + packet, (EntityPlayerMP) widget.getContext().getPlayer()); + } + } } diff --git a/src/main/java/gregtech/api/metatileentity/MetaPipeEntity.java b/src/main/java/gregtech/api/metatileentity/MetaPipeEntity.java index 105ec073ec..ff9ac7517d 100644 --- a/src/main/java/gregtech/api/metatileentity/MetaPipeEntity.java +++ b/src/main/java/gregtech/api/metatileentity/MetaPipeEntity.java @@ -8,6 +8,7 @@ import cpw.mods.fml.relauncher.SideOnly; import gnu.trove.list.TIntList; import gnu.trove.list.array.TIntArrayList; import gregtech.api.GregTech_API; +import gregtech.api.enums.Dyes; import gregtech.api.interfaces.metatileentity.IConnectable; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IColoredTileEntity; @@ -1047,4 +1048,17 @@ public abstract class MetaPipeEntity implements IMetaTileEntity, IConnectable { } public void reloadLocks() {} + + @Override + public int getGUIColorization() { + Dyes dye = Dyes.dyeWhite; + if (GregTech_API.sColoredGUI) { + if (GregTech_API.sMachineMetalGUI) { + dye = Dyes.MACHINE_METAL; + } else if (getBaseMetaTileEntity() != null) { + dye = Dyes.getDyeFromIndex(getBaseMetaTileEntity().getColorization()); + } + } + return GT_Util.getRGBInt(dye.getRGBA()); + } } diff --git a/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java index 5c8f1c33bb..586b52fd99 100644 --- a/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java @@ -6,14 +6,19 @@ import appeng.api.networking.energy.IEnergyGrid; import appeng.api.networking.pathing.IPathingGrid; import appeng.api.util.AECableType; import appeng.me.helpers.AENetworkProxy; +import com.gtnewhorizons.modularui.api.forge.ItemStackHandler; import cpw.mods.fml.common.Optional; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import gnu.trove.list.TIntList; import gnu.trove.list.array.TIntArrayList; import gregtech.api.GregTech_API; +import gregtech.api.enums.Dyes; import gregtech.api.enums.SoundResource; -import gregtech.api.interfaces.metatileentity.IConfigurationCircuitSupport; +import gregtech.api.enums.SteamVariant; +import gregtech.api.gui.GT_GUIColorOverride; +import gregtech.api.gui.modularui.GUITextureSet; +import gregtech.api.interfaces.IConfigurationCircuitSupport; import gregtech.api.interfaces.metatileentity.IMachineCallback; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; @@ -23,12 +28,15 @@ import gregtech.api.util.GT_Config; import gregtech.api.util.GT_LanguageManager; import gregtech.api.util.GT_Log; import gregtech.api.util.GT_ModHandler; +import gregtech.api.util.GT_TooltipDataCache; +import gregtech.api.util.GT_Util; import gregtech.api.util.GT_Utility; import gregtech.common.GT_Client; import java.io.File; import java.util.ArrayList; import java.util.List; import java.util.Locale; +import java.util.function.Supplier; import mcp.mobius.waila.api.IWailaConfigHandler; import mcp.mobius.waila.api.IWailaDataAccessor; import net.minecraft.block.Block; @@ -71,6 +79,19 @@ public abstract class MetaTileEntity implements IMetaTileEntity, IMachineCallbac */ public final ItemStack[] mInventory; + /** + * Inventory wrapper for ModularUI + */ + public final ItemStackHandler inventoryHandler; + + protected GT_GUIColorOverride colorOverride; + protected GT_TooltipDataCache mTooltipCache = new GT_TooltipDataCache(); + + @Override + public ItemStackHandler getInventoryHandler() { + return inventoryHandler; + } + public boolean doTickProfilingInThisTick = true; private MetaTileEntity mCallBackTile; @@ -107,6 +128,7 @@ public abstract class MetaTileEntity implements IMetaTileEntity, IMachineCallbac getBaseMetaTileEntity().setMetaTileID((short) aID); GT_LanguageManager.addStringLocalization("gt.blockmachines." + mName + ".name", aRegionalName); mInventory = new ItemStack[aInvSlotCount]; + inventoryHandler = new ItemStackHandler(mInventory); } /** @@ -115,6 +137,9 @@ public abstract class MetaTileEntity implements IMetaTileEntity, IMachineCallbac public MetaTileEntity(String aName, int aInvSlotCount) { mInventory = new ItemStack[aInvSlotCount]; mName = aName; + inventoryHandler = new ItemStackHandler(mInventory); + colorOverride = new GT_GUIColorOverride( + getGUITextureSet().getMainBackground().location.getResourcePath()); } /** @@ -151,6 +176,7 @@ public abstract class MetaTileEntity implements IMetaTileEntity, IMachineCallbac getBaseMetaTileEntity().getMetaTileID()); } + @Override public String getLocalName() { return GT_LanguageManager.getTranslation("gt.blockmachines." + mName + ".name"); } @@ -395,6 +421,14 @@ public abstract class MetaTileEntity implements IMetaTileEntity, IMachineCallbac return false; } + /** + * @return what type of texture does this machine use for GUI, + * i.e. Bronze, Steel, or Primitive + */ + public SteamVariant getSteamVariant() { + return SteamVariant.NONE; + } + /** * @return true if this Device emits Energy at all */ @@ -991,11 +1025,19 @@ public abstract class MetaTileEntity implements IMetaTileEntity, IMachineCallbac // } + /** + * @deprecated Use ModularUI + */ + @Deprecated @Override public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { return null; } + /** + * @deprecated Use ModularUI + */ + @Deprecated @Override public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { return null; @@ -1048,64 +1090,32 @@ public abstract class MetaTileEntity implements IMetaTileEntity, IMachineCallbac @Override public void doExplosion(long aExplosionPower) { - float tStrength = aExplosionPower < V[0] - ? 1.0F - : aExplosionPower < V[1] - ? 2.0F - : aExplosionPower < V[2] - ? 3.0F - : aExplosionPower < V[3] - ? 4.0F - : aExplosionPower < V[4] - ? 5.0F - : aExplosionPower < V[4] * 2 - ? 6.0F - : aExplosionPower < V[5] - ? 7.0F - : aExplosionPower < V[6] - ? 8.0F - : aExplosionPower < V[7] - ? 9.0F - : aExplosionPower < V[8] - ? 10.0F - : aExplosionPower < V[8] * 2 - ? 11.0F - : aExplosionPower < V[9] - ? 12.0F - : aExplosionPower - < V[ - 10] - ? 13.0F - : aExplosionPower - < V[ - 11] - ? 14.0F - : aExplosionPower - < V[ - 12] - ? 15.0F - : aExplosionPower - < V[ - 12] - * 2 - ? 16.0F - : aExplosionPower - < V[ - 13] - ? 17.0F - : aExplosionPower - < V[ - 14] - ? 18.0F - : aExplosionPower - < V[ - 15] - ? 19.0F - : 20.0F; - int tX = getBaseMetaTileEntity().getXCoord(), - tY = getBaseMetaTileEntity().getYCoord(), - tZ = getBaseMetaTileEntity().getZCoord(); - World tWorld = getBaseMetaTileEntity().getWorld(); + // spotless:off + float tStrength = + aExplosionPower < V[0] ? 1.0F : + aExplosionPower < V[1] ? 2.0F : + aExplosionPower < V[2] ? 3.0F : + aExplosionPower < V[3] ? 4.0F : + aExplosionPower < V[4] ? 5.0F : + aExplosionPower < V[4] * 2 ? 6.0F : + aExplosionPower < V[5] ? 7.0F : + aExplosionPower < V[6] ? 8.0F : + aExplosionPower < V[7] ? 9.0F : + aExplosionPower < V[8] ? 10.0F : + aExplosionPower < V[8] * 2 ? 11.0F : + aExplosionPower < V[9] ? 12.0F : + aExplosionPower < V[10] ? 13.0F : + aExplosionPower < V[11] ? 14.0F : + aExplosionPower < V[12] ? 15.0F : + aExplosionPower < V[12] * 2 ? 16.0F : + aExplosionPower < V[13] ? 17.0F : + aExplosionPower < V[14] ? 18.0F : + aExplosionPower < V[15] ? 19.0F : 20.0F; + // spotless:on + final int tX = getBaseMetaTileEntity().getXCoord(); + final int tY = getBaseMetaTileEntity().getYCoord(); + final int tZ = getBaseMetaTileEntity().getZCoord(); + final World tWorld = getBaseMetaTileEntity().getWorld(); GT_Utility.sendSoundToPlayers(tWorld, SoundResource.IC2_MACHINES_MACHINE_OVERLOAD, 1.0F, -1, tX, tY, tZ); tWorld.setBlock(tX, tY, tZ, Blocks.air); if (GregTech_API.sMachineExplosions) @@ -1174,6 +1184,8 @@ public abstract class MetaTileEntity implements IMetaTileEntity, IMachineCallbac return false; } + // === AE2 compat === + @Optional.Method(modid = "appliedenergistics2") public AECableType getCableConnectionType(ForgeDirection forgeDirection) { return AECableType.NONE; @@ -1187,6 +1199,8 @@ public abstract class MetaTileEntity implements IMetaTileEntity, IMachineCallbac @Optional.Method(modid = "appliedenergistics2") public void gridChanged() {} + // === Waila compat === + @Override public void getWailaBody( ItemStack itemStack, List currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config) { @@ -1218,4 +1232,38 @@ public abstract class MetaTileEntity implements IMetaTileEntity, IMachineCallbac } return ""; } + + @Override + public GUITextureSet getGUITextureSet() { + return GUITextureSet.DEFAULT; + } + + @Override + public int getGUIColorization() { + Dyes dye = Dyes.dyeWhite; + if (this.colorOverride.sLoaded()) { + if (this.colorOverride.sGuiTintingEnabled() && getBaseMetaTileEntity() != null) { + dye = Dyes.getDyeFromIndex(getBaseMetaTileEntity().getColorization()); + return this.colorOverride.getGuiTintOrDefault(dye.mName, GT_Util.getRGBInt(dye.getRGBA())); + } + } else if (GregTech_API.sColoredGUI) { + if (GregTech_API.sMachineMetalGUI) { + dye = Dyes.MACHINE_METAL; + } else if (getBaseMetaTileEntity() != null) { + dye = Dyes.getDyeFromIndex(getBaseMetaTileEntity().getColorization()); + } + } + return GT_Util.getRGBInt(dye.getRGBA()); + } + + @Override + public int getTextColorOrDefault(String textType, int defaultColor) { + return colorOverride.getTextColorOrDefault(textType, defaultColor); + } + + protected Supplier COLOR_TITLE = () -> getTextColorOrDefault("title", 0x404040); + protected Supplier COLOR_TITLE_WHITE = () -> getTextColorOrDefault("title_white", 0xfafaff); + protected Supplier COLOR_TEXT_WHITE = () -> getTextColorOrDefault("text_white", 0xfafaff); + protected Supplier COLOR_TEXT_GRAY = () -> getTextColorOrDefault("text_gray", 0x404040); + protected Supplier COLOR_TEXT_RED = () -> getTextColorOrDefault("text_red", 0xff0000); } diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicBatteryBuffer.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicBatteryBuffer.java index 67c3c672ae..45c07cf4c3 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicBatteryBuffer.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicBatteryBuffer.java @@ -2,17 +2,19 @@ package gregtech.api.metatileentity.implementations; import static gregtech.api.enums.GT_Values.V; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; import gregtech.api.enums.Textures; -import gregtech.api.gui.*; +import gregtech.api.gui.modularui.GT_UIInfos; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.modularui.IAddUIWidgets; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.items.GT_MetaBase_Item; import gregtech.api.util.GT_ModHandler; import gregtech.api.util.GT_Utility; import ic2.api.item.IElectricItem; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumChatFormatting; @@ -23,7 +25,8 @@ import net.minecraft.util.EnumChatFormatting; * This is the main construct for my Basic Machines such as the Automatic Extractor * Extend this class to make a simple Machine */ -public class GT_MetaTileEntity_BasicBatteryBuffer extends GT_MetaTileEntity_TieredMachineBlock { +public class GT_MetaTileEntity_BasicBatteryBuffer extends GT_MetaTileEntity_TieredMachineBlock + implements IAddUIWidgets { public boolean mCharge = false, mDecharge = false; public int mBatteryCount = 0, mChargeableCount = 0; private long count = 0; @@ -208,41 +211,10 @@ public class GT_MetaTileEntity_BasicBatteryBuffer extends GT_MetaTileEntity_Tier @Override public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { - if (aBaseMetaTileEntity.isClientSide()) return true; - aBaseMetaTileEntity.openGUI(aPlayer); + GT_UIInfos.openGTTileEntityUI(aBaseMetaTileEntity, aPlayer); return true; } - @Override - public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - switch (mInventory.length) { - case 1: - return new GT_Container_1by1(aPlayerInventory, aBaseMetaTileEntity); - case 4: - return new GT_Container_2by2(aPlayerInventory, aBaseMetaTileEntity); - case 9: - return new GT_Container_3by3(aPlayerInventory, aBaseMetaTileEntity); - case 16: - return new GT_Container_4by4(aPlayerInventory, aBaseMetaTileEntity); - } - return new GT_Container_1by1(aPlayerInventory, aBaseMetaTileEntity); - } - - @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - switch (mInventory.length) { - case 1: - return new GT_GUIContainer_1by1(aPlayerInventory, aBaseMetaTileEntity, getLocalName()); - case 4: - return new GT_GUIContainer_2by2(aPlayerInventory, aBaseMetaTileEntity, getLocalName()); - case 9: - return new GT_GUIContainer_3by3(aPlayerInventory, aBaseMetaTileEntity, getLocalName()); - case 16: - return new GT_GUIContainer_4by4(aPlayerInventory, aBaseMetaTileEntity, getLocalName()); - } - return new GT_GUIContainer_1by1(aPlayerInventory, aBaseMetaTileEntity, getLocalName()); - } - @Override public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { if (aBaseMetaTileEntity.isServerSide()) { @@ -357,4 +329,27 @@ public class GT_MetaTileEntity_BasicBatteryBuffer extends GT_MetaTileEntity_Tier public boolean isGivingInformation() { return true; } + + @Override + public boolean useModularUI() { + return true; + } + + @Override + public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { + switch (mInventory.length) { + case 4: + getBaseMetaTileEntity().add2by2Slots(builder); + break; + case 9: + getBaseMetaTileEntity().add3by3Slots(builder); + break; + case 16: + getBaseMetaTileEntity().add4by4Slots(builder); + break; + default: + getBaseMetaTileEntity().add1by1Slot(builder); + break; + } + } } diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicGenerator.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicGenerator.java index 091c364b4f..ca5f255302 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicGenerator.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicGenerator.java