diff --git a/dependencies.gradle b/dependencies.gradle index 9091c5c2..17101af0 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -35,12 +35,12 @@ */ dependencies { api('com.github.GTNewHorizons:NotEnoughItems:2.8.33-GTNH:dev') - api('com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-739-GTNH:dev') + api('com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-754-GTNH:dev') api('curse.maven:cofh-core-69162:2388751') api('com.github.GTNewHorizons:waila:1.9.7:dev') api("com.github.GTNewHorizons:GTNHLib:0.8.0:dev") - implementation("com.github.GTNewHorizons:WirelessCraftingTerminal:1.12.7:dev") { + implementation("com.github.GTNewHorizons:WirelessCraftingTerminal:1.12.10:dev") { exclude group: 'com.github.GTNewHorizons', module: 'Applied-Energistics-2-Unofficial' } diff --git a/repositories.gradle b/repositories.gradle index c227b16e..033d07fd 100644 --- a/repositories.gradle +++ b/repositories.gradle @@ -1,4 +1,5 @@ // Add any additional repositories for your dependencies here repositories { + mavenLocal() } diff --git a/src/main/java/com/glodblock/github/FluidCraft.java b/src/main/java/com/glodblock/github/FluidCraft.java index 291eaf4b..706ce9da 100644 --- a/src/main/java/com/glodblock/github/FluidCraft.java +++ b/src/main/java/com/glodblock/github/FluidCraft.java @@ -3,8 +3,6 @@ package com.glodblock.github; import net.minecraft.util.ResourceLocation; import com.glodblock.github.common.Config; -import com.glodblock.github.common.storage.FluidCellHandler; -import com.glodblock.github.crossmod.extracells.EC2Replacer; import com.glodblock.github.crossmod.opencomputers.OCDriverInit; import com.glodblock.github.crossmod.waila.WailaInit; import com.glodblock.github.inventory.InventoryHandler; @@ -12,21 +10,15 @@ import com.glodblock.github.loader.CalculatorV2PluginLoader; import com.glodblock.github.loader.ChannelLoader; import com.glodblock.github.loader.ItemAndBlockHolder; import com.glodblock.github.loader.RecipeLoader; -import com.glodblock.github.loader.filter.FluidFilter; -import com.glodblock.github.network.SPacketMEUpdateBuffer; import com.glodblock.github.proxy.CommonProxy; import com.glodblock.github.util.ModAndClassUtil; -import appeng.api.AEApi; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.SidedProxy; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLLoadCompleteEvent; -import cpw.mods.fml.common.event.FMLMissingMappingsEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; -import cpw.mods.fml.common.event.FMLServerStartingEvent; -import cpw.mods.fml.common.event.FMLServerStoppedEvent; import cpw.mods.fml.common.network.NetworkRegistry; @Mod( @@ -70,7 +62,6 @@ public class FluidCraft { public static void postInit(FMLPostInitializationEvent event) { NetworkRegistry.INSTANCE.registerGuiHandler(FluidCraft.INSTANCE, new InventoryHandler()); - AEApi.instance().registries().cell().addCellHandler(new FluidCellHandler()); ItemAndBlockHolder.loadSetting(); if (!Config.removeRecipe) { @@ -86,9 +77,6 @@ public class FluidCraft { if (ModAndClassUtil.isV2) { CalculatorV2PluginLoader.installCalculatorV2Plugins(); } - if (ModAndClassUtil.isTypeFilter) { - AEApi.instance().registries().itemDisplay().addItemFilter(FluidFilter::filter); - } proxy.postInit(event); } @@ -98,23 +86,6 @@ public class FluidCraft { proxy.onLoadComplete(event); } - @Mod.EventHandler - public void onServerStart(FMLServerStartingEvent event) { - SPacketMEUpdateBuffer.start(); - } - - @Mod.EventHandler - public void onServerStop(FMLServerStoppedEvent event) { - SPacketMEUpdateBuffer.stop(); - } - - @Mod.EventHandler - public void missingMappings(FMLMissingMappingsEvent event) { - if (!ModAndClassUtil.EC2 && Config.replaceEC2) { - EC2Replacer.replaceExtraCells(event); - } - } - public static ResourceLocation resource(String path) { return new ResourceLocation(MODID, path); } diff --git a/src/main/java/com/glodblock/github/api/registries/ILevelTerminalRegistry.java b/src/main/java/com/glodblock/github/api/registries/ILevelTerminalRegistry.java index d00c4d16..19d2421d 100644 --- a/src/main/java/com/glodblock/github/api/registries/ILevelTerminalRegistry.java +++ b/src/main/java/com/glodblock/github/api/registries/ILevelTerminalRegistry.java @@ -2,6 +2,7 @@ package com.glodblock.github.api.registries; import java.util.Set; +import appeng.api.features.ILevelViewable; import appeng.api.networking.IGridHost; public interface ILevelTerminalRegistry { diff --git a/src/main/java/com/glodblock/github/api/registries/ILevelViewable.java b/src/main/java/com/glodblock/github/api/registries/ILevelViewable.java deleted file mode 100644 index 21ab6f50..00000000 --- a/src/main/java/com/glodblock/github/api/registries/ILevelViewable.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.glodblock.github.api.registries; - -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; - -import com.glodblock.github.api.ISide; - -import appeng.api.implementations.tiles.ISegmentedInventory; -import appeng.api.networking.IGridHost; -import appeng.api.util.DimensionalCoord; -import appeng.helpers.ICustomNameObject; - -public interface ILevelViewable extends IGridHost, ISide, ISegmentedInventory, ICustomNameObject { - - DimensionalCoord getLocation(); - - TileEntity getTile(); - - @Deprecated - default long getSortValue() { - TileEntity te = getTile(); - return ((long) te.zCoord << 24) ^ ((long) te.xCoord << 8) ^ te.yCoord; - } - - @Deprecated - default boolean shouldDisplay() { - return true; - } - - /** - * Number of rows to expect. This is used with {@link #rowSize()} to determine how to render the slots. - */ - default int rows() { - return 1; - }; - - /** - * Number of slots per row. - */ - default int rowSize() { - return 1; - }; - - @Deprecated - default ItemStack getSelfItemStack() { - return null; - } - - /** - * "Target" Display representation - */ - @Deprecated - default ItemStack getDisplayItemStack() { - return null; - } - - LevelItemInfo[] getLevelItemInfoList(); - -} diff --git a/src/main/java/com/glodblock/github/api/registries/ILevelViewableAdapter.java b/src/main/java/com/glodblock/github/api/registries/ILevelViewableAdapter.java index 890b3f77..f71c8d9e 100644 --- a/src/main/java/com/glodblock/github/api/registries/ILevelViewableAdapter.java +++ b/src/main/java/com/glodblock/github/api/registries/ILevelViewableAdapter.java @@ -1,5 +1,6 @@ package com.glodblock.github.api.registries; +import appeng.api.features.ILevelViewable; import appeng.api.networking.IGridHost; public interface ILevelViewableAdapter extends ILevelViewable { diff --git a/src/main/java/com/glodblock/github/api/registries/LevelItemInfo.java b/src/main/java/com/glodblock/github/api/registries/LevelItemInfo.java deleted file mode 100644 index 82dc68df..00000000 --- a/src/main/java/com/glodblock/github/api/registries/LevelItemInfo.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.glodblock.github.api.registries; - -import net.minecraft.item.ItemStack; - -import org.jetbrains.annotations.NotNull; - -public class LevelItemInfo { - - public ItemStack stack; - public long quantity; - public long batchSize; - public LevelState state; - - public LevelItemInfo(@NotNull ItemStack stack, long quantity, long batchSize, LevelState state) { - this.stack = stack; - this.quantity = quantity; - this.batchSize = batchSize; - this.state = state; - } -} diff --git a/src/main/java/com/glodblock/github/api/registries/LevelState.java b/src/main/java/com/glodblock/github/api/registries/LevelState.java deleted file mode 100644 index 9041a84e..00000000 --- a/src/main/java/com/glodblock/github/api/registries/LevelState.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.glodblock.github.api.registries; - -public enum LevelState { - None, - Idle, - Craft, - Export, - Error, - NotFound, - CantCraft -} diff --git a/src/main/java/com/glodblock/github/client/FluidInterfaceButtons.java b/src/main/java/com/glodblock/github/client/FluidInterfaceButtons.java new file mode 100644 index 00000000..1ffac6da --- /dev/null +++ b/src/main/java/com/glodblock/github/client/FluidInterfaceButtons.java @@ -0,0 +1,98 @@ +package com.glodblock.github.client; + +import java.util.List; + +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.renderer.entity.RenderItem; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.StatCollector; + +import org.lwjgl.input.Mouse; + +import com.glodblock.github.FluidCraft; +import com.glodblock.github.loader.ItemAndBlockHolder; +import com.glodblock.github.network.CPacketCustomButtonUpdate; +import com.glodblock.github.network.CPacketSwitchGuis; + +import appeng.api.config.Settings; +import appeng.api.config.SidelessMode; +import appeng.client.gui.widgets.GuiImgButton; +import appeng.client.gui.widgets.GuiTabButton; +import appeng.core.sync.network.NetworkHandler; +import appeng.core.sync.packets.PacketConfigButton; +import appeng.helpers.ICustomButtonDataObject; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import io.netty.buffer.ByteBuf; + +public class FluidInterfaceButtons implements ICustomButtonDataObject { + + private GuiImgButton sidelessMode; + private GuiTabButton switcher; + private final boolean fullBlock; + public SidelessMode sidelessSate; + + public FluidInterfaceButtons(final boolean fullBlock) { + this.fullBlock = fullBlock; + } + + @SideOnly(Side.CLIENT) + @Override + public void initCustomButtons(int guiLeft, int guiTop, int xSize, int ySize, int xOffset, int yOffset, + List buttonList) { + if (fullBlock) { + this.sidelessMode = new GuiImgButton( + guiLeft - 18, + guiTop + yOffset, + Settings.SIDELESS_MODE, + SidelessMode.SIDELESS); + buttonList.add(this.sidelessMode); + } + + this.switcher = new GuiTabButton( + guiLeft + 132, + guiTop, + !fullBlock ? ItemAndBlockHolder.FLUID_INTERFACE.stack() : ItemAndBlockHolder.INTERFACE.stack(), + StatCollector.translateToLocal("ae2fc.tooltip.switch_fluid_interface"), + RenderItem.getInstance()); + buttonList.add(this.switcher); + + FluidCraft.proxy.netHandler.sendToServer(new CPacketCustomButtonUpdate()); + } + + @SideOnly(Side.CLIENT) + @Override + public boolean actionPerformedCustomButtons(final GuiButton btn) { + if (btn == this.switcher) { + FluidCraft.proxy.netHandler.sendToServer(new CPacketSwitchGuis()); + return true; + } else if (fullBlock && btn == this.sidelessMode) { + final boolean backwards = Mouse.isButtonDown(1); + NetworkHandler.instance.sendToServer(new PacketConfigButton(this.sidelessMode.getSetting(), backwards)); + FluidCraft.proxy.netHandler.sendToServer(new CPacketCustomButtonUpdate()); + return true; + } + + return false; + } + + @Override + public void readData(NBTTagCompound tag) {} + + @Override + public void writeData(NBTTagCompound tag) {} + + @Override + public void readByte(ByteBuf buf) { + this.sidelessMode.set(SidelessMode.values()[buf.readInt()]); + } + + @Override + public void writeByte(ByteBuf buf) { + buf.writeInt(this.sidelessSate.ordinal()); + } + + public void setSidelessMode(SidelessMode sm) { + this.sidelessSate = sm; + } +} diff --git a/src/main/java/com/glodblock/github/client/UltraTerminalButtons.java b/src/main/java/com/glodblock/github/client/UltraTerminalButtons.java new file mode 100644 index 00000000..f728d436 --- /dev/null +++ b/src/main/java/com/glodblock/github/client/UltraTerminalButtons.java @@ -0,0 +1,232 @@ +package com.glodblock.github.client; + +import static appeng.util.Platform.nextEnum; +import static com.glodblock.github.common.item.ItemWirelessUltraTerminal.MODE; +import static com.glodblock.github.inventory.item.WirelessMagnet.modeKey; + +import java.util.List; + +import net.minecraft.client.gui.GuiButton; +import net.minecraft.nbt.NBTTagCompound; + +import com.glodblock.github.FluidCraft; +import com.glodblock.github.client.gui.GuiFCImgButton; +import com.glodblock.github.inventory.item.WirelessMagnet; +import com.glodblock.github.network.CPacketFluidPatternTermBtns; +import com.glodblock.github.network.CPacketSwitchGuis; +import com.glodblock.github.util.UltraTerminalModes; + +import appeng.helpers.ICustomButtonDataObject; +import appeng.util.Platform; +import io.netty.buffer.ByteBuf; + +public class UltraTerminalButtons implements ICustomButtonDataObject { + + public static String restockItems = "restock"; + + private GuiFCImgButton CraftingTerminal; + private GuiFCImgButton PatternTerminal; + private GuiFCImgButton InterfaceTerminal; + private GuiFCImgButton LevelTerminal; + private GuiFCImgButton PatternTerminalEx; + + private GuiFCImgButton magnetOff; + private GuiFCImgButton magnetInv; + private GuiFCImgButton magnetME; + + private GuiFCImgButton magnetFilter; + + private GuiFCImgButton restockEnableBtn; + private GuiFCImgButton restockDisableBtn; + + private WirelessMagnet.Mode magnetMode; + private boolean reStock; + public UltraTerminalModes terminalMode; + + private int offset; + + public void initCustomButtons(int guiLeft, int guiTop, int xSize, int ySize, int xOffset, int yOffset, + List buttonList) { + this.offset = yOffset; + buttonList.add( + this.magnetOff = new GuiFCImgButton(guiLeft + xSize - 17, guiTop + ySize - 65, "MAGNET_CARD", "OFF")); + buttonList.add( + this.magnetInv = new GuiFCImgButton(guiLeft + xSize - 17, guiTop + ySize - 65, "MAGNET_CARD", "INV")); + buttonList.add( + this.magnetME = new GuiFCImgButton(guiLeft + xSize - 17, guiTop + ySize - 65, "MAGNET_CARD", "ME")); + + buttonList.add( + this.magnetFilter = new GuiFCImgButton( + guiLeft + xSize - 17, + guiTop + ySize - 45, + "MAGNET_CARD", + "FILTER")); + buttonList.add( + this.restockEnableBtn = new GuiFCImgButton( + guiLeft + xSize - 17, + guiTop + ySize - 25, + "RESTOCK", + "ENABLE")); + + buttonList.add( + this.restockDisableBtn = new GuiFCImgButton( + guiLeft + xSize - 17, + guiTop + ySize - 25, + "RESTOCK", + "DISABLE")); + + buttonList.add(this.CraftingTerminal = new GuiFCImgButton(guiLeft - 18, yOffset, "CRAFT_TEM", "YES")); + + buttonList.add(this.PatternTerminal = new GuiFCImgButton(guiLeft - 18, yOffset, "PATTERN_TEM", "YES")); + + buttonList.add(this.PatternTerminalEx = new GuiFCImgButton(guiLeft - 18, yOffset, "PATTERN_EX_TEM", "YES")); + + buttonList.add(this.InterfaceTerminal = new GuiFCImgButton(guiLeft - 18, yOffset, "INTERFACE_TEM", "YES")); + + buttonList.add(this.LevelTerminal = new GuiFCImgButton(guiLeft - 18, yOffset, "LEVEL_TEM", "YES")); + + toggleSwitchButtons(); + toggleMagnetButtonsVisibility(); + toggleRestockVisibility(); + } + + @Override + public boolean actionPerformedCustomButtons(final GuiButton btn) { + if (btn instanceof GuiFCImgButton) { + if (btn == this.CraftingTerminal) { + FluidCraft.proxy.netHandler.sendToServer(new CPacketSwitchGuis(UltraTerminalModes.CRAFTING, true)); + } else if (btn == this.PatternTerminal) { + FluidCraft.proxy.netHandler.sendToServer(new CPacketSwitchGuis(UltraTerminalModes.PATTERN, true)); + } else if (btn == this.InterfaceTerminal) { + FluidCraft.proxy.netHandler.sendToServer(new CPacketSwitchGuis(UltraTerminalModes.INTERFACE, true)); + } else if (btn == this.LevelTerminal) { + FluidCraft.proxy.netHandler.sendToServer(new CPacketSwitchGuis(UltraTerminalModes.LEVEL, true)); + } else if (btn == this.PatternTerminalEx) { + FluidCraft.proxy.netHandler.sendToServer(new CPacketSwitchGuis(UltraTerminalModes.PATTERN_EX, true)); + } + + if (btn == this.magnetOff || btn == this.magnetME || btn == this.magnetInv) { + FluidCraft.proxy.netHandler.sendToServer( + new CPacketFluidPatternTermBtns( + CPacketFluidPatternTermBtns.Command.MAGNET_MODE, + this.magnetMode.ordinal())); + } else if (btn == this.magnetFilter) FluidCraft.proxy.netHandler.sendToServer( + new CPacketFluidPatternTermBtns(CPacketFluidPatternTermBtns.Command.MAGNET_OPEN_FILTER, 0)); + else if (btn == this.restockDisableBtn || btn == this.restockEnableBtn) { + FluidCraft.proxy.netHandler + .sendToServer(new CPacketFluidPatternTermBtns(CPacketFluidPatternTermBtns.Command.RESTOCK, 1)); + } + + return true; + } + return false; + } + + public void toggleRestock() { + this.reStock = !this.reStock; + } + + public void toggleRestockVisibility() { + if (Platform.isClient()) { + if (this.reStock) { + this.restockEnableBtn.setVisibility(true); + this.restockDisableBtn.setVisibility(false); + } else { + this.restockEnableBtn.setVisibility(false); + this.restockDisableBtn.setVisibility(true); + } + } + } + + public void toggleMagnetMode() { + this.magnetMode = nextEnum(this.magnetMode); + } + + public void toggleMagnetButtonsVisibility() { + switch (this.magnetMode) { + case Off -> { + this.magnetME.setVisibility(false); + this.magnetInv.setVisibility(false); + this.magnetOff.setVisibility(true); + } + case ME -> { + this.magnetME.setVisibility(true); + this.magnetInv.setVisibility(false); + this.magnetOff.setVisibility(false); + } + case Inv -> { + this.magnetME.setVisibility(false); + this.magnetInv.setVisibility(true); + this.magnetOff.setVisibility(false); + } + } + } + + public void toggleSwitchButtons() { + int offset = this.offset; + + CraftingTerminal.setVisibility(false); + PatternTerminal.setVisibility(false); + InterfaceTerminal.setVisibility(false); + LevelTerminal.setVisibility(false); + PatternTerminalEx.setVisibility(false); + + if (this.terminalMode != UltraTerminalModes.CRAFTING) { + this.CraftingTerminal.setVisibility(true); + this.CraftingTerminal.yPosition = offset; + offset += 20; + } + if (this.terminalMode != UltraTerminalModes.PATTERN) { + this.PatternTerminal.setVisibility(true); + this.PatternTerminal.yPosition = offset; + offset += 20; + } + if (this.terminalMode != UltraTerminalModes.PATTERN_EX) { + this.PatternTerminalEx.setVisibility(true); + this.PatternTerminalEx.yPosition = offset; + offset += 20; + } + if (this.terminalMode != UltraTerminalModes.INTERFACE) { + this.InterfaceTerminal.setVisibility(true); + this.InterfaceTerminal.yPosition = offset; + offset += 20; + } + if (this.terminalMode != UltraTerminalModes.LEVEL) { + this.LevelTerminal.setVisibility(true); + this.LevelTerminal.yPosition = offset; + offset += 20; + } + } + + @Override + public void readData(NBTTagCompound tag) { + this.reStock = tag.getBoolean(restockItems); + this.magnetMode = WirelessMagnet.Mode.values()[tag.getInteger(modeKey)]; + this.terminalMode = UltraTerminalModes.values()[tag.getInteger(MODE)]; + } + + @Override + public void writeData(NBTTagCompound tag) { + tag.setBoolean(restockItems, this.reStock); + tag.setInteger(modeKey, this.magnetMode.ordinal()); + tag.setInteger(MODE, this.terminalMode.ordinal()); + } + + @Override + public void readByte(ByteBuf buf) { + this.reStock = buf.readBoolean(); + this.magnetMode = WirelessMagnet.Mode.values()[buf.readInt()]; + this.terminalMode = UltraTerminalModes.values()[buf.readInt()]; + + toggleMagnetButtonsVisibility(); + toggleRestockVisibility(); + toggleSwitchButtons(); + } + + @Override + public void writeByte(ByteBuf buf) { + buf.writeBoolean(this.reStock); + buf.writeInt(this.magnetMode.ordinal()); + buf.writeInt(this.terminalMode.ordinal()); + } +} diff --git a/src/main/java/com/glodblock/github/client/gui/GuiCraftingStatus.java b/src/main/java/com/glodblock/github/client/gui/GuiCraftingStatus.java deleted file mode 100644 index d1442bcf..00000000 --- a/src/main/java/com/glodblock/github/client/gui/GuiCraftingStatus.java +++ /dev/null @@ -1,94 +0,0 @@ -package com.glodblock.github.client.gui; - -import net.minecraft.client.gui.GuiButton; -import net.minecraft.entity.player.InventoryPlayer; - -import com.glodblock.github.FluidCraft; -import com.glodblock.github.common.item.ItemWirelessUltraTerminal; -import com.glodblock.github.common.parts.PartFluidPatternTerminal; -import com.glodblock.github.common.parts.PartFluidPatternTerminalEx; -import com.glodblock.github.common.parts.PartFluidTerminal; -import com.glodblock.github.common.parts.PartLevelTerminal; -import com.glodblock.github.inventory.InventoryHandler; -import com.glodblock.github.inventory.gui.GuiType; -import com.glodblock.github.inventory.item.IWirelessTerminal; -import com.glodblock.github.inventory.item.WirelessFluidTerminalInventory; -import com.glodblock.github.inventory.item.WirelessInterfaceTerminalInventory; -import com.glodblock.github.inventory.item.WirelessLevelTerminalInventory; -import com.glodblock.github.inventory.item.WirelessPatternTerminalInventory; -import com.glodblock.github.loader.ItemAndBlockHolder; -import com.glodblock.github.network.CPacketInventoryAction; -import com.glodblock.github.util.Ae2ReflectClient; - -import appeng.api.storage.ITerminalHost; -import appeng.api.storage.data.IAEItemStack; -import appeng.container.AEBaseContainer; -import appeng.helpers.InventoryAction; - -public class GuiCraftingStatus extends appeng.client.gui.implementations.GuiCraftingStatus { - - private final ITerminalHost host; - - public GuiCraftingStatus(InventoryPlayer inventoryPlayer, ITerminalHost te) { - super(inventoryPlayer, te); - host = te; - } - - @Override - public void initGui() { - if (host instanceof PartFluidPatternTerminal) this.myIcon = ItemAndBlockHolder.FLUID_TERMINAL.stack(); - else if (host instanceof PartFluidPatternTerminalEx) this.myIcon = ItemAndBlockHolder.FLUID_TERMINAL_EX.stack(); - else if (host instanceof PartFluidTerminal) this.myIcon = ItemAndBlockHolder.FLUID_TERM.stack(); - else if (host instanceof PartLevelTerminal) this.myIcon = ItemAndBlockHolder.LEVEL_TERMINAL.stack(); - else if (host instanceof IWirelessTerminal terminal && terminal.isUniversal(host)) - this.myIcon = ItemAndBlockHolder.WIRELESS_ULTRA_TERM.stack(); - else if (host instanceof WirelessFluidTerminalInventory) - this.myIcon = ItemAndBlockHolder.WIRELESS_FLUID_TERM.stack(); - else if (host instanceof WirelessPatternTerminalInventory) - this.myIcon = ItemAndBlockHolder.WIRELESS_PATTERN_TERM.stack(); - else if (host instanceof WirelessInterfaceTerminalInventory) - this.myIcon = ItemAndBlockHolder.WIRELESS_INTERFACE_TERM.stack(); - else if (host instanceof WirelessLevelTerminalInventory) - this.myIcon = ItemAndBlockHolder.WIRELESS_LEVEL_TERM.stack(); - super.initGui(); - } - - @Override - protected void actionPerformed(final GuiButton btn) { - if (btn == originalGuiBtn) { - if (host instanceof PartFluidPatternTerminal) InventoryHandler.switchGui(GuiType.FLUID_PATTERN_TERMINAL); - else if (host instanceof PartFluidPatternTerminalEx) - InventoryHandler.switchGui(GuiType.FLUID_PATTERN_TERMINAL_EX); - else if (host instanceof PartFluidTerminal) InventoryHandler.switchGui(GuiType.FLUID_TERMINAL); - else if (host instanceof PartLevelTerminal) InventoryHandler.switchGui(GuiType.LEVEL_TERMINAL); - else if (host instanceof IWirelessTerminal terminal && terminal.isUniversal(host)) - InventoryHandler.switchGui(ItemWirelessUltraTerminal.readMode(terminal.getItemStack())); - else if (host instanceof WirelessFluidTerminalInventory) - InventoryHandler.switchGui(GuiType.WIRELESS_FLUID_TERMINAL); - else if (host instanceof WirelessPatternTerminalInventory) - InventoryHandler.switchGui(GuiType.WIRELESS_FLUID_PATTERN_TERMINAL); - else if (host instanceof WirelessInterfaceTerminalInventory) - InventoryHandler.switchGui(GuiType.WIRELESS_INTERFACE_TERMINAL); - else if (host instanceof WirelessLevelTerminalInventory) - InventoryHandler.switchGui(GuiType.WIRELESS_LEVEL_TERMINAL); - } else { - super.actionPerformed(btn); - } - } - - @Override - protected void mouseClicked(final int xCoord, final int yCoord, final int btn) { - IAEItemStack hoveredAEStack = getHoveredAEStack(); - if (hoveredAEStack != null && btn == 2) { - ((AEBaseContainer) inventorySlots).setTargetStack(hoveredAEStack); - FluidCraft.proxy.netHandler.sendToServer( - new CPacketInventoryAction( - InventoryAction.AUTO_CRAFT, - Ae2ReflectClient.getInventorySlots(this).size(), - hoveredAEStack.getStackSize(), - hoveredAEStack)); - return; - } - super.mouseClicked(xCoord, yCoord, btn); - } -} diff --git a/src/main/java/com/glodblock/github/client/gui/GuiDualInterface.java b/src/main/java/com/glodblock/github/client/gui/GuiDualInterface.java deleted file mode 100644 index 34cb4dbb..00000000 --- a/src/main/java/com/glodblock/github/client/gui/GuiDualInterface.java +++ /dev/null @@ -1,280 +0,0 @@ -package com.glodblock.github.client.gui; - -import net.minecraft.client.gui.GuiButton; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.util.StatCollector; - -import org.lwjgl.input.Keyboard; -import org.lwjgl.input.Mouse; - -import com.glodblock.github.client.gui.container.ContainerDualInterface; -import com.glodblock.github.common.parts.PartFluidInterface; -import com.glodblock.github.common.tile.TileFluidInterface; -import com.glodblock.github.inventory.InventoryHandler; -import com.glodblock.github.inventory.gui.GuiType; -import com.glodblock.github.loader.ItemAndBlockHolder; -import com.glodblock.github.util.ModAndClassUtil; -import com.glodblock.github.util.NameConst; - -import appeng.api.config.AdvancedBlockingMode; -import appeng.api.config.FuzzyMode; -import appeng.api.config.InsertionMode; -import appeng.api.config.LockCraftingMode; -import appeng.api.config.Settings; -import appeng.api.config.SidelessMode; -import appeng.api.config.Upgrades; -import appeng.api.config.YesNo; -import appeng.client.gui.implementations.GuiUpgradeable; -import appeng.client.gui.widgets.GuiImgButton; -import appeng.client.gui.widgets.GuiSimpleImgButton; -import appeng.client.gui.widgets.GuiTabButton; -import appeng.client.gui.widgets.GuiToggleButton; -import appeng.container.implementations.ContainerInterface; -import appeng.core.AELog; -import appeng.core.localization.ButtonToolTips; -import appeng.core.localization.GuiText; -import appeng.core.sync.network.NetworkHandler; -import appeng.core.sync.packets.PacketConfigButton; -import appeng.core.sync.packets.PacketValueConfig; -import appeng.helpers.IInterfaceHost; - -public class GuiDualInterface extends GuiUpgradeable { - - private GuiTabButton priority; - private GuiTabButton switcher; - private GuiImgButton BlockMode; - private GuiImgButton SmartBlockMode; - private GuiImgButton fuzzyMode; - private GuiToggleButton interfaceMode; - private GuiImgButton insertionMode; - private GuiImgButton sidelessMode; - private GuiSimpleImgButton doublePatterns; - private GuiToggleButton patternOptimization; - private GuiImgButton advancedBlockingMode; - private GuiImgButton lockCraftingMode; - private final IInterfaceHost host; - - public GuiDualInterface(InventoryPlayer inventoryPlayer, IInterfaceHost te) { - super(new ContainerDualInterface(inventoryPlayer, te)); - this.host = te; - this.ySize = 211; - } - - @Override - protected void addButtons() { - this.priority = new GuiTabButton( - this.guiLeft + 154, - this.guiTop, - 2 + 4 * 16, - GuiText.Priority.getLocal(), - itemRender); - this.buttonList.add(this.priority); - - this.switcher = new GuiTabButton( - this.guiLeft + 132, - this.guiTop, - host instanceof PartFluidInterface ? ItemAndBlockHolder.FLUID_INTERFACE.stack() - : ItemAndBlockHolder.INTERFACE.stack(), - StatCollector.translateToLocal("ae2fc.tooltip.switch_fluid_interface"), - itemRender); - this.buttonList.add(this.switcher); - - int offset = 8; - - this.BlockMode = new GuiImgButton(this.guiLeft - 18, this.guiTop + offset, Settings.BLOCK, YesNo.NO); - this.buttonList.add(this.BlockMode); - - this.SmartBlockMode = new GuiImgButton(this.guiLeft - 36, this.guiTop + offset, Settings.SMART_BLOCK, YesNo.NO); - this.buttonList.add(this.SmartBlockMode); - - offset += 18; - - this.interfaceMode = new GuiToggleButton( - this.guiLeft - 18, - this.guiTop + offset, - 84, - 85, - GuiText.InterfaceTerminal.getLocal(), - GuiText.InterfaceTerminalHint.getLocal()); - this.buttonList.add(this.interfaceMode); - - offset += 18; - - this.insertionMode = new GuiImgButton( - this.guiLeft - 18, - this.guiTop + offset, - Settings.INSERTION_MODE, - InsertionMode.DEFAULT); - this.buttonList.add(this.insertionMode); - - offset += 18; - - this.doublePatterns = new GuiSimpleImgButton(this.guiLeft - 18, this.guiTop + offset, 71, ""); - this.doublePatterns.enabled = false; - this.buttonList.add(this.doublePatterns); - - offset += 18; - - this.patternOptimization = new GuiToggleButton( - this.guiLeft - 18, - this.guiTop + offset, - 178, - 194, - GuiText.PatternOptimization.getLocal(), - GuiText.PatternOptimizationHint.getLocal()); - this.buttonList.add(this.patternOptimization); - - offset += 18; - - this.advancedBlockingMode = new GuiImgButton( - this.guiLeft - 18, - this.guiTop + offset, - Settings.ADVANCED_BLOCKING_MODE, - AdvancedBlockingMode.DEFAULT); - this.buttonList.add(this.advancedBlockingMode); - this.advancedBlockingMode.visible = this.bc.getInstalledUpgrades(Upgrades.ADVANCED_BLOCKING) > 0; - - offset += 18; - - if (isTile()) { - this.sidelessMode = new GuiImgButton( - this.guiLeft - 18, - this.guiTop + offset, - Settings.SIDELESS_MODE, - SidelessMode.SIDELESS); - this.buttonList.add(this.sidelessMode); - - offset += 18; - } - - this.lockCraftingMode = new GuiImgButton( - this.guiLeft - 18, - this.guiTop + offset, - Settings.LOCK_CRAFTING_MODE, - LockCraftingMode.NONE); - this.lockCraftingMode.visible = this.bc.getInstalledUpgrades(Upgrades.LOCK_CRAFTING) > 0; - this.buttonList.add(lockCraftingMode); - - offset += 18; - - this.fuzzyMode = new GuiImgButton( - this.guiLeft - 18, - this.guiTop + offset, - Settings.FUZZY_MODE, - FuzzyMode.IGNORE_ALL); - this.fuzzyMode.visible = this.bc.getInstalledUpgrades(Upgrades.FUZZY) > 0; - this.buttonList.add(fuzzyMode); - } - - @Override - public void drawFG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) { - if (this.BlockMode != null) { - this.BlockMode.set(((ContainerInterface) this.cvb).getBlockingMode()); - } - if (this.SmartBlockMode != null) { - this.SmartBlockMode.set(((ContainerInterface) this.cvb).getSmartBlockingMode()); - } - if (this.interfaceMode != null) { - this.interfaceMode.setState(((ContainerInterface) this.cvb).getInterfaceTerminalMode() == YesNo.YES); - } - if (this.insertionMode != null) { - this.insertionMode.set(((ContainerInterface) this.cvb).getInsertionMode()); - } - if (this.doublePatterns != null) { - this.doublePatterns.enabled = ((ContainerInterface) this.cvb).isAllowedToMultiplyPatterns; - if (this.doublePatterns.enabled) this.doublePatterns.setTooltip( - ButtonToolTips.DoublePatterns.getLocal() + "\n" + ButtonToolTips.DoublePatternsHint.getLocal()); - else this.doublePatterns.setTooltip( - ButtonToolTips.DoublePatterns.getLocal() + "\n" + ButtonToolTips.OptimizePatternsNoReq.getLocal()); - } - if (this.patternOptimization != null) { - this.patternOptimization.setState(((ContainerInterface) this.cvb).getPatternOptimization() == YesNo.YES); - } - if (this.sidelessMode != null) { - this.sidelessMode.set(((ContainerDualInterface) this.cvb).getSidelessMode()); - } - if (this.advancedBlockingMode != null) { - this.advancedBlockingMode.set(((ContainerDualInterface) this.cvb).getAdvancedBlockingMode()); - } - if (this.lockCraftingMode != null) { - this.lockCraftingMode.set(((ContainerInterface) this.cvb).getLockCraftingMode()); - } - if (this.fuzzyMode != null) { - this.fuzzyMode.set(((ContainerInterface) this.cvb).getFuzzyMode()); - } - this.fontRendererObj.drawString( - getGuiDisplayName(StatCollector.translateToLocal(NameConst.GUI_FLUID_INTERFACE)), - 8, - 6, - 4210752); - } - - @Override - protected String getBackground() { - if (!ModAndClassUtil.isBigInterface) return "guis/interface.png"; - return switch (((ContainerInterface) this.cvb).getPatternCapacityCardsInstalled()) { - case -1 -> "guis/interfacenonenoconfig.png"; - case 1 -> "guis/interface2.png"; - case 2 -> "guis/interface3.png"; - case 3 -> "guis/interface4.png"; - default -> "guis/interface.png"; - }; - } - - @Override - protected void actionPerformed(final GuiButton btn) { - super.actionPerformed(btn); - final boolean backwards = Mouse.isButtonDown(1); - if (btn == this.priority) { - InventoryHandler.switchGui(GuiType.PRIORITY); - } else if (btn == this.switcher) { - InventoryHandler.switchGui(GuiType.DUAL_INTERFACE_FLUID); - } else if (btn == this.interfaceMode) { - NetworkHandler.instance.sendToServer(new PacketConfigButton(Settings.INTERFACE_TERMINAL, backwards)); - } else if (btn == this.BlockMode) { - NetworkHandler.instance.sendToServer(new PacketConfigButton(this.BlockMode.getSetting(), backwards)); - } else if (btn == this.SmartBlockMode) { - NetworkHandler.instance.sendToServer(new PacketConfigButton(this.SmartBlockMode.getSetting(), backwards)); - } else if (btn == this.insertionMode) { - NetworkHandler.instance.sendToServer(new PacketConfigButton(this.insertionMode.getSetting(), backwards)); - } else if (btn == this.doublePatterns) { - try { - int val = Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) ? 1 : 0; - if (backwards) val |= 0b10; - NetworkHandler.instance - .sendToServer(new PacketValueConfig("Interface.DoublePatterns", String.valueOf(val))); - } catch (final Throwable e) { - AELog.debug(e); - } - } else if (btn == this.patternOptimization) { - NetworkHandler.instance.sendToServer(new PacketConfigButton(Settings.PATTERN_OPTIMIZATION, backwards)); - } else if (btn == this.sidelessMode) { - NetworkHandler.instance.sendToServer(new PacketConfigButton(this.sidelessMode.getSetting(), backwards)); - } else if (btn == this.advancedBlockingMode) { - NetworkHandler.instance - .sendToServer(new PacketConfigButton(this.advancedBlockingMode.getSetting(), backwards)); - } else if (btn == this.lockCraftingMode) { - NetworkHandler.instance.sendToServer(new PacketConfigButton(this.lockCraftingMode.getSetting(), backwards)); - } else if (btn == this.fuzzyMode) { - NetworkHandler.instance.sendToServer(new PacketConfigButton(this.fuzzyMode.getSetting(), backwards)); - } - } - - private boolean isTile() { - return this.host instanceof TileFluidInterface; - } - - @Override - protected void handleButtonVisibility() { - super.handleButtonVisibility(); - if (this.advancedBlockingMode != null) { - this.advancedBlockingMode.setVisibility(this.bc.getInstalledUpgrades(Upgrades.ADVANCED_BLOCKING) > 0); - } - if (this.lockCraftingMode != null) { - this.lockCraftingMode.setVisibility(this.bc.getInstalledUpgrades(Upgrades.LOCK_CRAFTING) > 0); - } - if (this.fuzzyMode != null) { - this.fuzzyMode.setVisibility(this.bc.getInstalledUpgrades(Upgrades.FUZZY) > 0); - } - } -} diff --git a/src/main/java/com/glodblock/github/client/gui/GuiEssentiaTerminal.java b/src/main/java/com/glodblock/github/client/gui/GuiEssentiaTerminal.java deleted file mode 100644 index 375ecfff..00000000 --- a/src/main/java/com/glodblock/github/client/gui/GuiEssentiaTerminal.java +++ /dev/null @@ -1,103 +0,0 @@ -package com.glodblock.github.client.gui; - -import java.util.Objects; - -import net.minecraft.client.gui.GuiButton; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; -import net.minecraftforge.fluids.FluidStack; - -import org.lwjgl.opengl.GL11; - -import com.glodblock.github.FluidCraft; -import com.glodblock.github.client.gui.container.ContainerEssentiaMonitor; -import com.glodblock.github.client.me.EssentiaRepo; -import com.glodblock.github.common.item.ItemFluidDrop; -import com.glodblock.github.crossmod.thaumcraft.AspectRender; -import com.glodblock.github.crossmod.thaumcraft.AspectUtil; -import com.glodblock.github.inventory.InventoryHandler; -import com.glodblock.github.inventory.gui.GuiType; -import com.glodblock.github.inventory.item.IWirelessTerminal; -import com.glodblock.github.network.CPacketFluidUpdate; - -import appeng.api.storage.data.IAEFluidStack; -import appeng.api.storage.data.IAEItemStack; -import appeng.client.me.SlotME; - -public class GuiEssentiaTerminal extends GuiFluidMonitor { - - protected EntityPlayer player; - - public GuiEssentiaTerminal(InventoryPlayer inventoryPlayer, IWirelessTerminal te) { - super(inventoryPlayer, te, new ContainerEssentiaMonitor(inventoryPlayer, te)); - this.repo = new EssentiaRepo(getScrollBar(), this); - this.player = inventoryPlayer.player; - } - - @Override - public void setTextFieldValue(String displayName, int mousex, int mousey, ItemStack stack) { - if (AspectUtil.getAspectFromJar(stack) != null) { - setSearchString(Objects.requireNonNull(AspectUtil.getAspectFromJar(stack)).getName(), true); - } - } - - @Override - public void func_146977_a(final Slot s) { - if (drawSlot0(s)) super.func_146977_a(s); - } - - public boolean drawSlot0(Slot slot) { - if (slot instanceof SlotME) { - IAEItemStack stack = ((SlotME) slot).getAEStack(); - if (stack == null) return true; - FluidStack fluidStack = ItemFluidDrop.getFluidStack(slot.getStack()); - AspectRender.drawAspect( - this.player, - slot.xDisplayPosition, - slot.yDisplayPosition, - this.zLevel, - AspectUtil.getAspectFromGas(fluidStack), - fluidStack.amount); - IAEItemStack gas = stack.copy().setStackSize(stack.getStackSize() / AspectUtil.R); - aeRenderItem.setAeStack(gas); - GL11.glTranslatef(0.0f, 0.0f, 200.0f); - aeRenderItem.renderItemOverlayIntoGUI( - fontRendererObj, - mc.getTextureManager(), - gas.getItemStack(), - slot.xDisplayPosition, - slot.yDisplayPosition); - GL11.glTranslatef(0.0f, 0.0f, -200.0f); - return false; - } - return true; - } - - @Override - protected void handleMouseClick(final Slot slot, final int slotIdx, final int ctrlDown, final int mouseButton) { - if (slot instanceof SlotME && AspectUtil.isEssentiaContainer(player.inventory.getItemStack())) { - IAEFluidStack fluid = ItemFluidDrop.getAeFluidStack(((SlotME) slot).getAEStack()); - FluidCraft.proxy.netHandler.sendToServer(new CPacketFluidUpdate(fluid, isShiftKeyDown())); - } - if (mouseButton == 3 && slot instanceof SlotME) { - return; - } - super.handleMouseClick(slot, slotIdx, ctrlDown, mouseButton); - } - - @Override - protected void actionPerformed(final GuiButton btn) { - if (btn == craftingStatusBtn) { - InventoryHandler.switchGui(GuiType.CRAFTING_STATUS); - } else { - super.actionPerformed(btn); - } - } - - public void update(ItemStack itemStack) { - this.player.inventory.setItemStack(itemStack); - } - -} diff --git a/src/main/java/com/glodblock/github/client/gui/GuiFCPriority.java b/src/main/java/com/glodblock/github/client/gui/GuiFCPriority.java deleted file mode 100644 index a6a260dc..00000000 --- a/src/main/java/com/glodblock/github/client/gui/GuiFCPriority.java +++ /dev/null @@ -1,108 +0,0 @@ -package com.glodblock.github.client.gui; - -import java.io.IOException; - -import net.minecraft.entity.player.InventoryPlayer; - -import com.glodblock.github.client.gui.base.FCGuiAmount; -import com.glodblock.github.common.parts.PartFluidStorageBus; -import com.glodblock.github.inventory.IDualHost; -import com.glodblock.github.inventory.gui.GuiType; -import com.glodblock.github.loader.ItemAndBlockHolder; - -import appeng.container.implementations.ContainerPriority; -import appeng.core.AEConfig; -import appeng.core.AELog; -import appeng.core.localization.GuiText; -import appeng.core.sync.network.NetworkHandler; -import appeng.core.sync.packets.PacketValueConfig; -import appeng.helpers.IPriorityHost; -import appeng.util.calculators.ArithHelper; -import appeng.util.calculators.Calculator; - -public class GuiFCPriority extends FCGuiAmount { - - public GuiFCPriority(final InventoryPlayer inventoryPlayer, final IPriorityHost te) { - super(new ContainerPriority(inventoryPlayer, te)); - } - - @Override - public void initGui() { - super.initGui(); - this.submit.enabled = false; - this.submit.visible = false; - this.buttonList.remove(this.submit); - ((ContainerPriority) this.inventorySlots).setTextField(this.amountBox); - } - - @Override - protected int getIncrementQuantity(int i) { - return AEConfig.instance.priorityByStacksAmounts(i); - } - - @Override - public void drawFG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) { - this.fontRendererObj.drawString(GuiText.Priority.getLocal(), 8, 6, 0x404040); - } - - @Override - public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) { - super.drawBG(offsetX, offsetY, mouseX, mouseY); - this.amountBox.drawTextBox(); - } - - @Override - protected void addQty(final int i) { - try { - this.amountBox.setText(Long.toString(getAmount() + i)); - this.amountBox.setCursorPositionEnd(); - } catch (final NumberFormatException ignore) {} - try { - NetworkHandler.instance - .sendToServer(new PacketValueConfig("PriorityHost.Priority", String.valueOf(getAmount()))); - } catch (IOException e) { - AELog.debug(e); - } - } - - @Override - protected void setOriginGUI(Object target) { - if (target instanceof IDualHost) { - this.myIcon = ItemAndBlockHolder.INTERFACE.stack(); - this.originalGui = GuiType.DUAL_INTERFACE; - } else if (target instanceof PartFluidStorageBus) { - this.myIcon = ItemAndBlockHolder.FLUID_STORAGE_BUS.stack(); - this.originalGui = GuiType.FLUID_STORAGE_BUS; - } - } - - @Override - protected void keyTyped(final char character, final int key) { - super.keyTyped(character, key); - try { - NetworkHandler.instance - .sendToServer(new PacketValueConfig("PriorityHost.Priority", String.valueOf(getAmount()))); - } catch (IOException e) { - AELog.debug(e); - } - } - - @Override - protected int getAmount() { - try { - String out = this.amountBox.getText(); - double result = Calculator.conversion(out); - if (Double.isNaN(result)) { - return 0; - } else { - return (int) ArithHelper.round(result, 0); - } - } catch (final NumberFormatException e) { - return 0; - } - } - - protected String getBackground() { - return "guis/priority.png"; - } -} diff --git a/src/main/java/com/glodblock/github/client/gui/GuiFluidAutoFiller.java b/src/main/java/com/glodblock/github/client/gui/GuiFluidAutoFiller.java index 06550497..cf6d3cee 100644 --- a/src/main/java/com/glodblock/github/client/gui/GuiFluidAutoFiller.java +++ b/src/main/java/com/glodblock/github/client/gui/GuiFluidAutoFiller.java @@ -10,10 +10,10 @@ import com.glodblock.github.client.gui.container.ContainerFluidAutoFiller; import com.glodblock.github.common.tile.TileFluidAutoFiller; import com.glodblock.github.util.NameConst; -import appeng.client.gui.AEBaseMEGui; +import appeng.client.gui.AEBaseGui; import appeng.core.localization.GuiText; -public class GuiFluidAutoFiller extends AEBaseMEGui { +public class GuiFluidAutoFiller extends AEBaseGui { protected EntityPlayer player; private static final ResourceLocation TEX_BG = FluidCraft.resource("textures/gui/fluid_auto_filler.png"); diff --git a/src/main/java/com/glodblock/github/client/gui/GuiFluidCraftAmount.java b/src/main/java/com/glodblock/github/client/gui/GuiFluidCraftAmount.java deleted file mode 100644 index 4203c8c2..00000000 --- a/src/main/java/com/glodblock/github/client/gui/GuiFluidCraftAmount.java +++ /dev/null @@ -1,122 +0,0 @@ -package com.glodblock.github.client.gui; - -import net.minecraft.client.gui.GuiButton; -import net.minecraft.entity.player.InventoryPlayer; - -import org.lwjgl.input.Mouse; - -import com.glodblock.github.FluidCraft; -import com.glodblock.github.client.gui.base.FCGuiAmount; -import com.glodblock.github.common.item.ItemWirelessUltraTerminal; -import com.glodblock.github.common.parts.PartFluidPatternTerminal; -import com.glodblock.github.common.parts.PartFluidPatternTerminalEx; -import com.glodblock.github.common.parts.PartFluidTerminal; -import com.glodblock.github.common.parts.PartLevelTerminal; -import com.glodblock.github.inventory.gui.GuiType; -import com.glodblock.github.inventory.item.IWirelessTerminal; -import com.glodblock.github.inventory.item.WirelessLevelTerminalInventory; -import com.glodblock.github.inventory.item.WirelessPatternTerminalInventory; -import com.glodblock.github.loader.ItemAndBlockHolder; -import com.glodblock.github.network.CPacketCraftRequest; - -import appeng.api.config.CraftingMode; -import appeng.api.config.Settings; -import appeng.api.storage.ITerminalHost; -import appeng.client.gui.widgets.GuiImgButton; -import appeng.container.implementations.ContainerCraftAmount; -import appeng.core.localization.GuiText; -import appeng.util.Platform; - -public class GuiFluidCraftAmount extends FCGuiAmount { - - private GuiImgButton craftingMode; - - public GuiFluidCraftAmount(final InventoryPlayer inventoryPlayer, final ITerminalHost te) { - super(new ContainerCraftAmount(inventoryPlayer, te)); - } - - @Override - public void initGui() { - super.initGui(); - - this.buttonList.add( - this.craftingMode = new GuiImgButton( - this.guiLeft + 10, - this.guiTop + 53, - Settings.CRAFTING_MODE, - CraftingMode.STANDARD)); - ((ContainerCraftAmount) this.inventorySlots).setAmountField(this.amountBox); - } - - @Override - public void drawFG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) { - this.fontRendererObj.drawString(GuiText.SelectAmount.getLocal(), 8, 6, 0x404040); - } - - @Override - public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) { - super.drawBG(offsetX, offsetY, mouseX, mouseY); - this.submit.displayString = isShiftKeyDown() ? GuiText.Start.getLocal() : GuiText.Next.getLocal(); - try { - this.submit.enabled = getAmount() > 0; - } catch (final NumberFormatException e) { - this.submit.enabled = false; - } - this.amountBox.drawTextBox(); - } - - @Override - protected void actionPerformed(final GuiButton btn) { - super.actionPerformed(btn); - try { - if (btn == this.craftingMode) { - GuiImgButton iBtn = ((GuiImgButton) btn); - - final Enum cv = iBtn.getCurrentValue(); - final boolean backwards = Mouse.isButtonDown(1); - final Enum next = Platform.rotateEnum(cv, backwards, iBtn.getSetting().getPossibleValues()); - - iBtn.set(next); - } else if (btn == this.submit && this.submit.enabled) { - FluidCraft.proxy.netHandler.sendToServer( - new CPacketCraftRequest( - getAmount(), - isShiftKeyDown(), - ((CraftingMode) this.craftingMode.getCurrentValue()))); - } - } catch (final NumberFormatException e) { - this.amountBox.setText("1"); - } - } - - @Override - protected void setOriginGUI(Object target) { - if (target instanceof PartFluidPatternTerminal) { - this.myIcon = ItemAndBlockHolder.FLUID_TERMINAL.stack(); - this.originalGui = GuiType.FLUID_PATTERN_TERMINAL; - } else if (target instanceof PartFluidPatternTerminalEx) { - this.myIcon = ItemAndBlockHolder.FLUID_TERMINAL_EX.stack(); - this.originalGui = GuiType.FLUID_PATTERN_TERMINAL_EX; - } else if (target instanceof PartFluidTerminal) { - this.myIcon = ItemAndBlockHolder.FLUID_TERM.stack(); - this.originalGui = GuiType.FLUID_TERMINAL; - } else if (target instanceof PartLevelTerminal) { - myIcon = ItemAndBlockHolder.LEVEL_TERMINAL.stack(); - originalGui = GuiType.LEVEL_TERMINAL; - } else if (target instanceof IWirelessTerminal terminal && terminal.isUniversal(target)) { - this.myIcon = ItemAndBlockHolder.WIRELESS_ULTRA_TERM.stack(); - this.originalGui = ItemWirelessUltraTerminal.readMode(terminal.getItemStack()); - } else if (target instanceof WirelessPatternTerminalInventory) { - this.myIcon = ItemAndBlockHolder.WIRELESS_PATTERN_TERM.stack(); - this.originalGui = GuiType.FLUID_TERMINAL; - } else if (target instanceof WirelessLevelTerminalInventory) { - myIcon = ItemAndBlockHolder.LEVEL_TERMINAL.stack(); - originalGui = GuiType.WIRELESS_LEVEL_TERMINAL; - } - } - - @Override - protected String getBackground() { - return "guis/craftAmt.png"; - } -} diff --git a/src/main/java/com/glodblock/github/client/gui/GuiFluidCraftConfirm.java b/src/main/java/com/glodblock/github/client/gui/GuiFluidCraftConfirm.java deleted file mode 100644 index 4ddbaea4..00000000 --- a/src/main/java/com/glodblock/github/client/gui/GuiFluidCraftConfirm.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.glodblock.github.client.gui; - -import net.minecraft.entity.player.InventoryPlayer; - -import com.glodblock.github.common.item.ItemWirelessUltraTerminal; -import com.glodblock.github.common.parts.PartFluidPatternTerminal; -import com.glodblock.github.common.parts.PartFluidPatternTerminalEx; -import com.glodblock.github.common.parts.PartLevelTerminal; -import com.glodblock.github.inventory.InventoryHandler; -import com.glodblock.github.inventory.gui.GuiType; -import com.glodblock.github.inventory.item.IWirelessTerminal; -import com.glodblock.github.inventory.item.WirelessLevelTerminalInventory; -import com.glodblock.github.inventory.item.WirelessPatternTerminalInventory; - -import appeng.api.storage.ITerminalHost; -import appeng.client.gui.implementations.GuiCraftConfirm; - -public class GuiFluidCraftConfirm extends GuiCraftConfirm { - - private GuiType originalGui; - - public GuiFluidCraftConfirm(final InventoryPlayer inventoryPlayer, final ITerminalHost te) { - super(inventoryPlayer, te); - if (te instanceof PartFluidPatternTerminal) { - this.originalGui = GuiType.FLUID_PATTERN_TERMINAL; - } else if (te instanceof PartFluidPatternTerminalEx) { - this.originalGui = GuiType.FLUID_PATTERN_TERMINAL_EX; - } else if (te instanceof PartLevelTerminal) { - originalGui = GuiType.LEVEL_TERMINAL; - } else if (te instanceof IWirelessTerminal terminal && terminal.isUniversal(te)) { - this.originalGui = ItemWirelessUltraTerminal.readMode(terminal.getItemStack()); - } else if (te instanceof WirelessPatternTerminalInventory) { - this.originalGui = GuiType.FLUID_TERMINAL; - } else if (te instanceof WirelessLevelTerminalInventory) { - originalGui = GuiType.WIRELESS_LEVEL_TERMINAL; - } - } - - @Override - public void switchToOriginalGUI() { - InventoryHandler.switchGui(originalGui); - } -} diff --git a/src/main/java/com/glodblock/github/client/gui/GuiFluidCraftingWireless.java b/src/main/java/com/glodblock/github/client/gui/GuiFluidCraftingWireless.java deleted file mode 100644 index 054cf43e..00000000 --- a/src/main/java/com/glodblock/github/client/gui/GuiFluidCraftingWireless.java +++ /dev/null @@ -1,84 +0,0 @@ -package com.glodblock.github.client.gui; - -import net.minecraft.client.gui.GuiButton; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.Container; -import net.minecraft.inventory.Slot; - -import com.glodblock.github.client.gui.container.ContainerCraftingWireless; -import com.glodblock.github.inventory.InventoryHandler; -import com.glodblock.github.inventory.gui.GuiType; -import com.glodblock.github.inventory.item.IWirelessTerminal; - -import appeng.api.config.ActionItems; -import appeng.api.config.Settings; -import appeng.client.gui.widgets.GuiImgButton; -import appeng.container.slot.SlotCraftingMatrix; -import appeng.core.localization.GuiColors; -import appeng.core.localization.GuiText; -import appeng.core.sync.network.NetworkHandler; -import appeng.core.sync.packets.PacketInventoryAction; -import appeng.helpers.InventoryAction; - -public class GuiFluidCraftingWireless extends GuiItemMonitor { - - private GuiImgButton clearBtn; - - public GuiFluidCraftingWireless(final InventoryPlayer inventoryPlayer, final IWirelessTerminal te) { - super(inventoryPlayer, te, new ContainerCraftingWireless(inventoryPlayer, te)); - this.setReservedSpace(73); - } - - @Override - protected void actionPerformed(final GuiButton btn) { - if (btn == craftingStatusBtn) { - InventoryHandler.switchGui(GuiType.CRAFTING_STATUS); - } else { - super.actionPerformed(btn); - if (this.clearBtn == btn) { - Slot s = null; - final Container c = this.inventorySlots; - for (final Object j : c.inventorySlots) { - if (j instanceof SlotCraftingMatrix) { - s = (Slot) j; - } - } - if (s != null) { - final PacketInventoryAction p = new PacketInventoryAction( - InventoryAction.MOVE_REGION, - s.slotNumber, - 0); - NetworkHandler.instance.sendToServer(p); - } - } - } - } - - @Override - public void initGui() { - super.initGui(); - this.buttonList.add( - this.clearBtn = new GuiImgButton( - this.guiLeft + 92, - this.guiTop + this.ySize - 156, - Settings.ACTIONS, - ActionItems.STASH)); - this.clearBtn.setHalfSize(true); - } - - @Override - public void drawFG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) { - super.drawFG(offsetX, offsetY, mouseX, mouseY); - this.fontRendererObj.drawString( - GuiText.CraftingTerminal.getLocal(), - 8, - this.ySize - 96 + 1 - this.getReservedSpace(), - GuiColors.CraftingTerminalTitle.getColor()); - } - - @Override - protected String getBackground() { - return "gui/crafting.png"; - } - -} diff --git a/src/main/java/com/glodblock/github/client/gui/GuiFluidIO.java b/src/main/java/com/glodblock/github/client/gui/GuiFluidIO.java deleted file mode 100644 index eda5d897..00000000 --- a/src/main/java/com/glodblock/github/client/gui/GuiFluidIO.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.glodblock.github.client.gui; - -import net.minecraft.client.resources.I18n; -import net.minecraft.entity.player.InventoryPlayer; - -import com.glodblock.github.client.gui.container.ContainerFluidIO; -import com.glodblock.github.common.parts.PartFluidExportBus; -import com.glodblock.github.common.parts.PartFluidImportBus; -import com.glodblock.github.common.parts.base.FCSharedFluidBus; -import com.glodblock.github.util.NameConst; - -import appeng.api.config.Upgrades; -import appeng.api.storage.data.IAEFluidStack; -import appeng.client.gui.implementations.GuiUpgradeable; -import appeng.core.localization.GuiText; - -public class GuiFluidIO extends GuiUpgradeable { - - private final FCSharedFluidBus bus; - - public GuiFluidIO(InventoryPlayer inventoryPlayer, FCSharedFluidBus te) { - super(new ContainerFluidIO(inventoryPlayer, te)); - this.bus = te; - } - - @Override - protected GuiText getName() { - return this.bus instanceof PartFluidImportBus ? GuiText.ImportBus : GuiText.ExportBus; - } - - public void update(int id, IAEFluidStack stack) { - ((ContainerFluidIO) this.cvb).getBus().setFluidInSlot(id, stack); - } - - @Override - public void drawFG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) { - this.fontRendererObj.drawString( - this.getGuiDisplayName( - I18n.format( - this.bus instanceof PartFluidImportBus ? NameConst.GUI_FLUID_IMPORT - : NameConst.GUI_FLUID_EXPORT)), - 8, - 6, - 4210752); - this.fontRendererObj.drawString(GuiText.inventory.getLocal(), 8, this.ySize - 96 + 3, 4210752); - - if (this.redstoneMode != null) { - this.redstoneMode.set(this.cvb.getRedStoneMode()); - } - - if (this.fuzzyMode != null) { - this.fuzzyMode.set(this.cvb.getFuzzyMode()); - } - - if (this.craftMode != null) { - this.craftMode.set(this.cvb.getCraftingMode()); - } - - if (this.schedulingMode != null) { - this.schedulingMode.set(this.cvb.getSchedulingMode()); - } - } - - @Override - protected void handleButtonVisibility() { - super.handleButtonVisibility(); - if (this.schedulingMode != null) { - this.schedulingMode.setVisibility( - this.bc.getInstalledUpgrades(Upgrades.CAPACITY) > 0 && this.bc instanceof PartFluidExportBus); - } - } -} diff --git a/src/main/java/com/glodblock/github/client/gui/GuiFluidInterface.java b/src/main/java/com/glodblock/github/client/gui/GuiFluidInterface.java index 1e70b9cd..8fa334a6 100644 --- a/src/main/java/com/glodblock/github/client/gui/GuiFluidInterface.java +++ b/src/main/java/com/glodblock/github/client/gui/GuiFluidInterface.java @@ -1,13 +1,11 @@ package com.glodblock.github.client.gui; -import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.renderer.texture.TextureMap; import net.minecraft.client.resources.I18n; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Slot; import net.minecraft.util.ResourceLocation; -import net.minecraft.util.StatCollector; import net.minecraftforge.common.util.ForgeDirection; import org.lwjgl.opengl.GL11; @@ -17,27 +15,22 @@ import com.glodblock.github.client.gui.container.ContainerFluidInterface; import com.glodblock.github.common.parts.PartFluidInterface; import com.glodblock.github.inventory.IAEFluidTank; import com.glodblock.github.inventory.IDualHost; -import com.glodblock.github.inventory.InventoryHandler; -import com.glodblock.github.inventory.gui.GuiType; import com.glodblock.github.inventory.gui.MouseRegionManager; import com.glodblock.github.inventory.gui.TankMouseHandler; -import com.glodblock.github.loader.ItemAndBlockHolder; import com.glodblock.github.util.NameConst; import com.glodblock.github.util.RenderUtil; import appeng.api.storage.data.IAEFluidStack; -import appeng.client.gui.AEBaseGui; -import appeng.client.gui.widgets.GuiTabButton; +import appeng.client.gui.GuiSub; import appeng.core.localization.GuiText; -public class GuiFluidInterface extends AEBaseGui { +public class GuiFluidInterface extends GuiSub { private static final ResourceLocation TEX_BG = FluidCraft.resource("textures/gui/interface_fluid.png"); private static final int TANK_X = 35, TANK_X_OFF = 18, TANK_Y = 53; private static final int TANK_WIDTH = 16, TANK_HEIGHT = 68; private final ContainerFluidInterface cont; - private GuiTabButton switcher; private final MouseRegionManager mouseRegions = new MouseRegionManager(this); public GuiFluidInterface(InventoryPlayer ipl, IDualHost tile) { @@ -65,18 +58,6 @@ public class GuiFluidInterface extends AEBaseGui { } catch (final Exception ignore) {} } - @Override - public void initGui() { - super.initGui(); - this.switcher = new GuiTabButton( - this.guiLeft + 154, - this.guiTop, - isPart() ? ItemAndBlockHolder.FLUID_INTERFACE.stack() : ItemAndBlockHolder.INTERFACE.stack(), - StatCollector.translateToLocal("ae2fc.tooltip.switch_fluid_interface"), - itemRender); - this.buttonList.add(this.switcher); - } - @Override public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) { fontRendererObj.drawString(getGuiDisplayName(I18n.format(NameConst.GUI_FLUID_INTERFACE)), 8, 6, 0x404040); @@ -112,14 +93,6 @@ public class GuiFluidInterface extends AEBaseGui { drawTexturedModalRect(offsetX, offsetY, 0, 0, 176, ySize); } - @Override - protected void actionPerformed(final GuiButton btn) { - super.actionPerformed(btn); - if (btn == this.switcher) { - InventoryHandler.switchGui(GuiType.DUAL_INTERFACE); - } - } - public void update(int id, IAEFluidStack stack) { if (id >= 100) { cont.getTile().setConfig(id - 100, stack); diff --git a/src/main/java/com/glodblock/github/client/gui/GuiFluidLevelEmitter.java b/src/main/java/com/glodblock/github/client/gui/GuiFluidLevelEmitter.java deleted file mode 100644 index 8e5a9a7f..00000000 --- a/src/main/java/com/glodblock/github/client/gui/GuiFluidLevelEmitter.java +++ /dev/null @@ -1,306 +0,0 @@ -package com.glodblock.github.client.gui; - -import net.minecraft.client.gui.GuiButton; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.item.ItemStack; -import net.minecraftforge.common.util.ForgeDirection; - -import org.lwjgl.input.Keyboard; -import org.lwjgl.opengl.GL11; - -import com.glodblock.github.FluidCraft; -import com.glodblock.github.client.gui.container.ContainerFluidLevelEmitter; -import com.glodblock.github.common.item.ItemWirelessUltraTerminal; -import com.glodblock.github.common.parts.PartFluidLevelEmitter; -import com.glodblock.github.common.parts.PartLevelTerminal; -import com.glodblock.github.inventory.gui.GuiType; -import com.glodblock.github.inventory.item.IWirelessTerminal; -import com.glodblock.github.inventory.item.WirelessLevelTerminalInventory; -import com.glodblock.github.loader.ItemAndBlockHolder; -import com.glodblock.github.network.CPacketLevelTerminalCommands; -import com.glodblock.github.network.CPacketValueConfig; -import com.glodblock.github.util.NameConst; -import com.glodblock.github.util.Util; - -import appeng.api.config.RedstoneMode; -import appeng.api.config.Settings; -import appeng.api.storage.data.IAEFluidStack; -import appeng.api.util.DimensionalCoord; -import appeng.client.gui.implementations.GuiUpgradeable; -import appeng.client.gui.widgets.GuiImgButton; -import appeng.client.gui.widgets.GuiTabButton; -import appeng.client.gui.widgets.MEGuiTextField; -import appeng.container.AEBaseContainer; -import appeng.core.AEConfig; -import appeng.core.localization.GuiColors; -import appeng.core.localization.GuiText; -import appeng.util.calculators.ArithHelper; -import appeng.util.calculators.Calculator; - -public class GuiFluidLevelEmitter extends GuiUpgradeable { - - private MEGuiTextField amountTextField; - - protected GuiType originalGui; - protected Util.DimensionalCoordSide originalBlockPos; - protected ItemStack originalGuiIcon; - protected GuiTabButton originalGuiBtn; - - private GuiButton plus1; - private GuiButton plus10; - private GuiButton plus100; - private GuiButton plus1000; - private GuiButton minus1; - private GuiButton minus10; - private GuiButton minus100; - private GuiButton minus1000; - - private GuiButton setButton; - - private boolean isMul = false; - - public GuiFluidLevelEmitter(final InventoryPlayer inventoryPlayer, final PartFluidLevelEmitter te) { - super(new ContainerFluidLevelEmitter(inventoryPlayer, te)); - - if (inventoryPlayer.player.openContainer instanceof AEBaseContainer container) { - var target = container.getTarget(); - if (target instanceof PartLevelTerminal terminal) { - originalGuiIcon = ItemAndBlockHolder.LEVEL_TERMINAL.stack(); - originalGui = GuiType.LEVEL_TERMINAL; - DimensionalCoord blockPos = new DimensionalCoord(terminal.getTile()); - originalBlockPos = new Util.DimensionalCoordSide( - blockPos.x, - blockPos.y, - blockPos.z, - blockPos.getDimension(), - terminal.getSide(), - ""); - } else if (target instanceof IWirelessTerminal terminal && terminal.isUniversal(target)) { - originalGuiIcon = ItemAndBlockHolder.WIRELESS_ULTRA_TERM.stack(); - originalGui = ItemWirelessUltraTerminal.readMode(terminal.getItemStack()); - originalBlockPos = new Util.DimensionalCoordSide( - terminal.getInventorySlot(), - Util.GuiHelper.encodeType(0, Util.GuiHelper.GuiType.ITEM), - 0, - inventoryPlayer.player.worldObj.provider.dimensionId, - ForgeDirection.UNKNOWN, - ""); - } else if (target instanceof WirelessLevelTerminalInventory terminal) { - originalGuiIcon = ItemAndBlockHolder.WIRELESS_LEVEL_TERM.stack(); - originalGui = GuiType.WIRELESS_LEVEL_TERMINAL; - originalBlockPos = new Util.DimensionalCoordSide( - terminal.getInventorySlot(), - Util.GuiHelper.encodeType(0, Util.GuiHelper.GuiType.ITEM), - 0, - inventoryPlayer.player.worldObj.provider.dimensionId, - ForgeDirection.UNKNOWN, - ""); - - } - } - } - - @Override - public void initGui() { - super.initGui(); - - this.amountTextField = new MEGuiTextField(90, 12); - this.amountTextField.x = this.guiLeft + 39; - this.amountTextField.y = this.guiTop + 44; - this.amountTextField.setFocused(true); - ((ContainerFluidLevelEmitter) this.inventorySlots).setTextField(this.amountTextField); - this.validateText(); - - if (this.originalGuiIcon != null) { - this.originalGuiBtn = new GuiTabButton( - this.guiLeft + 151, - this.guiTop - 4, - this.originalGuiIcon, - this.originalGuiIcon.getDisplayName(), - itemRender); - this.originalGuiBtn.setHideEdge(13); - this.buttonList.add(originalGuiBtn); - } - } - - @Override - protected void addButtons() { - this.redstoneMode = new GuiImgButton( - this.guiLeft - 18, - this.guiTop + 8, - Settings.REDSTONE_EMITTER, - RedstoneMode.LOW_SIGNAL); - - final int a = AEConfig.instance.levelByStackAmounts(0); - final int b = AEConfig.instance.levelByStackAmounts(1); - final int c = AEConfig.instance.levelByStackAmounts(2); - final int d = AEConfig.instance.levelByStackAmounts(3); - - this.buttonList.add(this.plus1 = new GuiButton(0, this.guiLeft + 20, this.guiTop + 17, 22, 20, "+" + a)); - this.buttonList.add(this.plus10 = new GuiButton(0, this.guiLeft + 48, this.guiTop + 17, 28, 20, "+" + b)); - this.buttonList.add(this.plus100 = new GuiButton(0, this.guiLeft + 82, this.guiTop + 17, 32, 20, "+" + c)); - this.buttonList.add(this.plus1000 = new GuiButton(0, this.guiLeft + 120, this.guiTop + 17, 38, 20, "+" + d)); - - this.buttonList.add(this.minus1 = new GuiButton(0, this.guiLeft + 20, this.guiTop + 63, 22, 20, "-" + a)); - this.buttonList.add(this.minus10 = new GuiButton(0, this.guiLeft + 48, this.guiTop + 63, 28, 20, "-" + b)); - this.buttonList.add(this.minus100 = new GuiButton(0, this.guiLeft + 82, this.guiTop + 63, 32, 20, "-" + c)); - this.buttonList.add(this.minus1000 = new GuiButton(0, this.guiLeft + 120, this.guiTop + 63, 38, 20, "-" + d)); - - this.buttonList.add( - this.setButton = new GuiButton( - 0, - this.guiLeft + 134, - this.guiTop + 40, - 28, - 20, - GuiText.Set.getLocal())); - - this.buttonList.add(this.redstoneMode); - } - - @Override - public void drawFG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) { - this.fontRendererObj.drawString( - getGuiDisplayName(NameConst.i18n(NameConst.GUI_FLUID_LEVEL_EMITTER)), - 8, - 6, - GuiColors.UpgradableTitle.getColor()); - this.fontRendererObj.drawString( - GuiText.inventory.getLocal(), - 8, - this.ySize - 96 + 3, - GuiColors.UpgradableInventory.getColor()); - this.redstoneMode.set(this.cvb.getRedStoneMode()); - - if (isShiftKeyDown() && !isMul) { - for (GuiButton btn : this.buttonList) { - if (btn instanceof GuiButton) { - btn.displayString += "000"; - } - } - isMul = true; - } else if (!isShiftKeyDown() && isMul) { - for (GuiButton btn : this.buttonList) { - if (btn instanceof GuiButton) { - btn.displayString = btn.displayString.substring(0, btn.displayString.lastIndexOf("000")); - } - } - isMul = false; - } - } - - @Override - public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) { - super.drawBG(offsetX, offsetY, mouseX, mouseY); - this.amountTextField.drawTextBox(); - - // Without these two lines, the liquid slot will not draw properly. - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - this.bindTexture(this.getBackground()); - } - - @Override - protected void handleButtonVisibility() {} - - @Override - protected String getBackground() { - return "guis/lvlemitter.png"; - } - - @Override - protected void actionPerformed(final GuiButton btn) { - - if (btn == this.originalGuiBtn) { - CPacketLevelTerminalCommands message = new CPacketLevelTerminalCommands( - CPacketLevelTerminalCommands.Action.BACK, - originalBlockPos.x, - originalBlockPos.y, - originalBlockPos.z, - originalBlockPos.getDimension(), - originalBlockPos.getSide()); - message.setOriginalGui(originalGui.ordinal()); - FluidCraft.proxy.netHandler.sendToServer(message); - } else if (btn == this.setButton && this.setButton.enabled) { - final long amount = this.getAmountLong(); - this.amountTextField.setText(Long.toString(amount)); - - FluidCraft.proxy.netHandler.sendToServer(new CPacketValueConfig(amount, 0)); - } else { - final boolean isPlus = btn == this.plus1 || btn == this.plus10 - || btn == this.plus100 - || btn == this.plus1000; - final boolean isMinus = btn == this.minus1 || btn == this.minus10 - || btn == this.minus100 - || btn == this.minus1000; - - if (isPlus || isMinus) { - long result = addOrderAmount(this.getQty(btn)); - this.amountTextField.setText(Long.toString(result)); - } else { - super.actionPerformed(btn); - } - } - } - - private long addOrderAmount(final int i) { - long resultL = getAmountLong(); - - if (resultL == 1 && i > 1) { - resultL = 0; - } - - resultL += i; - if (resultL < 1) { - resultL = 1; - } - return resultL; - } - - private long getAmountLong() { - String out = this.amountTextField.getText(); - double resultD = Calculator.conversion(out); - - if (resultD <= 0 || Double.isNaN(resultD)) { - return 0; - } else { - return (long) ArithHelper.round(resultD, 0); - } - } - - private void validateText() { - String text = this.amountTextField.getText(); - double resultD = Calculator.conversion(text); - this.setButton.enabled = !Double.isNaN(resultD); - } - - @Override - protected void mouseClicked(int xCoord, int yCoord, int btn) { - this.amountTextField.mouseClicked(xCoord, yCoord, btn); - super.mouseClicked(xCoord, yCoord, btn); - } - - @Override - protected void keyTyped(final char character, final int key) { - if (!this.checkHotbarKeys(key)) { - if (key == Keyboard.KEY_RETURN || key == Keyboard.KEY_NUMPADENTER) { - this.actionPerformed(this.setButton); - } else { - boolean typedTextbox = this.amountTextField.textboxKeyTyped(character, key); - if (typedTextbox) { - this.validateText(); - } else { - super.keyTyped(character, key); - } - } - } - } - - @Override - protected boolean drawUpgrades() { - return false; - } - - public void update(Integer key, IAEFluidStack value) { - ((ContainerFluidLevelEmitter) this.cvb).getBus().setFluidInSlot(key, value); - } -} diff --git a/src/main/java/com/glodblock/github/client/gui/GuiFluidMonitor.java b/src/main/java/com/glodblock/github/client/gui/GuiFluidMonitor.java deleted file mode 100644 index 1652483f..00000000 --- a/src/main/java/com/glodblock/github/client/gui/GuiFluidMonitor.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.glodblock.github.client.gui; - -import java.util.List; - -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.item.ItemStack; -import net.minecraftforge.fluids.FluidStack; - -import com.glodblock.github.client.gui.base.FCGuiMonitor; -import com.glodblock.github.client.gui.container.ContainerFluidMonitor; -import com.glodblock.github.client.me.FluidRepo; -import com.glodblock.github.common.item.ItemFluidDrop; -import com.glodblock.github.util.Util; - -import appeng.api.storage.ITerminalHost; -import appeng.api.storage.data.IAEFluidStack; -import appeng.api.storage.data.IAEItemStack; -import appeng.core.localization.GuiText; -import appeng.util.item.AEItemStack; - -public class GuiFluidMonitor extends FCGuiMonitor { - - public GuiFluidMonitor(final InventoryPlayer inventoryPlayer, final ITerminalHost te, - final ContainerFluidMonitor c) { - super(inventoryPlayer, te, c); - this.repo = new FluidRepo(getScrollBar(), this); - this.setScrollBar(); - } - - @Override - public void postUpdate(final List list, boolean resort) { - for (final IAEFluidStack is : list) { - IAEItemStack stack = AEItemStack.create(ItemFluidDrop.newDisplayStack(is.getFluidStack())); - stack.setStackSize(is.getStackSize()); - this.repo.postUpdate(stack); - } - if (resort) { - this.repo.updateView(); - } - this.setScrollBar(); - } - - @Override - public void drawFG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) { - this.fontRendererObj.drawString(this.getGuiDisplayName(GuiText.Terminal.getLocal()), 8, 6, 4210752); - this.fontRendererObj.drawString(GuiText.inventory.getLocal(), 8, this.ySize - 96 + 3, 4210752); - super.drawFG(offsetX, offsetY, mouseX, mouseY); - } - - @Override - protected IAEItemStack transformItem(IAEItemStack stack) { - if (stack.getItem() instanceof ItemFluidDrop) { - return ItemFluidDrop.newAeStack(ItemFluidDrop.getAeFluidStack(stack)); - } - return stack; - } - - @Override - public void setTextFieldValue(String displayName, int mousex, int mousey, ItemStack stack) { - final FluidStack fluid = Util.getFluidFromItem(stack); - if (fluid != null) { - setSearchString(fluid.getLocalizedName(), true); - } - } -} diff --git a/src/main/java/com/glodblock/github/client/gui/GuiFluidOptimizePatterns.java b/src/main/java/com/glodblock/github/client/gui/GuiFluidOptimizePatterns.java deleted file mode 100644 index ddd97789..00000000 --- a/src/main/java/com/glodblock/github/client/gui/GuiFluidOptimizePatterns.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.glodblock.github.client.gui; - -import net.minecraft.client.gui.GuiButton; -import net.minecraft.entity.player.InventoryPlayer; - -import com.glodblock.github.common.item.ItemWirelessUltraTerminal; -import com.glodblock.github.common.parts.PartFluidPatternTerminal; -import com.glodblock.github.common.parts.PartFluidPatternTerminalEx; -import com.glodblock.github.common.parts.PartLevelTerminal; -import com.glodblock.github.inventory.InventoryHandler; -import com.glodblock.github.inventory.gui.GuiType; -import com.glodblock.github.inventory.item.IWirelessTerminal; -import com.glodblock.github.inventory.item.WirelessLevelTerminalInventory; -import com.glodblock.github.inventory.item.WirelessPatternTerminalInventory; - -import appeng.api.storage.ITerminalHost; -import appeng.client.gui.implementations.GuiOptimizePatterns; -import appeng.core.localization.GuiText; - -public class GuiFluidOptimizePatterns extends GuiOptimizePatterns { - - private GuiType originalGui; - - public GuiFluidOptimizePatterns(InventoryPlayer inventoryPlayer, ITerminalHost te) { - super(inventoryPlayer, te); - if (te instanceof PartFluidPatternTerminal) { - this.originalGui = GuiType.FLUID_PATTERN_TERMINAL; - } else if (te instanceof PartFluidPatternTerminalEx) { - this.originalGui = GuiType.FLUID_PATTERN_TERMINAL_EX; - } else if (te instanceof PartLevelTerminal) { - originalGui = GuiType.LEVEL_TERMINAL; - } else if (te instanceof IWirelessTerminal terminal && terminal.isUniversal(te)) { - this.originalGui = ItemWirelessUltraTerminal.readMode(terminal.getItemStack()); - } else if (te instanceof WirelessPatternTerminalInventory) { - this.originalGui = GuiType.FLUID_TERMINAL; - } else if (te instanceof WirelessLevelTerminalInventory) { - originalGui = GuiType.WIRELESS_LEVEL_TERMINAL; - } - } - - @Override - protected void actionPerformed(GuiButton btn) { - if (btn.displayString.equals(GuiText.Cancel.getLocal())) { - InventoryHandler.switchGui(originalGui); - return; - } - super.actionPerformed(btn); - } -} diff --git a/src/main/java/com/glodblock/github/client/gui/GuiFluidPatternEncoder.java b/src/main/java/com/glodblock/github/client/gui/GuiFluidPatternEncoder.java index 7ca1fdd1..512093ef 100644 --- a/src/main/java/com/glodblock/github/client/gui/GuiFluidPatternEncoder.java +++ b/src/main/java/com/glodblock/github/client/gui/GuiFluidPatternEncoder.java @@ -22,7 +22,6 @@ import com.glodblock.github.common.tile.TileFluidPatternEncoder; import com.glodblock.github.inventory.gui.MouseRegionManager; import com.glodblock.github.inventory.slot.ISlotFluid; import com.glodblock.github.inventory.slot.SlotSingleItem; -import com.glodblock.github.network.CPacketEncodePattern; import com.glodblock.github.util.NameConst; import appeng.api.storage.data.IAEItemStack; @@ -50,7 +49,7 @@ public class GuiFluidPatternEncoder extends AEBaseGui { public boolean onClick(int button) { if (button == 0) { if (cont.canEncodePattern()) { - FluidCraft.proxy.netHandler.sendToServer(new CPacketEncodePattern()); + // FluidCraft.proxy.netHandler.sendToServer(new CPacketEncodePattern()); } return true; } diff --git a/src/main/java/com/glodblock/github/client/gui/GuiFluidPatternExWireless.java b/src/main/java/com/glodblock/github/client/gui/GuiFluidPatternExWireless.java deleted file mode 100644 index db13d964..00000000 --- a/src/main/java/com/glodblock/github/client/gui/GuiFluidPatternExWireless.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.glodblock.github.client.gui; - -import net.minecraft.entity.player.InventoryPlayer; - -import com.glodblock.github.inventory.item.IWirelessTerminal; - -import appeng.container.slot.AppEngSlot; -import appeng.container.slot.SlotDisabled; - -public class GuiFluidPatternExWireless extends GuiFluidPatternTerminalEx { - - public GuiFluidPatternExWireless(InventoryPlayer inventoryPlayer, IWirelessTerminal te) { - super(inventoryPlayer, te); - } - - @Override - protected void repositionSlot(final AppEngSlot s) { - if (s instanceof SlotDisabled || s.isPlayerSide()) { - s.yDisplayPosition = s.getY() + this.ySize - 78 - 5; - } else { - s.yDisplayPosition = s.getY() + this.ySize - 78 - 3; - } - } -} diff --git a/src/main/java/com/glodblock/github/client/gui/GuiFluidPatternTerminal.java b/src/main/java/com/glodblock/github/client/gui/GuiFluidPatternTerminal.java deleted file mode 100644 index 8febe5a1..00000000 --- a/src/main/java/com/glodblock/github/client/gui/GuiFluidPatternTerminal.java +++ /dev/null @@ -1,180 +0,0 @@ -package com.glodblock.github.client.gui; - -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.init.Blocks; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; -import net.minecraft.util.StatCollector; - -import com.glodblock.github.FluidCraft; -import com.glodblock.github.client.gui.base.FCGuiEncodeTerminal; -import com.glodblock.github.client.gui.container.ContainerFluidPatternTerminal; -import com.glodblock.github.client.gui.container.ContainerFluidPatternWireless; -import com.glodblock.github.inventory.item.IWirelessTerminal; -import com.glodblock.github.network.CPacketInventoryAction; -import com.glodblock.github.util.ModAndClassUtil; -import com.glodblock.github.util.NameConst; - -import appeng.api.config.ActionItems; -import appeng.api.config.ItemSubstitution; -import appeng.api.config.PatternBeSubstitution; -import appeng.api.config.Settings; -import appeng.api.storage.ITerminalHost; -import appeng.client.gui.widgets.GuiImgButton; -import appeng.client.gui.widgets.GuiTabButton; -import appeng.container.slot.OptionalSlotFake; -import appeng.container.slot.SlotFakeCraftingMatrix; -import appeng.container.slot.SlotPatternTerm; -import appeng.core.localization.GuiText; -import appeng.helpers.InventoryAction; - -public class GuiFluidPatternTerminal extends FCGuiEncodeTerminal { - - public GuiFluidPatternTerminal(final InventoryPlayer inventoryPlayer, final ITerminalHost te) { - super(inventoryPlayer, te, new ContainerFluidPatternTerminal(inventoryPlayer, te)); - } - - public GuiFluidPatternTerminal(final InventoryPlayer inventoryPlayer, final IWirelessTerminal te) { - super(inventoryPlayer, te, new ContainerFluidPatternWireless(inventoryPlayer, te)); - } - - @Override - public void initGui() { - super.initGui(); - this.tabCraftButton = new GuiTabButton( - this.guiLeft + 173, - this.guiTop + this.ySize - 177, - new ItemStack(Blocks.crafting_table), - GuiText.CraftingPattern.getLocal(), - itemRender); - this.buttonList.add(this.tabCraftButton); - - this.tabProcessButton = new GuiTabButton( - this.guiLeft + 173, - this.guiTop + this.ySize - 177, - new ItemStack(Blocks.furnace), - GuiText.ProcessingPattern.getLocal(), - itemRender); - this.buttonList.add(this.tabProcessButton); - - this.substitutionsEnabledBtn = new GuiImgButton( - this.guiLeft + 84, - this.guiTop + this.ySize - 163, - Settings.ACTIONS, - ItemSubstitution.ENABLED); - this.substitutionsEnabledBtn.setHalfSize(true); - this.buttonList.add(this.substitutionsEnabledBtn); - - this.substitutionsDisabledBtn = new GuiImgButton( - this.guiLeft + 84, - this.guiTop + this.ySize - 163, - Settings.ACTIONS, - ItemSubstitution.DISABLED); - this.substitutionsDisabledBtn.setHalfSize(true); - this.buttonList.add(this.substitutionsDisabledBtn); - - this.clearBtn = new GuiImgButton( - this.guiLeft + 74, - this.guiTop + this.ySize - 163, - Settings.ACTIONS, - ActionItems.CLOSE); - this.clearBtn.setHalfSize(true); - this.buttonList.add(this.clearBtn); - - this.encodeBtn = new GuiImgButton( - this.guiLeft + 147, - this.guiTop + this.ySize - 142, - Settings.ACTIONS, - ActionItems.ENCODE); - this.buttonList.add(this.encodeBtn); - - int combineLeft = 74; - int combineTop = 153; - if (ModAndClassUtil.isDoubleButton) { - this.doubleBtn = new GuiImgButton( - this.guiLeft + 74, - this.guiTop + this.ySize - 153, - Settings.ACTIONS, - ActionItems.DOUBLE); - this.doubleBtn.setHalfSize(true); - this.buttonList.add(this.doubleBtn); - combineLeft = 84; - } - if (ModAndClassUtil.isBeSubstitutionsButton) { - combineLeft = 74; - combineTop -= 11; - this.beSubstitutionsEnabledBtn = new GuiImgButton( - this.guiLeft + 84, - this.guiTop + this.ySize - 153, - Settings.ACTIONS, - PatternBeSubstitution.ENABLED); - this.beSubstitutionsEnabledBtn.setHalfSize(true); - this.buttonList.add(this.beSubstitutionsEnabledBtn); - - this.beSubstitutionsDisabledBtn = new GuiImgButton( - this.guiLeft + 84, - this.guiTop + this.ySize - 153, - Settings.ACTIONS, - PatternBeSubstitution.DISABLED); - this.beSubstitutionsDisabledBtn.setHalfSize(true); - this.buttonList.add(this.beSubstitutionsDisabledBtn); - } - this.combineEnableBtn = new GuiFCImgButton( - this.guiLeft + combineLeft, - this.guiTop + this.ySize - combineTop, - "FORCE_COMBINE", - "DO_COMBINE"); - this.combineEnableBtn.setHalfSize(true); - this.buttonList.add(this.combineEnableBtn); - - this.combineDisableBtn = new GuiFCImgButton( - this.guiLeft + combineLeft, - this.guiTop + this.ySize - combineTop, - "NOT_COMBINE", - "DONT_COMBINE"); - this.combineDisableBtn.setHalfSize(true); - this.buttonList.add(this.combineDisableBtn); - } - - @Override - public void drawFG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) { - super.drawFG(offsetX, offsetY, mouseX, mouseY); - this.fontRendererObj.drawString( - StatCollector.translateToLocal(NameConst.GUI_FLUID_PATTERN_TERMINAL), - 8, - this.ySize - 96 + 2 - getReservedSpace(), - 4210752); - } - - @Override - protected void mouseClicked(final int xCoord, final int yCoord, final int btn) { - - if (btn == 2 && doubleBtn.mousePressed(this.mc, xCoord, yCoord)) { // - InventoryAction action = InventoryAction.SET_PATTERN_MULTI; - - final CPacketInventoryAction p = new CPacketInventoryAction(action, 0, 0); - FluidCraft.proxy.netHandler.sendToServer(p); - } else super.mouseClicked(xCoord, yCoord, btn); - - } - - @Override - protected void handleMouseClick(final Slot slot, final int slotIdx, final int ctrlDown, final int mouseButton) { - if (mouseButton == 3) { - if (this.container.isCraftingMode() - && (slot instanceof OptionalSlotFake || slot instanceof SlotFakeCraftingMatrix - || slot instanceof SlotPatternTerm)) { - return; - } - } - super.handleMouseClick(slot, slotIdx, ctrlDown, mouseButton); - } - - @Override - protected String getBackground() { - if (this.container.isCraftingMode()) { - return "gui/pattern.png"; - } - return "gui/pattern2.png"; - } -} diff --git a/src/main/java/com/glodblock/github/client/gui/GuiFluidPatternTerminalEx.java b/src/main/java/com/glodblock/github/client/gui/GuiFluidPatternTerminalEx.java deleted file mode 100644 index 5cd0d1e8..00000000 --- a/src/main/java/com/glodblock/github/client/gui/GuiFluidPatternTerminalEx.java +++ /dev/null @@ -1,232 +0,0 @@ -package com.glodblock.github.client.gui; - -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.util.StatCollector; - -import org.lwjgl.input.Mouse; - -import com.glodblock.github.FluidCraft; -import com.glodblock.github.client.gui.base.FCGuiEncodeTerminal; -import com.glodblock.github.client.gui.container.ContainerFluidPatternExWireless; -import com.glodblock.github.client.gui.container.ContainerFluidPatternTerminalEx; -import com.glodblock.github.inventory.item.IWirelessTerminal; -import com.glodblock.github.network.CPacketFluidPatternTermBtns; -import com.glodblock.github.network.CPacketInventoryAction; -import com.glodblock.github.util.ModAndClassUtil; -import com.glodblock.github.util.NameConst; - -import appeng.api.config.ActionItems; -import appeng.api.config.ItemSubstitution; -import appeng.api.config.PatternBeSubstitution; -import appeng.api.config.PatternSlotConfig; -import appeng.api.config.Settings; -import appeng.api.storage.ITerminalHost; -import appeng.client.gui.widgets.GuiImgButton; -import appeng.helpers.InventoryAction; - -public class GuiFluidPatternTerminalEx extends FCGuiEncodeTerminal { - - public GuiFluidPatternTerminalEx(final InventoryPlayer inventoryPlayer, final ITerminalHost te) { - super(inventoryPlayer, te, new ContainerFluidPatternTerminalEx(inventoryPlayer, te)); - processingScrollBar.setHeight(70).setWidth(7).setLeft(6).setRange(0, 1, 1); - processingScrollBar.setTexture(FluidCraft.MODID, "gui/pattern3.png", 242, 0); - } - - public GuiFluidPatternTerminalEx(final InventoryPlayer inventoryPlayer, final IWirelessTerminal te) { - super(inventoryPlayer, te, new ContainerFluidPatternExWireless(inventoryPlayer, te)); - processingScrollBar.setHeight(70).setWidth(7).setLeft(6).setRange(0, 1, 1); - processingScrollBar.setTexture(FluidCraft.MODID, "gui/pattern3.png", 242, 0); - } - - @Override - public void initGui() { - super.initGui(); - - this.substitutionsEnabledBtn = new GuiImgButton( - this.guiLeft + 97, - this.guiTop + this.ySize - 163, - Settings.ACTIONS, - ItemSubstitution.ENABLED); - this.substitutionsEnabledBtn.setHalfSize(true); - this.buttonList.add(this.substitutionsEnabledBtn); - - this.substitutionsDisabledBtn = new GuiImgButton( - this.guiLeft + 97, - this.guiTop + this.ySize - 163, - Settings.ACTIONS, - ItemSubstitution.DISABLED); - this.substitutionsDisabledBtn.setHalfSize(true); - this.buttonList.add(this.substitutionsDisabledBtn); - - this.fluidPrioritizedEnabledBtn = new GuiFCImgButton( - this.guiLeft + 97, - this.guiTop + this.ySize - 114, - "FORCE_PRIO", - "DO_PRIO"); - this.fluidPrioritizedEnabledBtn.setHalfSize(true); - this.buttonList.add(this.fluidPrioritizedEnabledBtn); - - this.fluidPrioritizedDisabledBtn = new GuiFCImgButton( - this.guiLeft + 97, - this.guiTop + this.ySize - 114, - "NOT_PRIO", - "DONT_PRIO"); - this.fluidPrioritizedDisabledBtn.setHalfSize(true); - this.buttonList.add(this.fluidPrioritizedDisabledBtn); - - invertBtn = new GuiImgButton( - this.guiLeft + 87, - this.guiTop + this.ySize - 153, - Settings.ACTIONS, - container.inverted ? PatternSlotConfig.C_4_16 : PatternSlotConfig.C_16_4); - invertBtn.setHalfSize(true); - this.buttonList.add(this.invertBtn); - - this.clearBtn = new GuiImgButton( - this.guiLeft + 87, - this.guiTop + this.ySize - 163, - Settings.ACTIONS, - ActionItems.CLOSE); - this.clearBtn.setHalfSize(true); - this.buttonList.add(this.clearBtn); - - this.encodeBtn = new GuiImgButton( - this.guiLeft + 147, - this.guiTop + this.ySize - 142, - Settings.ACTIONS, - ActionItems.ENCODE); - this.buttonList.add(this.encodeBtn); - - if (ModAndClassUtil.isDoubleButton) { - this.doubleBtn = new GuiImgButton( - this.guiLeft + 97, - this.guiTop + this.ySize - 153, - Settings.ACTIONS, - ActionItems.DOUBLE); - this.doubleBtn.setHalfSize(true); - this.buttonList.add(this.doubleBtn); - } - - this.combineEnableBtn = new GuiFCImgButton( - this.guiLeft + 87, - this.guiTop + this.ySize - 114, - "FORCE_COMBINE", - "DO_COMBINE"); - this.combineEnableBtn.setHalfSize(true); - this.buttonList.add(this.combineEnableBtn); - - this.combineDisableBtn = new GuiFCImgButton( - this.guiLeft + 87, - this.guiTop + this.ySize - 114, - "NOT_COMBINE", - "DONT_COMBINE"); - this.combineDisableBtn.setHalfSize(true); - this.buttonList.add(this.combineDisableBtn); - if (ModAndClassUtil.isBeSubstitutionsButton) { - this.beSubstitutionsEnabledBtn = new GuiImgButton( - this.guiLeft + 87, - this.guiTop + this.ySize - 103, - Settings.ACTIONS, - PatternBeSubstitution.ENABLED); - this.beSubstitutionsEnabledBtn.setHalfSize(true); - this.buttonList.add(this.beSubstitutionsEnabledBtn); - - this.beSubstitutionsDisabledBtn = new GuiImgButton( - this.guiLeft + 87, - this.guiTop + this.ySize - 103, - Settings.ACTIONS, - PatternBeSubstitution.DISABLED); - this.beSubstitutionsDisabledBtn.setHalfSize(true); - this.buttonList.add(this.beSubstitutionsDisabledBtn); - } - processingScrollBar.setTop(this.ySize - 164); - } - - @Override - public void drawFG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) { - super.drawFG(offsetX, offsetY, mouseX, mouseY); - this.fontRendererObj.drawString( - StatCollector.translateToLocal(NameConst.GUI_FLUID_PATTERN_TERMINAL_EX), - 8, - this.ySize - 96 + 2 - getReservedSpace(), - 4210752); - this.processingScrollBar.draw(this); - } - - @Override - protected String getBackground() { - return container.inverted ? "gui/pattern4.png" : "gui/pattern3.png"; - } - - @Override - public void drawScreen(final int mouseX, final int mouseY, final float btn) { - final int offset = container.inverted ? 18 * -3 : 0; - substitutionsEnabledBtn.xPosition = this.guiLeft + 97 + offset; - substitutionsDisabledBtn.xPosition = this.guiLeft + 97 + offset; - beSubstitutionsEnabledBtn.xPosition = this.guiLeft + 97 + offset; - beSubstitutionsDisabledBtn.xPosition = this.guiLeft + 97 + offset; - fluidPrioritizedEnabledBtn.xPosition = this.guiLeft + 97 + offset; - fluidPrioritizedDisabledBtn.xPosition = this.guiLeft + 97 + offset; - doubleBtn.xPosition = this.guiLeft + 97 + offset; - clearBtn.xPosition = this.guiLeft + 87 + offset; - invertBtn.xPosition = this.guiLeft + 87 + offset; - combineEnableBtn.xPosition = this.guiLeft + 87 + offset; - combineDisableBtn.xPosition = this.guiLeft + 87 + offset; - processingScrollBar.setCurrentScroll(container.activePage); - super.drawScreen(mouseX, mouseY, btn); - } - - @Override - protected void mouseClicked(final int xCoord, final int yCoord, final int btn) { - final int currentScroll = this.processingScrollBar.getCurrentScroll(); - this.processingScrollBar.click(this, xCoord - this.guiLeft, yCoord - this.guiTop); - if (btn == 2 && doubleBtn.mousePressed(this.mc, xCoord, yCoord)) { // - InventoryAction action = InventoryAction.SET_PATTERN_MULTI; - - final CPacketInventoryAction p = new CPacketInventoryAction(action, 0, 0); - FluidCraft.proxy.netHandler.sendToServer(p); - } else super.mouseClicked(xCoord, yCoord, btn); - - if (currentScroll != this.processingScrollBar.getCurrentScroll()) { - changeActivePage(); - } - } - - @Override - protected void mouseClickMove(final int x, final int y, final int c, final long d) { - final int currentScroll = this.processingScrollBar.getCurrentScroll(); - this.processingScrollBar.click(this, x - this.guiLeft, y - this.guiTop); - super.mouseClickMove(x, y, c, d); - - if (currentScroll != this.processingScrollBar.getCurrentScroll()) { - changeActivePage(); - } - } - - @Override - public void handleMouseInput() { - super.handleMouseInput(); - final int wheel = Mouse.getEventDWheel(); - - if (wheel != 0) { - final int x = Mouse.getEventX() * this.width / this.mc.displayWidth; - final int y = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight; - - if (this.processingScrollBar.contains(x - this.guiLeft, y - this.guiTop)) { - final int currentScroll = this.processingScrollBar.getCurrentScroll(); - this.processingScrollBar.wheel(wheel); - - if (currentScroll != this.processingScrollBar.getCurrentScroll()) { - changeActivePage(); - } - } - } - } - - private void changeActivePage() { - FluidCraft.proxy.netHandler.sendToServer( - new CPacketFluidPatternTermBtns( - "PatternTerminal.ActivePage", - String.valueOf(this.processingScrollBar.getCurrentScroll()))); - } -} diff --git a/src/main/java/com/glodblock/github/client/gui/GuiFluidPatternWireless.java b/src/main/java/com/glodblock/github/client/gui/GuiFluidPatternWireless.java deleted file mode 100644 index 24d0c94c..00000000 --- a/src/main/java/com/glodblock/github/client/gui/GuiFluidPatternWireless.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.glodblock.github.client.gui; - -import net.minecraft.entity.player.InventoryPlayer; - -import com.glodblock.github.inventory.item.IWirelessTerminal; - -import appeng.container.slot.AppEngSlot; -import appeng.container.slot.SlotDisabled; - -public class GuiFluidPatternWireless extends GuiFluidPatternTerminal { - - public GuiFluidPatternWireless(InventoryPlayer inventoryPlayer, IWirelessTerminal te) { - super(inventoryPlayer, te); - } - - @Override - protected void repositionSlot(final AppEngSlot s) { - if (s instanceof SlotDisabled || s.isPlayerSide()) { - s.yDisplayPosition = s.getY() + this.ySize - 78 - 5; - } else { - s.yDisplayPosition = s.getY() + this.ySize - 78 - 3; - } - } -} diff --git a/src/main/java/com/glodblock/github/client/gui/GuiFluidPortableCell.java b/src/main/java/com/glodblock/github/client/gui/GuiFluidPortableCell.java deleted file mode 100644 index c3759a61..00000000 --- a/src/main/java/com/glodblock/github/client/gui/GuiFluidPortableCell.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.glodblock.github.client.gui; - -import net.minecraft.entity.player.InventoryPlayer; - -import com.glodblock.github.client.gui.container.ContainerFluidPortableCell; -import com.glodblock.github.inventory.item.IFluidPortableCell; -import com.glodblock.github.inventory.item.IWirelessTerminal; - -import appeng.container.slot.AppEngSlot; - -public class GuiFluidPortableCell extends GuiFluidTerminal { - - public GuiFluidPortableCell(final InventoryPlayer inventoryPlayer, final IFluidPortableCell te) { - super(inventoryPlayer, te, new ContainerFluidPortableCell(inventoryPlayer, te)); - } - - @Override - protected void repositionSlot(final AppEngSlot s) { - s.yDisplayPosition = s.getY() + this.ySize - 78 - 5; - } - - @Override - protected int getMaxRows() { - if (this.container.getHost() instanceof IWirelessTerminal) { - return super.getMaxRows(); - } else { - return 3; - } - } - - @Override - protected boolean isPortableCell() { - return true; - } -} diff --git a/src/main/java/com/glodblock/github/client/gui/GuiFluidStorageBus.java b/src/main/java/com/glodblock/github/client/gui/GuiFluidStorageBus.java deleted file mode 100644 index b1630e51..00000000 --- a/src/main/java/com/glodblock/github/client/gui/GuiFluidStorageBus.java +++ /dev/null @@ -1,104 +0,0 @@ -package com.glodblock.github.client.gui; - -import net.minecraft.client.gui.GuiButton; -import net.minecraft.client.resources.I18n; -import net.minecraft.entity.player.InventoryPlayer; - -import org.lwjgl.input.Mouse; - -import com.glodblock.github.FluidCraft; -import com.glodblock.github.client.gui.container.ContainerFluidStorageBus; -import com.glodblock.github.common.parts.PartFluidStorageBus; -import com.glodblock.github.inventory.InventoryHandler; -import com.glodblock.github.inventory.gui.GuiType; -import com.glodblock.github.network.CPacketFluidPatternTermBtns; -import com.glodblock.github.util.NameConst; - -import appeng.api.config.AccessRestriction; -import appeng.api.config.ActionItems; -import appeng.api.config.Settings; -import appeng.api.storage.data.IAEFluidStack; -import appeng.client.gui.implementations.GuiUpgradeable; -import appeng.client.gui.widgets.GuiImgButton; -import appeng.client.gui.widgets.GuiTabButton; -import appeng.core.localization.GuiColors; -import appeng.core.localization.GuiText; -import appeng.core.sync.network.NetworkHandler; -import appeng.core.sync.packets.PacketConfigButton; - -public class GuiFluidStorageBus extends GuiUpgradeable { - - private GuiImgButton rwMode; - private GuiTabButton priority; - private GuiImgButton partition; - private GuiImgButton clear; - - public GuiFluidStorageBus(InventoryPlayer inventoryPlayer, PartFluidStorageBus te) { - super(new ContainerFluidStorageBus(inventoryPlayer, te)); - this.ySize = 251; - } - - @Override - protected void addButtons() { - this.clear = new GuiImgButton(this.guiLeft - 18, this.guiTop + 8, Settings.ACTIONS, ActionItems.CLOSE); - this.partition = new GuiImgButton(this.guiLeft - 18, this.guiTop + 28, Settings.ACTIONS, ActionItems.WRENCH); - this.rwMode = new GuiImgButton( - this.guiLeft - 18, - this.guiTop + 48, - Settings.ACCESS, - AccessRestriction.READ_WRITE); - this.priority = new GuiTabButton( - this.guiLeft + 154, - this.guiTop, - 2 + 4 * 16, - GuiText.Priority.getLocal(), - itemRender); - - this.buttonList.add(this.priority); - this.buttonList.add(this.rwMode); - this.buttonList.add(this.partition); - this.buttonList.add(this.clear); - } - - @Override - public void drawFG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) { - this.fontRendererObj.drawString( - this.getGuiDisplayName(I18n.format(NameConst.GUI_FLUID_STORAGE_BUS)), - 8, - 6, - GuiColors.StorageBusTitle.getColor()); - this.fontRendererObj.drawString( - GuiText.inventory.getLocal(), - 8, - this.ySize - 96 + 3, - GuiColors.StorageBusInventory.getColor()); - - if (this.rwMode != null) { - this.rwMode.set(((ContainerFluidStorageBus) this.cvb).getReadWriteMode()); - } - } - - @Override - protected String getBackground() { - return "guis/storagebus.png"; - } - - @Override - protected void actionPerformed(final GuiButton btn) { - super.actionPerformed(btn); - final boolean backwards = Mouse.isButtonDown(1); - if (btn == this.partition) { - FluidCraft.proxy.netHandler.sendToServer(new CPacketFluidPatternTermBtns("StorageBus.Action", "Partition")); - } else if (btn == this.clear) { - FluidCraft.proxy.netHandler.sendToServer(new CPacketFluidPatternTermBtns("StorageBus.Action", "Clear")); - } else if (btn == this.priority) { - InventoryHandler.switchGui(GuiType.PRIORITY); - } else if (btn == this.rwMode) { - NetworkHandler.instance.sendToServer(new PacketConfigButton(this.rwMode.getSetting(), backwards)); - } - } - - public void update(int id, IAEFluidStack stack) { - ((ContainerFluidStorageBus) this.cvb).bus.setFluidInSlot(id, stack); - } -} diff --git a/src/main/java/com/glodblock/github/client/gui/GuiFluidTerminal.java b/src/main/java/com/glodblock/github/client/gui/GuiFluidTerminal.java deleted file mode 100644 index dd6bbc8b..00000000 --- a/src/main/java/com/glodblock/github/client/gui/GuiFluidTerminal.java +++ /dev/null @@ -1,127 +0,0 @@ -package com.glodblock.github.client.gui; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiButton; -import net.minecraft.client.renderer.texture.TextureMap; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; -import net.minecraft.util.IIcon; -import net.minecraftforge.fluids.Fluid; -import net.minecraftforge.fluids.FluidStack; - -import org.lwjgl.opengl.GL11; - -import com.glodblock.github.FluidCraft; -import com.glodblock.github.client.gui.container.ContainerFluidMonitor; -import com.glodblock.github.common.item.ItemFluidDrop; -import com.glodblock.github.inventory.InventoryHandler; -import com.glodblock.github.inventory.gui.GuiType; -import com.glodblock.github.network.CPacketFluidUpdate; -import com.glodblock.github.util.Util; - -import appeng.api.storage.ITerminalHost; -import appeng.api.storage.data.IAEFluidStack; -import appeng.api.storage.data.IAEItemStack; -import appeng.client.me.SlotME; -import appeng.container.slot.AppEngSlot; - -public class GuiFluidTerminal extends GuiFluidMonitor { - - protected EntityPlayer player; - public ContainerFluidMonitor container; - - public GuiFluidTerminal(InventoryPlayer inventoryPlayer, ITerminalHost te) { - super(inventoryPlayer, te, new ContainerFluidMonitor(inventoryPlayer, te)); - this.container = new ContainerFluidMonitor(inventoryPlayer, te); - this.player = inventoryPlayer.player; - this.showViewBtn = false; - } - - public GuiFluidTerminal(final InventoryPlayer inventoryPlayer, final ITerminalHost te, - final ContainerFluidMonitor c) { - super(inventoryPlayer, te, c); - this.container = c; - this.player = inventoryPlayer.player; - this.showViewBtn = false; - } - - @Override - protected void repositionSlot(final AppEngSlot s) { - if (s.isPlayerSide()) { - s.yDisplayPosition = s.getY() + this.ySize - 78 - 5; - } else { - s.yDisplayPosition = s.getY() + this.ySize - 78 - 3; - } - } - - @Override - protected void actionPerformed(final GuiButton btn) { - if (btn == craftingStatusBtn) { - InventoryHandler.switchGui(GuiType.CRAFTING_STATUS); - } else { - super.actionPerformed(btn); - } - } - - @Override - public void func_146977_a(final Slot s) { - if (drawSlot0(s)) super.func_146977_a(s); - } - - public boolean drawSlot0(Slot slot) { - if (slot instanceof SlotME) { - IAEItemStack stack = ((SlotME) slot).getAEStack(); - if (stack == null) return true; - FluidStack fluidStack = ItemFluidDrop.getFluidStack(slot.getStack()); - this.drawWidget(slot.xDisplayPosition, slot.yDisplayPosition, fluidStack.getFluid()); - aeRenderItem.setAeStack(stack); - GL11.glTranslatef(0.0f, 0.0f, 200.0f); - aeRenderItem.renderItemOverlayIntoGUI( - fontRendererObj, - mc.getTextureManager(), - stack.getItemStack(), - slot.xDisplayPosition, - slot.yDisplayPosition); - GL11.glTranslatef(0.0f, 0.0f, -200.0f); - return false; - } - return true; - } - - private void drawWidget(int posX, int posY, Fluid fluid) { - if (fluid == null) return; - IIcon icon = fluid.getIcon(); - if (icon == null) return; - - Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.locationBlocksTexture); - GL11.glDisable(GL11.GL_LIGHTING); - GL11.glEnable(GL11.GL_BLEND); - GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); - GL11.glColor3f( - (fluid.getColor() >> 16 & 0xFF) / 255.0F, - (fluid.getColor() >> 8 & 0xFF) / 255.0F, - (fluid.getColor() & 0xFF) / 255.0F); - drawTexturedModelRectFromIcon(posX, posY, icon, 16, 16); - GL11.glEnable(GL11.GL_LIGHTING); - GL11.glDisable(GL11.GL_BLEND); - GL11.glColor3f(1, 1, 1); - } - - @Override - protected void handleMouseClick(final Slot slot, final int slotIdx, final int ctrlDown, final int mouseButton) { - if (slot instanceof SlotME && Util.FluidUtil.isFluidContainer(player.inventory.getItemStack())) { - IAEFluidStack fluid = ItemFluidDrop.getAeFluidStack(((SlotME) slot).getAEStack()); - FluidCraft.proxy.netHandler.sendToServer(new CPacketFluidUpdate(fluid, isShiftKeyDown())); - } - if (mouseButton == 3 && slot instanceof SlotME) { - return; - } - super.handleMouseClick(slot, slotIdx, ctrlDown, mouseButton); - } - - public void update(ItemStack itemStack) { - this.player.inventory.setItemStack(itemStack); - } -} diff --git a/src/main/java/com/glodblock/github/client/gui/GuiInterfaceWireless.java b/src/main/java/com/glodblock/github/client/gui/GuiInterfaceWireless.java deleted file mode 100644 index e46adaf8..00000000 --- a/src/main/java/com/glodblock/github/client/gui/GuiInterfaceWireless.java +++ /dev/null @@ -1,107 +0,0 @@ -package com.glodblock.github.client.gui; - -import net.minecraft.client.gui.GuiButton; -import net.minecraft.entity.player.InventoryPlayer; - -import com.glodblock.github.client.gui.container.ContainerInterfaceWireless; -import com.glodblock.github.common.item.ItemWirelessUltraTerminal; -import com.glodblock.github.inventory.gui.GuiType; -import com.glodblock.github.inventory.item.IWirelessTerminal; -import com.glodblock.github.util.ModAndClassUtil; - -import appeng.client.gui.implementations.GuiInterfaceTerminal; - -public class GuiInterfaceWireless extends GuiInterfaceTerminal { - - protected GuiFCImgButton FluidTerminal; - protected GuiFCImgButton CraftingTerminal; - protected GuiFCImgButton PatternTerminal; - protected GuiFCImgButton EssentiaTerminal; - protected GuiFCImgButton InterfaceTerminal; - protected GuiFCImgButton LevelTerminal; - protected GuiFCImgButton PatternTerminalEx; - - public GuiInterfaceWireless(final InventoryPlayer inventoryPlayer, final IWirelessTerminal te) { - super(new ContainerInterfaceWireless(inventoryPlayer, te)); - } - - @Override - public void initGui() { - super.initGui(); - drawSwitchGuiBtns(); - } - - protected void drawSwitchGuiBtns() { - this.buttonList.add(this.CraftingTerminal = new GuiFCImgButton(this.guiLeft - 18, offsetY, "CRAFT_TEM", "YES")); - offsetY += 20; - - this.buttonList - .add(this.PatternTerminal = new GuiFCImgButton(this.guiLeft - 18, offsetY, "PATTERN_TEM", "YES")); - offsetY += 20; - - this.buttonList - .add(this.PatternTerminalEx = new GuiFCImgButton(this.guiLeft - 18, offsetY, "PATTERN_EX_TEM", "YES")); - offsetY += 20; - - this.buttonList.add(this.FluidTerminal = new GuiFCImgButton(this.guiLeft - 18, offsetY, "FLUID_TEM", "YES")); - offsetY += 20; - - this.buttonList.add(this.LevelTerminal = new GuiFCImgButton(this.guiLeft - 18, offsetY, "LEVEL_TEM", "YES")); - offsetY += 20; - - if (ModAndClassUtil.ThE) { - this.buttonList - .add(this.EssentiaTerminal = new GuiFCImgButton(this.guiLeft - 18, offsetY, "ESSENTIA_TEM", "YES")); - offsetY += 20; - } - } - - private boolean scheduleGuiResize; - - @Override - protected void mouseClicked(int xCoord, int yCoord, int btn) { - super.mouseClicked(xCoord, yCoord, btn); - if (scheduleGuiResize) { - // in the GuiScreen class, the implementation of super.mouseClicked - // ends up looping on the button list and execute the action for any - // button below the mouse. - // Therefore, if we initGui() the terminal in the actionPerformed method below - // it will run the actionPerformed a second time for the new button - // that will end up being below the mouse (if any) after the initGui() - buttonList.clear(); - initGui(); - scheduleGuiResize = false; - } - } - - protected final void scheduleGuiResize() { - scheduleGuiResize = true; - } - - @Override - protected void actionPerformed(final GuiButton btn) { - if (btn instanceof GuiFCImgButton) { - if (btn == this.FluidTerminal) { - ItemWirelessUltraTerminal.switchTerminal(this.mc.thePlayer, GuiType.WIRELESS_FLUID_TERMINAL); - } else if (btn == this.CraftingTerminal) { - ItemWirelessUltraTerminal.switchTerminal(this.mc.thePlayer, GuiType.WIRELESS_CRAFTING_TERMINAL); - } else if (btn == this.EssentiaTerminal) { - ItemWirelessUltraTerminal.switchTerminal(this.mc.thePlayer, GuiType.WIRELESS_ESSENTIA_TERMINAL); - } else if (btn == this.PatternTerminal) { - ItemWirelessUltraTerminal.switchTerminal(this.mc.thePlayer, GuiType.WIRELESS_FLUID_PATTERN_TERMINAL); - } else if (btn == this.InterfaceTerminal) { - ItemWirelessUltraTerminal.switchTerminal(this.mc.thePlayer, GuiType.WIRELESS_INTERFACE_TERMINAL); - } else if (btn == this.LevelTerminal) { - ItemWirelessUltraTerminal.switchTerminal(this.mc.thePlayer, GuiType.WIRELESS_LEVEL_TERMINAL); - } else if (btn == this.PatternTerminalEx) { - ItemWirelessUltraTerminal.switchTerminal(this.mc.thePlayer, GuiType.WIRELESS_FLUID_PATTERN_TERMINAL_EX); - } - } - - super.actionPerformed(btn); - - if (btn == this.terminalStyleBox) { - scheduleGuiResize(); - } - } -} diff --git a/src/main/java/com/glodblock/github/client/gui/GuiItemMonitor.java b/src/main/java/com/glodblock/github/client/gui/GuiItemMonitor.java deleted file mode 100644 index d2a41ec6..00000000 --- a/src/main/java/com/glodblock/github/client/gui/GuiItemMonitor.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.glodblock.github.client.gui; - -import java.util.List; - -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.item.ItemStack; - -import com.glodblock.github.client.gui.base.FCGuiMonitor; -import com.glodblock.github.client.gui.container.ContainerItemMonitor; - -import appeng.api.storage.ITerminalHost; -import appeng.api.storage.data.IAEItemStack; -import appeng.client.me.ItemRepo; -import appeng.core.localization.GuiText; - -public class GuiItemMonitor extends FCGuiMonitor { - - public GuiItemMonitor(final InventoryPlayer inventoryPlayer, final ITerminalHost te, final ContainerItemMonitor c) { - super(inventoryPlayer, te, c); - this.repo = new ItemRepo(getScrollBar(), this); - } - - @Override - public void postUpdate(final List list, boolean resort) { - for (final IAEItemStack is : list) { - this.repo.postUpdate(is); - } - if (resort) { - this.repo.updateView(); - } - this.setScrollBar(); - } - - @Override - public void drawFG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) { - this.fontRendererObj.drawString(this.getGuiDisplayName(GuiText.Terminal.getLocal()), 8, 6, 4210752); - this.fontRendererObj.drawString(GuiText.inventory.getLocal(), 8, this.ySize - 96 + 3, 4210752); - super.drawFG(offsetX, offsetY, mouseX, mouseY); - } - - @Override - public void setTextFieldValue(String displayName, int mousex, int mousey, ItemStack stack) { - setSearchString(displayName, true); - } -} diff --git a/src/main/java/com/glodblock/github/client/gui/GuiLevelEmitterProxy.java b/src/main/java/com/glodblock/github/client/gui/GuiLevelEmitterProxy.java index 4a747ee0..bbc4c059 100644 --- a/src/main/java/com/glodblock/github/client/gui/GuiLevelEmitterProxy.java +++ b/src/main/java/com/glodblock/github/client/gui/GuiLevelEmitterProxy.java @@ -2,103 +2,47 @@ package com.glodblock.github.client.gui; import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.item.ItemStack; -import net.minecraftforge.common.util.ForgeDirection; -import com.glodblock.github.FluidCraft; -import com.glodblock.github.common.item.ItemWirelessUltraTerminal; -import com.glodblock.github.common.parts.PartLevelTerminal; -import com.glodblock.github.inventory.gui.GuiType; -import com.glodblock.github.inventory.item.IWirelessTerminal; -import com.glodblock.github.inventory.item.WirelessLevelTerminalInventory; -import com.glodblock.github.loader.ItemAndBlockHolder; -import com.glodblock.github.network.CPacketLevelTerminalCommands; -import com.glodblock.github.util.Util; - -import appeng.api.util.DimensionalCoord; +import appeng.api.parts.ILevelEmitter; +import appeng.client.gui.IGuiSub; import appeng.client.gui.implementations.GuiLevelEmitter; import appeng.client.gui.widgets.GuiTabButton; -import appeng.container.AEBaseContainer; -import appeng.parts.automation.PartLevelEmitter; +import appeng.container.interfaces.IContainerSubGui; +import appeng.core.sync.network.NetworkHandler; +import appeng.core.sync.packets.PacketSwitchGuis; -public class GuiLevelEmitterProxy extends GuiLevelEmitter { +public class GuiLevelEmitterProxy extends GuiLevelEmitter implements IGuiSub { - protected GuiType originalGui; - protected Util.DimensionalCoordSide originalBlockPos; - protected ItemStack originalGuiIcon; - protected GuiTabButton originalGuiBtn; + protected final IContainerSubGui container; + protected GuiTabButton originalGuiBtn;; - public GuiLevelEmitterProxy(final InventoryPlayer inventoryPlayer, final PartLevelEmitter te) { + public GuiLevelEmitterProxy(final InventoryPlayer inventoryPlayer, final ILevelEmitter te) { super(inventoryPlayer, te); - - if (inventoryPlayer.player.openContainer instanceof AEBaseContainer container) { - var target = container.getTarget(); - if (target instanceof PartLevelTerminal terminal) { - originalGuiIcon = ItemAndBlockHolder.LEVEL_TERMINAL.stack(); - originalGui = GuiType.LEVEL_TERMINAL; - DimensionalCoord blockPos = new DimensionalCoord(terminal.getTile()); - originalBlockPos = new Util.DimensionalCoordSide( - blockPos.x, - blockPos.y, - blockPos.z, - blockPos.getDimension(), - terminal.getSide(), - ""); - } else if (target instanceof IWirelessTerminal terminal && terminal.isUniversal(target)) { - originalGuiIcon = ItemAndBlockHolder.WIRELESS_ULTRA_TERM.stack(); - originalGui = ItemWirelessUltraTerminal.readMode(terminal.getItemStack()); - originalBlockPos = new Util.DimensionalCoordSide( - terminal.getInventorySlot(), - Util.GuiHelper.encodeType(0, Util.GuiHelper.GuiType.ITEM), - 0, - inventoryPlayer.player.worldObj.provider.dimensionId, - ForgeDirection.UNKNOWN, - ""); - } else if (target instanceof WirelessLevelTerminalInventory terminal) { - originalGuiIcon = ItemAndBlockHolder.WIRELESS_LEVEL_TERM.stack(); - originalGui = GuiType.WIRELESS_LEVEL_TERMINAL; - originalBlockPos = new Util.DimensionalCoordSide( - terminal.getInventorySlot(), - Util.GuiHelper.encodeType(0, Util.GuiHelper.GuiType.ITEM), - 0, - inventoryPlayer.player.worldObj.provider.dimensionId, - ForgeDirection.UNKNOWN, - ""); - - } - } + this.container = (IContainerSubGui) inventorySlots; + this.container.setGuiLink(this); } @Override public void initGui() { super.initGui(); + if (container.getPrimaryGuiIcon() != null) initPrimaryGuiButton(); + } - if (this.originalGuiIcon != null) { - this.originalGuiBtn = new GuiTabButton( - this.guiLeft + 151, - this.guiTop - 4, - this.originalGuiIcon, - this.originalGuiIcon.getDisplayName(), - itemRender); - this.originalGuiBtn.setHideEdge(13); - this.buttonList.add(originalGuiBtn); - } + public void initPrimaryGuiButton() { + this.buttonList.add( + this.originalGuiBtn = new GuiTabButton( + this.guiLeft + this.xSize - 57, + this.guiTop, + container.getPrimaryGuiIcon(), + container.getPrimaryGuiIcon().getDisplayName(), + itemRender)); } @Override protected void actionPerformed(GuiButton btn) { + super.actionPerformed(btn); if (btn == this.originalGuiBtn) { - CPacketLevelTerminalCommands message = new CPacketLevelTerminalCommands( - CPacketLevelTerminalCommands.Action.BACK, - originalBlockPos.x, - originalBlockPos.y, - originalBlockPos.z, - originalBlockPos.getDimension(), - originalBlockPos.getSide()); - message.setOriginalGui(originalGui.ordinal()); - FluidCraft.proxy.netHandler.sendToServer(message); - } else { - super.actionPerformed(btn); + NetworkHandler.instance.sendToServer(new PacketSwitchGuis()); } } } diff --git a/src/main/java/com/glodblock/github/client/gui/GuiLevelMaintainer.java b/src/main/java/com/glodblock/github/client/gui/GuiLevelMaintainer.java index 2c3af402..c56bcd65 100644 --- a/src/main/java/com/glodblock/github/client/gui/GuiLevelMaintainer.java +++ b/src/main/java/com/glodblock/github/client/gui/GuiLevelMaintainer.java @@ -2,61 +2,36 @@ package com.glodblock.github.client.gui; import java.text.NumberFormat; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; -import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; import net.minecraft.util.StatCollector; -import net.minecraftforge.common.util.ForgeDirection; import org.jetbrains.annotations.Nullable; import org.lwjgl.input.Keyboard; -import org.lwjgl.opengl.GL11; import com.glodblock.github.FluidCraft; -import com.glodblock.github.api.registries.LevelState; import com.glodblock.github.client.gui.container.ContainerLevelMaintainer; -import com.glodblock.github.common.item.ItemWirelessUltraTerminal; -import com.glodblock.github.common.parts.PartLevelTerminal; import com.glodblock.github.common.tile.TileLevelMaintainer; -import com.glodblock.github.inventory.gui.GuiType; import com.glodblock.github.inventory.gui.MouseRegionManager; -import com.glodblock.github.inventory.item.IWirelessTerminal; -import com.glodblock.github.inventory.item.WirelessLevelTerminalInventory; -import com.glodblock.github.inventory.slot.SlotFluidConvertingFake; -import com.glodblock.github.inventory.slot.SlotSingleItem; -import com.glodblock.github.loader.ItemAndBlockHolder; import com.glodblock.github.network.CPacketLevelMaintainer; import com.glodblock.github.network.CPacketLevelMaintainer.Action; -import com.glodblock.github.network.CPacketLevelTerminalCommands; import com.glodblock.github.util.FCGuiColors; import com.glodblock.github.util.NameConst; -import com.glodblock.github.util.Util; -import appeng.api.storage.data.IAEItemStack; -import appeng.api.util.DimensionalCoord; -import appeng.client.gui.AEBaseGui; +import appeng.api.features.LevelState; +import appeng.api.storage.data.IAEStack; +import appeng.client.gui.GuiSub; +import appeng.client.gui.slots.VirtualMEPhantomSlot; import appeng.client.gui.widgets.GuiTabButton; -import appeng.container.AEBaseContainer; -import appeng.container.slot.SlotFake; -import appeng.core.sync.network.NetworkHandler; -import appeng.core.sync.packets.PacketNEIDragClick; import appeng.util.calculators.ArithHelper; import appeng.util.calculators.Calculator; -import codechicken.nei.VisiblityData; -import codechicken.nei.api.INEIGuiHandler; -import codechicken.nei.api.TaggedInventoryArea; import cofh.core.render.CoFHFontRenderer; -import cpw.mods.fml.common.Optional; -@Optional.Interface(modid = "NotEnoughItems", iface = "codechicken.nei.api.INEIGuiHandler") -public class GuiLevelMaintainer extends AEBaseGui implements INEIGuiHandler { +public class GuiLevelMaintainer extends GuiSub { private static final ResourceLocation TEX_BG = FluidCraft.resource("textures/gui/level_maintainer.png"); private final ContainerLevelMaintainer cont; @@ -64,11 +39,6 @@ public class GuiLevelMaintainer extends AEBaseGui implements INEIGuiHandler { private final MouseRegionManager mouseRegions = new MouseRegionManager(this); private Widget focusedWidget; private final CoFHFontRenderer render; - protected ItemStack icon = null; - - protected GuiType originalGui; - protected Util.DimensionalCoordSide originalBlockPos; - protected GuiTabButton originalGuiBtn; public GuiLevelMaintainer(InventoryPlayer ipl, TileLevelMaintainer tile) { super(new ContainerLevelMaintainer(ipl, tile)); @@ -80,48 +50,23 @@ public class GuiLevelMaintainer extends AEBaseGui implements INEIGuiHandler { TEX_BG, Minecraft.getMinecraft().getTextureManager(), true); - - if (ipl.player.openContainer instanceof AEBaseContainer container) { - var target = container.getTarget(); - if (target instanceof PartLevelTerminal terminal) { - icon = ItemAndBlockHolder.LEVEL_TERMINAL.stack(); - originalGui = GuiType.LEVEL_TERMINAL; - DimensionalCoord blockPos = new DimensionalCoord(terminal.getTile()); - originalBlockPos = new Util.DimensionalCoordSide( - blockPos.x, - blockPos.y, - blockPos.z, - blockPos.getDimension(), - terminal.getSide(), - ""); - } else if (target instanceof IWirelessTerminal terminal && terminal.isUniversal(target)) { - icon = ItemAndBlockHolder.WIRELESS_ULTRA_TERM.stack(); - originalGui = ItemWirelessUltraTerminal.readMode(terminal.getItemStack()); - originalBlockPos = new Util.DimensionalCoordSide( - terminal.getInventorySlot(), - Util.GuiHelper.encodeType(0, Util.GuiHelper.GuiType.ITEM), - 0, - ipl.player.worldObj.provider.dimensionId, - ForgeDirection.UNKNOWN, - ""); - } else if (target instanceof WirelessLevelTerminalInventory terminal) { - icon = ItemAndBlockHolder.WIRELESS_LEVEL_TERM.stack(); - originalGui = GuiType.WIRELESS_LEVEL_TERMINAL; - originalBlockPos = new Util.DimensionalCoordSide( - terminal.getInventorySlot(), - Util.GuiHelper.encodeType(0, Util.GuiHelper.GuiType.ITEM), - 0, - ipl.player.worldObj.provider.dimensionId, - ForgeDirection.UNKNOWN, - ""); - - } - } } @Override public void initGui() { super.initGui(); + + for (int i = 0; i < TileLevelMaintainer.REQ_COUNT; i++) { + VirtualMEPhantomSlot slot = new VirtualMEPhantomSlot( + 27, + 20 + i * 19, + this.cont.getTile().getAEStackInventory(), + i); + slot.setShowAmount(true); + slot.setShowAmountAlways(true); + this.registerVirtualSlots(slot); + } + for (int i = 0; i < TileLevelMaintainer.REQ_COUNT; i++) { component[i] = new Component( new Widget( @@ -141,16 +86,18 @@ public class GuiLevelMaintainer extends AEBaseGui implements INEIGuiHandler { this.buttonList, this.cont); } - if (this.icon != null) { - this.originalGuiBtn = new GuiTabButton( - this.guiLeft + 151, - this.guiTop - 4, - this.icon, - this.icon.getDisplayName(), - itemRender); - this.originalGuiBtn.setHideEdge(13); - this.buttonList.add(originalGuiBtn); - } + } + + @Override + public void initPrimaryGuiButton() { + this.originalGuiBtn = new GuiTabButton( + this.guiLeft + 151, + this.guiTop - 4, + this.cont.getPrimaryGuiIcon(), + this.cont.getPrimaryGuiIcon().getDisplayName(), + itemRender); + this.originalGuiBtn.setHideEdge(13); + this.buttonList.add(originalGuiBtn); } @Override @@ -179,36 +126,6 @@ public class GuiLevelMaintainer extends AEBaseGui implements INEIGuiHandler { mouseRegions.render(mouseX, mouseY); } - @Override - public void func_146977_a(final Slot s) { - if (drawSlot0(s)) super.func_146977_a(s); - } - - public boolean drawSlot0(Slot slot) { - if (slot instanceof SlotFake) { - IAEItemStack stack = ((SlotFluidConvertingFake) slot).getAeStack(); - super.func_146977_a(new SlotSingleItem(slot)); - if (stack == null) return true; - IAEItemStack fake = stack.copy(); - - Widget qty = this.component[slot.getSlotIndex()].getQty(); - qty.validate(); - fake.setStackSize(qty.getAmount() != null ? qty.getAmount() : 0); - - GL11.glTranslatef(0.0f, 0.0f, 200.0f); - aeRenderItem.setAeStack(fake); - aeRenderItem.renderItemOverlayIntoGUI( - fontRendererObj, - mc.getTextureManager(), - fake.getItemStack(), - slot.xDisplayPosition, - slot.yDisplayPosition); - GL11.glTranslatef(0.0f, 0.0f, -200.0f); - return false; - } - return true; - } - @Override protected void mouseClicked(final int xCoord, final int yCoord, final int btn) { if (btn == 0) { @@ -253,83 +170,12 @@ public class GuiLevelMaintainer extends AEBaseGui implements INEIGuiHandler { @Override protected void actionPerformed(final GuiButton btn) { - if (btn == originalGuiBtn) { - switchGui(); - } else { - super.actionPerformed(btn); - for (Component com : this.component) { - if (com.sendToServer(btn)) { - break; - } + for (Component com : this.component) { + if (com.sendToServer(btn)) { + return; } } - } - - public void switchGui() { - CPacketLevelTerminalCommands message = new CPacketLevelTerminalCommands( - CPacketLevelTerminalCommands.Action.BACK, - originalBlockPos.x, - originalBlockPos.y, - originalBlockPos.z, - originalBlockPos.getDimension(), - originalBlockPos.getSide()); - if (originalGui != null) { - message.setOriginalGui(originalGui.ordinal()); - } - FluidCraft.proxy.netHandler.sendToServer(message); - } - - @Override - public VisiblityData modifyVisiblity(GuiContainer gui, VisiblityData currentVisibility) { - return currentVisibility; - } - - @Override - public Iterable getItemSpawnSlots(GuiContainer gui, ItemStack item) { - return Collections.emptyList(); - } - - @Override - public List getInventoryAreas(GuiContainer gui) { - return null; - } - - @Override - protected void handleMouseClick(Slot slot, int slotIdx, int ctrlDown, int mouseButton) { - if (slot instanceof SlotFluidConvertingFake && this.cont.getPlayerInv().getItemStack() == null) { - slot.putStack(null); - this.component[slot.getSlotIndex()].reset(); - } - super.handleMouseClick(slot, slotIdx, ctrlDown, mouseButton); - } - - @Override - public boolean handleDragNDrop(GuiContainer gui, int mouseX, int mouseY, ItemStack draggedStack, int button) { - if (draggedStack == null) { - return false; - } - - draggedStack.stackSize = 0; - Slot slotAtPosition = this.getSlotAtPosition(mouseX, mouseY); - if (slotAtPosition == null) { - return false; - } - - for (int i = 0; i < this.cont.getRequestSlots().length; i++) { - SlotFluidConvertingFake slot = this.cont.getRequestSlots()[i]; - if (slotAtPosition.equals(slot)) { - slot.putStack(draggedStack); - component[i].reset(); - NetworkHandler.instance.sendToServer(new PacketNEIDragClick(draggedStack, slot.getSlotIndex())); - return true; - } - } - return false; - } - - @Override - public boolean hideItemPanelSlot(GuiContainer gui, int x, int y, int w, int h) { - return false; + super.actionPerformed(btn); } public void updateComponent(int index, long quantity, long batchSize, boolean isEnabled, LevelState state) { @@ -383,8 +229,12 @@ public class GuiLevelMaintainer extends AEBaseGui implements INEIGuiHandler { this.isEnable = enable; } + public IAEStack getStack() { + return this.container.getTile().getAEStackInventory().getAEStackInSlot(this.getIndex()); + } + private void send(Widget widget) { - if (cont.inventorySlots.get(widget.componentIndex).getHasStack() && widget.getAmount() != null) { + if (this.getStack() != null && widget.getAmount() != null) { FluidCraft.proxy.netHandler.sendToServer( new CPacketLevelMaintainer(widget.action, widget.componentIndex, widget.getAmount())); } @@ -416,7 +266,7 @@ public class GuiLevelMaintainer extends AEBaseGui implements INEIGuiHandler { FluidCraft.proxy.netHandler.sendToServer(new CPacketLevelMaintainer(Action.Enable, this.getIndex())); didSomething = true; } else if (this.disable == btn) { - if (this.container.getInventory().get(this.getIndex()) != null) { + if (this.getStack() != null) { this.setEnable(true); FluidCraft.proxy.netHandler .sendToServer(new CPacketLevelMaintainer(Action.Disable, this.getIndex())); @@ -525,15 +375,6 @@ public class GuiLevelMaintainer extends AEBaseGui implements INEIGuiHandler { public void setState(LevelState state) { this.state = state; } - - public void reset() { - this.qty.textField.setText("0"); - this.batch.textField.setText("0"); - this.qty.validate(); - this.batch.validate(); - this.setEnable(false); - this.setState(LevelState.None); - } } private class Widget { @@ -592,6 +433,12 @@ public class GuiLevelMaintainer extends AEBaseGui implements INEIGuiHandler { this.amount = (long) ArithHelper.round(result, 0); this.textField.setTextColor(0xFFFFFF); } + + IAEStack stack = component[this.componentIndex].getStack(); + if (stack != null) { + Long amount = component[this.componentIndex].getQty().getAmount(); + stack.setStackSize(amount != null ? amount : 0); + } } @Nullable diff --git a/src/main/java/com/glodblock/github/client/gui/GuiLevelTerminal.java b/src/main/java/com/glodblock/github/client/gui/GuiLevelTerminal.java index 2d1aa548..c4a3cebd 100644 --- a/src/main/java/com/glodblock/github/client/gui/GuiLevelTerminal.java +++ b/src/main/java/com/glodblock/github/client/gui/GuiLevelTerminal.java @@ -1,7 +1,5 @@ package com.glodblock.github.client.gui; -import static com.glodblock.github.common.item.ItemWirelessUltraTerminal.hasInfinityBoosterCard; - import java.text.NumberFormat; import java.util.ArrayList; import java.util.Arrays; @@ -35,16 +33,10 @@ import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL12; import com.glodblock.github.FluidCraft; -import com.glodblock.github.api.registries.LevelItemInfo; -import com.glodblock.github.api.registries.LevelState; import com.glodblock.github.client.gui.base.FCBaseMEGui; import com.glodblock.github.client.gui.container.ContainerLevelTerminal; -import com.glodblock.github.inventory.InventoryHandler; -import com.glodblock.github.inventory.gui.GuiType; -import com.glodblock.github.network.CPacketInventoryAction; import com.glodblock.github.network.CPacketLevelTerminalCommands; import com.glodblock.github.network.CPacketLevelTerminalCommands.Action; -import com.glodblock.github.network.CPacketRenamer; import com.glodblock.github.network.SPacketLevelTerminalUpdate; import com.glodblock.github.util.FCGuiColors; import com.glodblock.github.util.ModAndClassUtil; @@ -55,7 +47,10 @@ import appeng.api.config.Settings; import appeng.api.config.TerminalFontSize; import appeng.api.config.TerminalStyle; import appeng.api.config.YesNo; +import appeng.api.features.LevelItemInfo; +import appeng.api.features.LevelState; import appeng.api.storage.ITerminalHost; +import appeng.api.storage.data.IAEStack; import appeng.client.gui.IGuiTooltipHandler; import appeng.client.gui.widgets.GuiImgButton; import appeng.client.gui.widgets.GuiScrollbar; @@ -70,12 +65,14 @@ import appeng.core.localization.ButtonToolTips; import appeng.core.localization.GuiColors; import appeng.core.localization.GuiText; import appeng.core.localization.PlayerMessages; +import appeng.core.sync.GuiBridge; +import appeng.core.sync.network.NetworkHandler; +import appeng.core.sync.packets.PacketSwitchGuis; import appeng.helpers.InventoryAction; import appeng.integration.IntegrationRegistry; import appeng.integration.IntegrationType; import appeng.util.Platform; import appeng.util.ReadableNumberConverter; -import appeng.util.item.AEItemStack; import cpw.mods.fml.common.Loader; public class GuiLevelTerminal extends FCBaseMEGui implements IDropToFillTextField, IGuiTooltipHandler { @@ -86,7 +83,6 @@ public class GuiLevelTerminal extends FCBaseMEGui implements IDropToFillTextFiel public static final int VIEW_LEFT = 8; private static final ResourceLocation TEX_BG = FluidCraft.resource("textures/gui/level_terminal.png"); private static final RenderItem renderItem = new RenderItem(); - protected int offsetY; private static final int offsetX = 21; protected static String searchFieldOutputsText = ""; protected static String searchFieldNamesText = ""; @@ -147,16 +143,6 @@ public class GuiLevelTerminal extends FCBaseMEGui implements IDropToFillTextFiel this(inventoryPlayer, new ContainerLevelTerminal(inventoryPlayer, te)); } - @Override - public int getOffsetY() { - return offsetY; - } - - @Override - public void setOffsetY(int y) { - offsetY = y; - } - private void setScrollBar() { int maxScroll = masterList.getHeight() - viewHeight - 1; if (maxScroll <= 0) { @@ -174,7 +160,7 @@ public class GuiLevelTerminal extends FCBaseMEGui implements IDropToFillTextFiel final int unusedSpace = height - ySize; guiTop = (int) Math.floor(unusedSpace / (unusedSpace < 0 ? 3.8f : 2.0f)); - offsetY = guiTop + 8; + int offsetY = guiTop + 8; terminalStyleBox = new GuiImgButton( guiLeft - 18, offsetY, @@ -213,7 +199,7 @@ public class GuiLevelTerminal extends FCBaseMEGui implements IDropToFillTextFiel setScrollBar(); repositionSlots(); - initGuiDone(); + initCustomButtons(0, offsetY); } @Override @@ -274,12 +260,6 @@ public class GuiLevelTerminal extends FCBaseMEGui implements IDropToFillTextFiel public void drawScreen(final int mouseX, final int mouseY, final float btn) { terminalStyleBox.set(AEConfig.instance.settings.getSetting(Settings.TERMINAL_STYLE)); - buttonList.clear(); - buttonList.add(terminalStyleBox); - buttonList.add(searchStringSave); - buttonList.add(craftingStatusBtn); - addSwitchGuiBtns(); - super.drawScreen(mouseX, mouseY, btn); handleTooltip(mouseX, mouseY, searchFieldOutputs); @@ -309,7 +289,8 @@ public class GuiLevelTerminal extends FCBaseMEGui implements IDropToFillTextFiel @Override protected void actionPerformed(final GuiButton btn) { - if (ModAndClassUtil.isSaveText && btn == searchStringSave) { + if (actionPerformedCustomButtons(btn)) return; + if (ModAndClassUtil.isSaveText && btn == searchStringSave) { final boolean backwards = Mouse.isButtonDown(1); final GuiImgButton iBtn = (GuiImgButton) btn; @@ -320,7 +301,7 @@ public class GuiLevelTerminal extends FCBaseMEGui implements IDropToFillTextFiel searchStringSave.set(next); } else if (btn == craftingStatusBtn) { - InventoryHandler.switchGui(GuiType.CRAFTING_STATUS); + NetworkHandler.instance.sendToServer(new PacketSwitchGuis(GuiBridge.GUI_CRAFTING_STATUS)); } else if (btn instanceof final GuiImgButton iBtn) { if (iBtn.getSetting() != Settings.ACTIONS) { final Enum cv = iBtn.getCurrentValue(); @@ -521,7 +502,7 @@ public class GuiLevelTerminal extends FCBaseMEGui implements IDropToFillTextFiel entry.renameButton.yPosition = viewY + 1; entry.configButton.yPosition = viewY + 1; GuiFCImgButton toRender; - if (isCtrlKeyDown() && isShiftKeyDown() && hasInfinityBoosterCard(player)) { + if (isCtrlKeyDown() && isShiftKeyDown()) { toRender = entry.configButton; } else if (isShiftKeyDown()) { toRender = entry.renameButton; @@ -561,7 +542,7 @@ public class GuiLevelTerminal extends FCBaseMEGui implements IDropToFillTextFiel && relMouseY >= Math.max(viewY + rowYTop, LevelTerminalSection.TITLE_HEIGHT) && relMouseY < Math.min(viewY + rowYBot, viewHeight); if (info != null) { - ItemStack itemStack = info.stack; + IAEStack aes = info.stack; long quantity = info.quantity; long batch = info.batchSize; LevelState state = info.state; @@ -570,10 +551,10 @@ public class GuiLevelTerminal extends FCBaseMEGui implements IDropToFillTextFiel GL11.glTranslatef(colLeft, viewY + rowYTop + 1, ITEM_STACK_Z); GL11.glEnable(GL12.GL_RESCALE_NORMAL); RenderHelper.enableGUIStandardItemLighting(); - itemStack.stackSize = 0; + aes.setStackSize(1); renderItem.zLevel = ITEM_STACK_Z - MAGIC_RENDER_ITEM_Z; - renderItem.renderItemAndEffectIntoGUI(fontRendererObj, mc.getTextureManager(), itemStack, 0, 0); - renderItem.renderItemOverlayIntoGUI(fontRendererObj, mc.getTextureManager(), itemStack, 0, 0); + aes.drawInGui(mc, 0, 0); + aes.drawOverlayInGui(mc, 0, 0, false, false, false, false); GL11.glTranslatef(0.0f, 0.0f, ITEM_STACK_OVERLAY_Z - ITEM_STACK_Z); int color = switch (state) { case Idle -> FCGuiColors.StateIdle.getColor(); @@ -601,7 +582,7 @@ public class GuiLevelTerminal extends FCBaseMEGui implements IDropToFillTextFiel drawRect(0, 0, 16, 16, GuiColors.ItemSlotOverlayUnpowered.getColor()); } } else { - tooltipStack = itemStack; + tooltipStack = Platform.stackConvert(aes).getItemStack(); } GL11.glPopMatrix(); } else if (entry.filteredRecipes[slotIdx]) { @@ -1122,7 +1103,9 @@ public class GuiLevelTerminal extends FCBaseMEGui implements IDropToFillTextFiel continue; } - if (itemStackMatchesSearchTerm(entry.infoList[i].stack, output)) { + if (itemStackMatchesSearchTerm( + Platform.stackConvert(entry.infoList[i].stack).getItemStack(), + output)) { shouldAdd = true; entry.filteredRecipes[i] = false; } else { @@ -1252,12 +1235,14 @@ public class GuiLevelTerminal extends FCBaseMEGui implements IDropToFillTextFiel blockPos.getSide())); } else if (isShiftKeyDown()) { FluidCraft.proxy.netHandler.sendToServer( - new CPacketRenamer( + new CPacketLevelTerminalCommands( + Action.RENAME, blockPos.x, blockPos.y, blockPos.z, blockPos.getDimension(), blockPos.getSide())); + } else { BlockPosHighlighter.highlightBlocks( mc.thePlayer, @@ -1294,9 +1279,10 @@ public class GuiLevelTerminal extends FCBaseMEGui implements IDropToFillTextFiel }; if (action != null && this.infoList[slotIdx] != null) { - AEItemStack aeStack = AEItemStack.create(this.infoList[slotIdx].stack); + IAEStack aeStack = this.infoList[slotIdx].stack; ((AEBaseContainer) inventorySlots).setTargetStack(aeStack); - FluidCraft.proxy.netHandler.sendToServer(new CPacketInventoryAction(action, slotIdx, 0, aeStack)); + // FluidCraft.proxy.netHandler.sendToServer(new CPacketInventoryAction(action, slotIdx, 0, + // aeStack)); } return true; diff --git a/src/main/java/com/glodblock/github/client/gui/GuiMagnetFilter.java b/src/main/java/com/glodblock/github/client/gui/GuiMagnetFilter.java index 4621e1c6..d78b4bd7 100644 --- a/src/main/java/com/glodblock/github/client/gui/GuiMagnetFilter.java +++ b/src/main/java/com/glodblock/github/client/gui/GuiMagnetFilter.java @@ -8,8 +8,6 @@ import org.lwjgl.input.Keyboard; import com.glodblock.github.FluidCraft; import com.glodblock.github.client.gui.container.ContainerMagnetFilter; -import com.glodblock.github.common.item.ItemWirelessUltraTerminal; -import com.glodblock.github.inventory.InventoryHandler; import com.glodblock.github.inventory.item.WirelessMagnet; import com.glodblock.github.network.CPacketFluidPatternTermBtns; import com.glodblock.github.util.NameConst; @@ -17,12 +15,11 @@ import com.glodblock.github.util.NameConst; import appeng.api.config.ActionItems; import appeng.api.config.Settings; import appeng.api.storage.ITerminalHost; -import appeng.client.gui.AEBaseMEGui; +import appeng.client.gui.GuiSub; import appeng.client.gui.widgets.GuiImgButton; -import appeng.client.gui.widgets.GuiTabButton; import appeng.client.gui.widgets.MEGuiTextField; -public class GuiMagnetFilter extends AEBaseMEGui { +public class GuiMagnetFilter extends GuiSub { protected FCGuiBaseButton listModeBtn; protected ContainerMagnetFilter cont; @@ -30,12 +27,11 @@ public class GuiMagnetFilter extends AEBaseMEGui { protected Component[] components = new Component[4]; protected MEGuiTextField oreDict; - protected GuiTabButton originalGuiBtn; protected GuiImgButton clearBtn; public GuiMagnetFilter(InventoryPlayer ip, ITerminalHost container) { super(new ContainerMagnetFilter(ip, container)); - this.xSize = 195; + this.xSize = 176; this.ySize = 214; this.cont = (ContainerMagnetFilter) this.inventorySlots; oreDict = new MEGuiTextField(149, 12, NameConst.i18n(NameConst.TT_MAGNET_CARD_OREDICT)); @@ -45,10 +41,10 @@ public class GuiMagnetFilter extends AEBaseMEGui { private final GuiFCImgButton enable; private final GuiFCImgButton disable; - private final String action; + private final CPacketFluidPatternTermBtns.Command action; private boolean var; - public Component(int x, int y, boolean var, String action) { + public Component(int x, int y, boolean var, CPacketFluidPatternTermBtns.Command action) { this.enable = new GuiFCImgButton(x, y, "ENABLE_12x", "ENABLE", false); this.disable = new GuiFCImgButton(x, y, "DISABLE_12x", "DISABLE", false); this.var = var; @@ -106,36 +102,27 @@ public class GuiMagnetFilter extends AEBaseMEGui { this.guiLeft + 157, this.guiTop + 18, this.cont.nbt, - "WirelessTerminal.magnet.NBT"); + CPacketFluidPatternTermBtns.Command.MAGNET_FILTER_NBT); this.components[1] = new Component( this.guiLeft + 157, this.guiTop + 31, this.cont.meta, - "WirelessTerminal.magnet.Meta"); + CPacketFluidPatternTermBtns.Command.MAGNET_FILTER_META); this.components[2] = new Component( this.guiLeft + 157, this.guiTop + 44, this.cont.ore, - "WirelessTerminal.magnet.Ore"); + CPacketFluidPatternTermBtns.Command.MAGNET_FILTER_ORE); this.components[3] = new Component( this.guiLeft + 157, this.guiTop + 112, this.cont.oreDict, - "WirelessTerminal.magnet.OreDictState"); + CPacketFluidPatternTermBtns.Command.MAGNET_FILTER_OREDICT_STATE); oreDict.x = this.guiLeft + 7; oreDict.y = this.guiTop + 112; oreDict.setText(this.cont.oreDictFilter); - this.buttonList.add( - this.originalGuiBtn = new GuiTabButton( - this.guiLeft + this.xSize - 44, - this.guiTop - 4, - this.cont.getPortableCell().getItemStack(), - this.cont.getPortableCell().getItemStack().getDisplayName(), - itemRender)); - this.originalGuiBtn.setHideEdge(13); // GuiTabButton implementation // - this.clearBtn = new GuiImgButton(this.guiLeft + 7, this.guiTop + 48, Settings.ACTIONS, ActionItems.CLOSE); this.clearBtn.setHalfSize(true); this.buttonList.add(this.clearBtn); @@ -176,7 +163,9 @@ public class GuiMagnetFilter extends AEBaseMEGui { protected void keyTyped(char typedChar, int keyCode) { if (oreDict.isFocused() && (Keyboard.KEY_NUMPADENTER == keyCode || Keyboard.KEY_RETURN == keyCode)) { FluidCraft.proxy.netHandler.sendToServer( - new CPacketFluidPatternTermBtns("WirelessTerminal.magnet.OreDictFilter", oreDict.getText())); + new CPacketFluidPatternTermBtns( + CPacketFluidPatternTermBtns.Command.MAGNET_FILTER_OREDICT_FILTER, + oreDict.getText())); } if (!oreDict.textboxKeyTyped(typedChar, keyCode)) super.keyTyped(typedChar, keyCode); @@ -199,13 +188,11 @@ public class GuiMagnetFilter extends AEBaseMEGui { if (btn == this.listModeBtn) { FluidCraft.proxy.netHandler.sendToServer( new CPacketFluidPatternTermBtns( - "WirelessTerminal.magnet.FilterMode", + CPacketFluidPatternTermBtns.Command.MAGNET_FILTER_MODE, this.cont.listMode != WirelessMagnet.ListMode.WhiteList)); - } else if (btn == this.originalGuiBtn) { - InventoryHandler.switchGui(ItemWirelessUltraTerminal.readMode(this.cont.getPortableCell().getItemStack())); } else if (btn == this.clearBtn) { - FluidCraft.proxy.netHandler - .sendToServer(new CPacketFluidPatternTermBtns("WirelessTerminal.magnet.clear", 1)); + FluidCraft.proxy.netHandler.sendToServer( + new CPacketFluidPatternTermBtns(CPacketFluidPatternTermBtns.Command.MAGNET_FILTER_CLEAR, 1)); } super.actionPerformed(btn); } diff --git a/src/main/java/com/glodblock/github/client/gui/GuiPatternItemRenamer.java b/src/main/java/com/glodblock/github/client/gui/GuiPatternItemRenamer.java deleted file mode 100644 index fb0bc91d..00000000 --- a/src/main/java/com/glodblock/github/client/gui/GuiPatternItemRenamer.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.glodblock.github.client.gui; - -import net.minecraft.entity.player.InventoryPlayer; - -import org.lwjgl.input.Keyboard; - -import com.glodblock.github.FluidCraft; -import com.glodblock.github.common.item.ItemWirelessUltraTerminal; -import com.glodblock.github.common.parts.PartFluidPatternTerminal; -import com.glodblock.github.common.parts.PartFluidPatternTerminalEx; -import com.glodblock.github.common.parts.PartFluidTerminal; -import com.glodblock.github.common.parts.PartLevelTerminal; -import com.glodblock.github.inventory.gui.GuiType; -import com.glodblock.github.inventory.item.IWirelessTerminal; -import com.glodblock.github.inventory.item.WirelessLevelTerminalInventory; -import com.glodblock.github.inventory.item.WirelessPatternTerminalInventory; -import com.glodblock.github.network.SPacketPatternItemRenamer; - -import appeng.api.storage.ITerminalHost; - -public class GuiPatternItemRenamer extends appeng.client.gui.implementations.GuiPatternItemRenamer { - - private GuiType originalGui; - - public GuiPatternItemRenamer(InventoryPlayer ip, ITerminalHost p) { - super(ip, p); - } - - @Override - protected void setOriginGUI(Object target) { - if (target instanceof PartFluidPatternTerminal) { - this.originalGui = GuiType.FLUID_PATTERN_TERMINAL; - } else if (target instanceof PartFluidPatternTerminalEx) { - this.originalGui = GuiType.FLUID_PATTERN_TERMINAL_EX; - } else if (target instanceof PartFluidTerminal) { - this.originalGui = GuiType.FLUID_TERMINAL; - } else if (target instanceof PartLevelTerminal) { - originalGui = GuiType.LEVEL_TERMINAL; - } else if (target instanceof IWirelessTerminal terminal && terminal.isUniversal(target)) { - this.originalGui = ItemWirelessUltraTerminal.readMode(terminal.getItemStack()); - } else if (target instanceof WirelessPatternTerminalInventory) { - this.originalGui = GuiType.FLUID_TERMINAL; - } else if (target instanceof WirelessLevelTerminalInventory) { - originalGui = GuiType.WIRELESS_LEVEL_TERMINAL; - } - } - - @Override - protected void keyTyped(final char character, final int key) { - if (key == Keyboard.KEY_RETURN || key == Keyboard.KEY_NUMPADENTER) { - FluidCraft.proxy.netHandler - .sendToServer(new SPacketPatternItemRenamer(originalGui, getText(), getValueIndex())); - } else super.keyTyped(character, key); - } -} diff --git a/src/main/java/com/glodblock/github/client/gui/GuiPatternMulti.java b/src/main/java/com/glodblock/github/client/gui/GuiPatternMulti.java deleted file mode 100644 index e08d094e..00000000 --- a/src/main/java/com/glodblock/github/client/gui/GuiPatternMulti.java +++ /dev/null @@ -1,155 +0,0 @@ -package com.glodblock.github.client.gui; - -import net.minecraft.client.gui.GuiButton; -import net.minecraft.entity.player.InventoryPlayer; - -import com.glodblock.github.FluidCraft; -import com.glodblock.github.common.item.ItemWirelessUltraTerminal; -import com.glodblock.github.common.parts.PartFluidPatternTerminal; -import com.glodblock.github.common.parts.PartFluidPatternTerminalEx; -import com.glodblock.github.common.parts.PartFluidTerminal; -import com.glodblock.github.common.parts.PartLevelTerminal; -import com.glodblock.github.inventory.gui.GuiType; -import com.glodblock.github.inventory.item.IWirelessTerminal; -import com.glodblock.github.inventory.item.WirelessLevelTerminalInventory; -import com.glodblock.github.inventory.item.WirelessPatternTerminalInventory; -import com.glodblock.github.loader.ItemAndBlockHolder; -import com.glodblock.github.network.CPacketPatternMultiSet; - -import appeng.api.config.ActionItems; -import appeng.api.config.Settings; -import appeng.api.storage.ITerminalHost; -import appeng.client.gui.implementations.GuiAmount; -import appeng.client.gui.widgets.GuiImgButton; -import appeng.container.implementations.ContainerPatternMulti; -import appeng.core.localization.GuiColors; -import appeng.core.localization.GuiText; -import appeng.helpers.Reflected; -import appeng.util.calculators.ArithHelper; -import appeng.util.calculators.Calculator; - -public class GuiPatternMulti extends GuiAmount { - - private static final int DEFAULT_VALUE = 0; - private GuiImgButton symbolSwitch; - protected GuiType originalGui; - - @Reflected - public GuiPatternMulti(final InventoryPlayer inventoryPlayer, final ITerminalHost te) { - super(new ContainerPatternMulti(inventoryPlayer, te)); - } - - @Override - public void initGui() { - super.initGui(); - - this.buttonList.add( - this.symbolSwitch = new GuiImgButton( - this.guiLeft + 22, - this.guiTop + 53, - Settings.ACTIONS, - ActionItems.MULTIPLY)); - - this.amountTextField.x = this.guiLeft + 48; - this.amountTextField.w = 73; - this.amountTextField.setText(String.valueOf(DEFAULT_VALUE)); - this.amountTextField.setCursorPositionEnd(); - this.amountTextField.setSelectionPos(0); - } - - @Override - public void drawFG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) { - this.fontRendererObj - .drawString(GuiText.SelectAmount.getLocal(), 8, 6, GuiColors.CraftAmountSelectAmount.getColor()); - } - - @Override - public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) { - super.drawBG(offsetX, offsetY, mouseX, mouseY); - this.nextBtn.displayString = GuiText.Set.getLocal(); - - try { - int resultI = getAmount(); - - this.symbolSwitch.set(resultI >= 0 ? ActionItems.MULTIPLY : ActionItems.DIVIDE); - this.nextBtn.enabled = resultI < -1 || resultI > 1; - } catch (final NumberFormatException e) { - this.nextBtn.enabled = false; - } - - this.amountTextField.drawTextBox(); - } - - @Override - protected void actionPerformed(final GuiButton btn) { - super.actionPerformed(btn); - - try { - - if (btn == this.nextBtn && btn.enabled) { - int resultI = getAmount(); - if (resultI > 1 || resultI < -1) - FluidCraft.proxy.netHandler.sendToServer(new CPacketPatternMultiSet(this.originalGui, resultI)); - } - } catch (final NumberFormatException e) { - // nope.. - this.amountTextField.setText(String.valueOf(DEFAULT_VALUE)); - } - - if (btn == this.symbolSwitch) { - int resultI = -getAmount(); - this.amountTextField.setText(Integer.toString(resultI)); - } - - } - - @Override - protected int getAmount() { - String out = this.amountTextField.getText(); - - double resultD = Calculator.conversion(out); - - if (Double.isNaN(resultD)) { - return DEFAULT_VALUE; - } else { - return (int) ArithHelper.round(resultD, 0); - } - } - - @Override - protected void addAmount(int i) { - this.amountTextField.setText(Long.toString(i + getAmount())); - this.amountTextField.setCursorPositionEnd(); - } - - @Override - protected String getBackground() { - return "guis/patternMulti.png"; - } - - @Override - protected void setOriginGUI(Object target) { - if (target instanceof PartFluidPatternTerminal) { - this.myIcon = ItemAndBlockHolder.FLUID_TERMINAL.stack(); - this.originalGui = GuiType.FLUID_PATTERN_TERMINAL; - } else if (target instanceof PartFluidPatternTerminalEx) { - this.myIcon = ItemAndBlockHolder.FLUID_TERMINAL_EX.stack(); - this.originalGui = GuiType.FLUID_PATTERN_TERMINAL_EX; - } else if (target instanceof PartFluidTerminal) { - this.myIcon = ItemAndBlockHolder.FLUID_TERM.stack(); - this.originalGui = GuiType.FLUID_TERMINAL; - } else if (target instanceof PartLevelTerminal) { - myIcon = ItemAndBlockHolder.LEVEL_TERMINAL.stack(); - originalGui = GuiType.LEVEL_TERMINAL; - } else if (target instanceof IWirelessTerminal terminal && terminal.isUniversal(target)) { - this.myIcon = ItemAndBlockHolder.WIRELESS_ULTRA_TERM.stack(); - this.originalGui = ItemWirelessUltraTerminal.readMode(terminal.getItemStack()); - } else if (target instanceof WirelessPatternTerminalInventory) { - this.myIcon = ItemAndBlockHolder.WIRELESS_PATTERN_TERM.stack(); - this.originalGui = GuiType.FLUID_TERMINAL; - } else if (target instanceof WirelessLevelTerminalInventory) { - myIcon = ItemAndBlockHolder.LEVEL_TERMINAL.stack(); - originalGui = GuiType.WIRELESS_LEVEL_TERMINAL; - } - } -} diff --git a/src/main/java/com/glodblock/github/client/gui/GuiPatternValueAmount.java b/src/main/java/com/glodblock/github/client/gui/GuiPatternValueAmount.java deleted file mode 100644 index b73d099d..00000000 --- a/src/main/java/com/glodblock/github/client/gui/GuiPatternValueAmount.java +++ /dev/null @@ -1,95 +0,0 @@ -package com.glodblock.github.client.gui; - -import net.minecraft.client.gui.GuiButton; -import net.minecraft.entity.player.InventoryPlayer; - -import com.glodblock.github.FluidCraft; -import com.glodblock.github.client.gui.base.FCGuiAmount; -import com.glodblock.github.client.gui.container.ContainerPatternValueAmount; -import com.glodblock.github.common.item.ItemWirelessUltraTerminal; -import com.glodblock.github.common.parts.PartFluidPatternTerminal; -import com.glodblock.github.common.parts.PartFluidPatternTerminalEx; -import com.glodblock.github.common.tile.TileSuperStockReplenisher; -import com.glodblock.github.inventory.gui.GuiType; -import com.glodblock.github.inventory.item.IWirelessTerminal; -import com.glodblock.github.inventory.item.WirelessPatternTerminalInventory; -import com.glodblock.github.loader.ItemAndBlockHolder; -import com.glodblock.github.network.CPacketPatternValueSet; - -import appeng.core.localization.GuiText; - -public class GuiPatternValueAmount extends FCGuiAmount { - - public GuiPatternValueAmount(final InventoryPlayer inventoryPlayer, final Object te) { - super(new ContainerPatternValueAmount(inventoryPlayer, te)); - } - - @Override - public void initGui() { - super.initGui(); - this.submit.displayString = GuiText.Set.getLocal(); - } - - @Override - public void drawFG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) { - this.fontRendererObj.drawString(GuiText.SelectAmount.getLocal(), 8, 6, 0x404040); - } - - @Override - public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) { - super.drawBG(offsetX, offsetY, mouseX, mouseY); - try { - int result = getAmount(); - this.submit.enabled = result > 0; - } catch (final NumberFormatException e) { - this.submit.enabled = false; - } - this.amountBox.drawTextBox(); - } - - @Override - protected void actionPerformed(final GuiButton btn) { - super.actionPerformed(btn); - try { - if (btn == this.submit && btn.enabled) { - FluidCraft.proxy.netHandler.sendToServer( - new CPacketPatternValueSet( - originalGui.ordinal(), - getAmount(), - ((ContainerPatternValueAmount) this.inventorySlots).getValueIndex())); - } - } catch (final NumberFormatException e) { - this.amountBox.setText("1"); - } - } - - @Override - protected void setOriginGUI(Object target) { - if (target instanceof PartFluidPatternTerminal) { - this.myIcon = ItemAndBlockHolder.FLUID_TERMINAL.stack(); - this.originalGui = GuiType.FLUID_PATTERN_TERMINAL; - } else if (target instanceof PartFluidPatternTerminalEx) { - this.myIcon = ItemAndBlockHolder.FLUID_TERMINAL_EX.stack(); - this.originalGui = GuiType.FLUID_PATTERN_TERMINAL_EX; - } else if (target instanceof IWirelessTerminal terminal && terminal.isUniversal(target)) { - this.myIcon = ItemAndBlockHolder.WIRELESS_ULTRA_TERM.stack(); - this.originalGui = ItemWirelessUltraTerminal.readMode(terminal.getItemStack()); - } else if (target instanceof WirelessPatternTerminalInventory) { - this.myIcon = ItemAndBlockHolder.WIRELESS_PATTERN_TERM.stack(); - this.originalGui = GuiType.WIRELESS_FLUID_PATTERN_TERMINAL; - } else if (target instanceof TileSuperStockReplenisher) { - this.myIcon = ItemAndBlockHolder.SUPER_STOCK_RERPLENISHER.stack(); - this.originalGui = GuiType.GUI_SUPER_STOCK_REPLENISHER; - } - } - - @Override - protected String getBackground() { - return "guis/craftAmt.png"; - } - - public void setAmount(int amount) { - this.amountBox.setText(String.valueOf(amount)); - this.amountBox.setSelectionPos(0); - } -} diff --git a/src/main/java/com/glodblock/github/client/gui/GuiRenamer.java b/src/main/java/com/glodblock/github/client/gui/GuiRenamer.java deleted file mode 100644 index a12af8d2..00000000 --- a/src/main/java/com/glodblock/github/client/gui/GuiRenamer.java +++ /dev/null @@ -1,134 +0,0 @@ -package com.glodblock.github.client.gui; - -import net.minecraft.client.gui.GuiButton; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.item.ItemStack; - -import org.lwjgl.input.Keyboard; - -import com.glodblock.github.FluidCraft; -import com.glodblock.github.client.gui.container.ContainerRenamer; -import com.glodblock.github.common.item.ItemWirelessUltraTerminal; -import com.glodblock.github.common.parts.PartLevelTerminal; -import com.glodblock.github.inventory.InventoryHandler; -import com.glodblock.github.inventory.gui.GuiType; -import com.glodblock.github.inventory.item.IWirelessTerminal; -import com.glodblock.github.inventory.item.WirelessInterfaceTerminalInventory; -import com.glodblock.github.inventory.item.WirelessLevelTerminalInventory; -import com.glodblock.github.loader.ItemAndBlockHolder; -import com.glodblock.github.network.CPacketRenamer; - -import appeng.api.storage.ITerminalHost; -import appeng.client.gui.AEBaseGui; -import appeng.client.gui.widgets.GuiTabButton; -import appeng.client.gui.widgets.IDropToFillTextField; -import appeng.client.gui.widgets.MEGuiTextField; -import appeng.core.localization.GuiColors; -import appeng.core.localization.GuiText; - -public class GuiRenamer extends AEBaseGui implements IDropToFillTextField { - - protected final MEGuiTextField textField; - - protected final ITerminalHost host; - protected GuiTabButton originalGuiBtn; - - protected ItemStack icon = null; - - protected GuiType originalGui; - - public GuiRenamer(InventoryPlayer ip, ITerminalHost monitorable) { - super(new ContainerRenamer(ip, monitorable)); - this.host = monitorable; - this.xSize = 256; - - this.textField = new MEGuiTextField(230, 12); - this.textField.setMaxStringLength(32); - } - - @Override - public void initGui() { - super.initGui(); - FluidCraft.proxy.netHandler.sendToServer(new CPacketRenamer(CPacketRenamer.Action.GET_TEXT)); - if (host instanceof PartLevelTerminal) { - icon = ItemAndBlockHolder.LEVEL_TERMINAL.stack(); - originalGui = GuiType.LEVEL_TERMINAL; - } else if (host instanceof IWirelessTerminal terminal && terminal.isUniversal(host)) { - icon = ItemAndBlockHolder.WIRELESS_ULTRA_TERM.stack(); - originalGui = ItemWirelessUltraTerminal.readMode(terminal.getItemStack()); - } else if (host instanceof WirelessLevelTerminalInventory) { - icon = ItemAndBlockHolder.WIRELESS_LEVEL_TERM.stack(); - originalGui = GuiType.WIRELESS_LEVEL_TERMINAL; - } else if (host instanceof WirelessInterfaceTerminalInventory) { - icon = ItemAndBlockHolder.WIRELESS_INTERFACE_TERM.stack(); - originalGui = GuiType.WIRELESS_INTERFACE_TERMINAL; - } - if (this.icon != null) { - this.buttonList.add( - this.originalGuiBtn = new GuiTabButton( - this.guiLeft + 231, - this.guiTop - 4, - this.icon, - this.icon.getDisplayName(), - itemRender)); - this.originalGuiBtn.setHideEdge(13); - } - this.textField.x = this.guiLeft + 12; - this.textField.y = this.guiTop + 35; - this.textField.setFocused(true); - } - - @Override - public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) { - this.fontRendererObj.drawString(GuiText.Renamer.getLocal(), 12, 8, GuiColors.RenamerTitle.getColor()); - } - - @Override - public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) { - this.bindTexture("guis/renamer.png"); - this.drawTexturedModalRect(offsetX, offsetY, 0, 0, this.xSize, this.ySize); - this.textField.drawTextBox(); - } - - @Override - protected void mouseClicked(final int xCoord, final int yCoord, final int btn) { - this.textField.mouseClicked(xCoord, yCoord, btn); - super.mouseClicked(xCoord, yCoord, btn); - } - - @Override - protected void keyTyped(final char character, final int key) { - if (key == Keyboard.KEY_RETURN || key == Keyboard.KEY_NUMPADENTER) { - FluidCraft.proxy.netHandler.sendToServer(new CPacketRenamer(this.textField.getText())); - } else if (!this.textField.textboxKeyTyped(character, key)) { - super.keyTyped(character, key); - } - } - - public boolean isOverTextField(final int mousex, final int mousey) { - return textField.isMouseIn(mousex, mousey); - } - - @Override - protected void actionPerformed(GuiButton button) { - if (button == originalGuiBtn) { - switchGui(); - } else { - super.actionPerformed(button); - } - } - - public void switchGui() { - if (originalGui != null) { - InventoryHandler.switchGui(originalGui); - } - } - - public void setTextFieldValue(final String displayName, final int mousex, final int mousey, final ItemStack stack) { - textField.setText(displayName); - } - - public void postUpdate(String text) { - this.textField.setText(text); - } -} diff --git a/src/main/java/com/glodblock/github/client/gui/GuiSuperStockReplenisher.java b/src/main/java/com/glodblock/github/client/gui/GuiSuperStockReplenisher.java index b9cd2607..ea86fc09 100644 --- a/src/main/java/com/glodblock/github/client/gui/GuiSuperStockReplenisher.java +++ b/src/main/java/com/glodblock/github/client/gui/GuiSuperStockReplenisher.java @@ -14,15 +14,18 @@ import com.glodblock.github.FluidCraft; import com.glodblock.github.client.gui.container.ContainerSuperStockReplenisher; import com.glodblock.github.common.item.ItemFluidPacket; import com.glodblock.github.common.tile.TileSuperStockReplenisher; -import com.glodblock.github.network.CPacketInventoryAction; +import appeng.api.storage.StorageName; import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IAEStack; import appeng.client.gui.AEBaseGui; import appeng.container.AEBaseContainer; import appeng.container.slot.SlotFake; import appeng.core.localization.GuiText; -import appeng.helpers.InventoryAction; +import appeng.core.sync.GuiBridge; +import appeng.core.sync.network.NetworkHandler; +import appeng.core.sync.packets.PacketSwitchGuis; +import appeng.core.sync.packets.PacketVirtualSlot; import appeng.util.item.AEItemStack; public class GuiSuperStockReplenisher extends AEBaseGui { @@ -41,12 +44,14 @@ public class GuiSuperStockReplenisher extends AEBaseGui { if (mouseButton == 3) { if (slot instanceof SlotFake) { if (slot.getHasStack()) { - InventoryAction action = InventoryAction.SET_PATTERN_VALUE; IAEItemStack stack = AEItemStack.create(slot.getStack()); ((AEBaseContainer) this.inventorySlots).setTargetStack(stack); for (int i = 0; i < this.inventorySlots.inventorySlots.size(); i++) { if (slot.equals(this.inventorySlots.inventorySlots.get(i))) { - FluidCraft.proxy.netHandler.sendToServer(new CPacketInventoryAction(action, i, 0, stack)); + NetworkHandler.instance + .sendToServer(new PacketSwitchGuis(GuiBridge.GUI_PATTERN_VALUE_AMOUNT)); + NetworkHandler.instance + .sendToServer(new PacketVirtualSlot(StorageName.CRAFTING_INPUT, i, stack)); } } return; diff --git a/src/main/java/com/glodblock/github/client/gui/base/FCBaseMEGui.java b/src/main/java/com/glodblock/github/client/gui/base/FCBaseMEGui.java index b5dcdd67..dfddd296 100644 --- a/src/main/java/com/glodblock/github/client/gui/base/FCBaseMEGui.java +++ b/src/main/java/com/glodblock/github/client/gui/base/FCBaseMEGui.java @@ -1,68 +1,14 @@ package com.glodblock.github.client.gui.base; -import java.util.ArrayList; -import java.util.List; - -import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; -import com.glodblock.github.FluidCraft; -import com.glodblock.github.client.gui.GuiEssentiaTerminal; -import com.glodblock.github.client.gui.GuiFCImgButton; -import com.glodblock.github.client.gui.GuiFluidCraftingWireless; -import com.glodblock.github.client.gui.GuiFluidPatternExWireless; -import com.glodblock.github.client.gui.GuiFluidPatternWireless; -import com.glodblock.github.client.gui.GuiFluidPortableCell; -import com.glodblock.github.client.gui.GuiLevelWireless; -import com.glodblock.github.client.gui.container.base.FCBaseContainer; -import com.glodblock.github.common.item.ItemWirelessUltraTerminal; -import com.glodblock.github.inventory.gui.GuiType; -import com.glodblock.github.inventory.item.IWirelessTerminal; -import com.glodblock.github.inventory.item.WirelessMagnet; -import com.glodblock.github.network.CPacketFluidPatternTermBtns; -import com.glodblock.github.util.ModAndClassUtil; +import appeng.client.gui.AEBaseGui; -import appeng.api.storage.StorageChannel; -import appeng.client.gui.AEBaseMEGui; - -public abstract class FCBaseMEGui extends AEBaseMEGui { - - protected GuiFCImgButton FluidTerminal; - protected GuiFCImgButton CraftingTerminal; - protected GuiFCImgButton PatternTerminal; - protected GuiFCImgButton EssentiaTerminal; - protected GuiFCImgButton InterfaceTerminal; - protected GuiFCImgButton LevelTerminal; - protected GuiFCImgButton PatternTerminalEx; - protected GuiFCImgButton magnetOff; - protected GuiFCImgButton magnetInv; - protected GuiFCImgButton magnetME; - protected GuiFCImgButton magnetFilter; - protected GuiFCImgButton restockEnableBtn; - protected GuiFCImgButton restockDisableBtn; - protected List termBtns = new ArrayList<>(); - protected boolean drawSwitchGuiBtn; - private StorageChannel channel = null; +public abstract class FCBaseMEGui extends AEBaseGui { public FCBaseMEGui(final InventoryPlayer inventoryPlayer, Container container) { super(container); - if (container instanceof FCBaseContainer) { - Object target = ((FCBaseContainer) container).getTarget(); - if (target instanceof IWirelessTerminal - && ((IWirelessTerminal) target).getItemStack().getItem() instanceof ItemWirelessUltraTerminal) { - this.drawSwitchGuiBtn = true; - channel = ((IWirelessTerminal) target).getChannel(); - } - } - } - - protected WirelessMagnet.Mode getMagnetMode() { - return ((FCBaseContainer) this.inventorySlots).mode; - } - - protected boolean isRestock() { - return ((FCBaseContainer) this.inventorySlots).restock; } @Override @@ -70,128 +16,6 @@ public abstract class FCBaseMEGui extends AEBaseMEGui { super.onGuiClosed(); } - protected void initGuiDone() { - if (drawSwitchGuiBtn) { - drawSwitchGuiBtns(); - } - } - - public abstract int getOffsetY(); - - public abstract void setOffsetY(int y); - - protected void drawSwitchGuiBtns() { - if (!drawSwitchGuiBtn) return; - if (!termBtns.isEmpty()) { - this.termBtns.clear(); - } - if (this.getMagnetMode() != null && this.channel == StorageChannel.ITEMS) { - this.buttonList.add( - this.magnetOff = new GuiFCImgButton( - this.guiLeft + this.xSize - 18, - this.guiTop + this.ySize - 124, - "MAGNET_CARD", - "OFF")); - this.buttonList.add( - this.magnetInv = new GuiFCImgButton( - this.guiLeft + this.xSize - 18, - this.guiTop + this.ySize - 124, - "MAGNET_CARD", - "INV")); - this.buttonList.add( - this.magnetME = new GuiFCImgButton( - this.guiLeft + this.xSize - 18, - this.guiTop + this.ySize - 124, - "MAGNET_CARD", - "ME")); - this.buttonList.add( - this.magnetFilter = new GuiFCImgButton( - this.guiLeft + this.xSize - 18, - this.guiTop + this.ySize - 104, - "MAGNET_CARD", - "FILTER")); - } - if (this.channel == StorageChannel.ITEMS) { - this.buttonList.add( - this.restockEnableBtn = new GuiFCImgButton( - this.guiLeft + this.xSize - 18, - this.guiTop + this.ySize - 84, - "RESTOCK", - "ENABLE")); - this.buttonList.add( - this.restockDisableBtn = new GuiFCImgButton( - this.guiLeft + this.xSize - 18, - this.guiTop + this.ySize - 84, - "RESTOCK", - "DISABLE")); - } - if (!(this instanceof GuiFluidCraftingWireless)) { - this.buttonList.add( - this.CraftingTerminal = new GuiFCImgButton( - this.guiLeft - 18, - this.getOffsetY(), - "CRAFT_TEM", - "YES")); - this.setOffsetY(this.getOffsetY() + 20); - termBtns.add(this.CraftingTerminal); - } - if (!(this instanceof GuiFluidPatternWireless)) { - this.buttonList.add( - this.PatternTerminal = new GuiFCImgButton( - this.guiLeft - 18, - this.getOffsetY(), - "PATTERN_TEM", - "YES")); - this.setOffsetY(this.getOffsetY() + 20); - termBtns.add(this.PatternTerminal); - } - if (!(this instanceof GuiFluidPatternExWireless)) { - this.buttonList.add( - this.PatternTerminalEx = new GuiFCImgButton( - this.guiLeft - 18, - this.getOffsetY(), - "PATTERN_EX_TEM", - "YES")); - this.setOffsetY(this.getOffsetY() + 20); - termBtns.add(this.PatternTerminalEx); - } - if (!(this instanceof GuiFluidPortableCell)) { - this.buttonList.add( - this.FluidTerminal = new GuiFCImgButton(this.guiLeft - 18, this.getOffsetY(), "FLUID_TEM", "YES")); - this.setOffsetY(this.getOffsetY() + 20); - termBtns.add(this.FluidTerminal); - } - this.buttonList.add( - this.InterfaceTerminal = new GuiFCImgButton( - this.guiLeft - 18, - this.getOffsetY(), - "INTERFACE_TEM", - "YES")); - this.setOffsetY(this.getOffsetY() + 20); - termBtns.add(this.InterfaceTerminal); - if (!(this instanceof GuiLevelWireless)) { - this.buttonList.add( - this.LevelTerminal = new GuiFCImgButton(this.guiLeft - 18, this.getOffsetY(), "LEVEL_TEM", "YES")); - this.setOffsetY(this.getOffsetY() + 20); - termBtns.add(this.LevelTerminal); - } - if (ModAndClassUtil.ThE && !(this instanceof GuiEssentiaTerminal)) { - this.buttonList.add( - this.EssentiaTerminal = new GuiFCImgButton( - this.guiLeft - 18, - this.getOffsetY(), - "ESSENTIA_TEM", - "YES")); - this.setOffsetY(this.getOffsetY() + 20); - termBtns.add(this.EssentiaTerminal); - } - } - - protected void addSwitchGuiBtns() { - if (!drawSwitchGuiBtn) return; - this.buttonList.addAll(termBtns); - } - private boolean scheduleGuiResize; @Override @@ -213,53 +37,4 @@ public abstract class FCBaseMEGui extends AEBaseMEGui { protected final void scheduleGuiResize() { scheduleGuiResize = true; } - - @Override - public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) { - if (isPortableCell()) return; - if (getMagnetMode() != null && this.channel == StorageChannel.ITEMS) { - GuiFCImgButton[] magnetButtons = { this.magnetOff, this.magnetInv, this.magnetME }; - for (int i = 0; i < magnetButtons.length; i++) { - magnetButtons[i].visible = getMagnetMode().ordinal() == i; - } - } - if (this.drawSwitchGuiBtn && this.channel == StorageChannel.ITEMS) { // Only ultra terminal - this.restockDisableBtn.visible = !this.isRestock(); - this.restockEnableBtn.visible = this.isRestock(); - } - } - - @Override - protected void actionPerformed(final GuiButton btn) { - if (btn instanceof GuiFCImgButton) { - if (btn == this.FluidTerminal) { - ItemWirelessUltraTerminal.switchTerminal(this.mc.thePlayer, GuiType.WIRELESS_FLUID_TERMINAL); - } else if (btn == this.CraftingTerminal) { - ItemWirelessUltraTerminal.switchTerminal(this.mc.thePlayer, GuiType.WIRELESS_CRAFTING_TERMINAL); - } else if (btn == this.EssentiaTerminal) { - ItemWirelessUltraTerminal.switchTerminal(this.mc.thePlayer, GuiType.WIRELESS_ESSENTIA_TERMINAL); - } else if (btn == this.PatternTerminal) { - ItemWirelessUltraTerminal.switchTerminal(this.mc.thePlayer, GuiType.WIRELESS_FLUID_PATTERN_TERMINAL); - } else if (btn == this.InterfaceTerminal) { - ItemWirelessUltraTerminal.switchTerminal(this.mc.thePlayer, GuiType.WIRELESS_INTERFACE_TERMINAL); - } else if (btn == this.LevelTerminal) { - ItemWirelessUltraTerminal.switchTerminal(this.mc.thePlayer, GuiType.WIRELESS_LEVEL_TERMINAL); - } else if (btn == this.PatternTerminalEx) { - ItemWirelessUltraTerminal.switchTerminal(this.mc.thePlayer, GuiType.WIRELESS_FLUID_PATTERN_TERMINAL_EX); - } else if (btn == this.magnetOff || btn == this.magnetME || btn == this.magnetInv) { - FluidCraft.proxy.netHandler.sendToServer( - new CPacketFluidPatternTermBtns("WirelessTerminal.MagnetMode", this.getMagnetMode().ordinal())); - } else if (btn == this.magnetFilter) { - FluidCraft.proxy.netHandler - .sendToServer(new CPacketFluidPatternTermBtns("WirelessTerminal.OpenMagnet", 0)); - } else if (btn == this.restockDisableBtn || btn == this.restockEnableBtn) { - FluidCraft.proxy.netHandler.sendToServer(new CPacketFluidPatternTermBtns("WirelessTerminal.Stock", 1)); - } - } - super.actionPerformed(btn); - } - - protected boolean isPortableCell() { - return false; - } } diff --git a/src/main/java/com/glodblock/github/client/gui/base/FCGuiAmount.java b/src/main/java/com/glodblock/github/client/gui/base/FCGuiAmount.java deleted file mode 100644 index 1ac4b997..00000000 --- a/src/main/java/com/glodblock/github/client/gui/base/FCGuiAmount.java +++ /dev/null @@ -1,152 +0,0 @@ -package com.glodblock.github.client.gui.base; - -import net.minecraft.client.gui.GuiButton; -import net.minecraft.inventory.Container; -import net.minecraft.item.ItemStack; - -import org.lwjgl.input.Keyboard; - -import com.glodblock.github.inventory.InventoryHandler; -import com.glodblock.github.inventory.gui.GuiType; - -import appeng.client.gui.AEBaseGui; -import appeng.client.gui.widgets.GuiTabButton; -import appeng.client.gui.widgets.MEGuiTextField; -import appeng.container.AEBaseContainer; -import appeng.core.AEConfig; -import appeng.core.localization.GuiText; -import appeng.util.calculators.ArithHelper; -import appeng.util.calculators.Calculator; - -public abstract class FCGuiAmount extends AEBaseGui { - - protected MEGuiTextField amountBox; - protected GuiTabButton originalGuiBtn; - protected GuiButton submit; - protected GuiButton plus1; - protected GuiButton plus10; - protected GuiButton plus100; - protected GuiButton plus1000; - protected GuiButton minus1; - protected GuiButton minus10; - protected GuiButton minus100; - protected GuiButton minus1000; - protected GuiType originalGui; - protected ItemStack myIcon; - - public FCGuiAmount(Container container) { - super(container); - } - - @Override - public void initGui() { - super.initGui(); - - final int a = getIncrementQuantity(0); - final int b = getIncrementQuantity(1); - final int c = getIncrementQuantity(2); - final int d = getIncrementQuantity(3); - - this.buttonList.add(this.plus1 = new GuiButton(0, this.guiLeft + 20, this.guiTop + 26, 22, 20, "+" + a)); - this.buttonList.add(this.plus10 = new GuiButton(0, this.guiLeft + 48, this.guiTop + 26, 28, 20, "+" + b)); - this.buttonList.add(this.plus100 = new GuiButton(0, this.guiLeft + 82, this.guiTop + 26, 32, 20, "+" + c)); - this.buttonList.add(this.plus1000 = new GuiButton(0, this.guiLeft + 120, this.guiTop + 26, 38, 20, "+" + d)); - - this.buttonList.add(this.minus1 = new GuiButton(0, this.guiLeft + 20, this.guiTop + 75, 22, 20, "-" + a)); - this.buttonList.add(this.minus10 = new GuiButton(0, this.guiLeft + 48, this.guiTop + 75, 28, 20, "-" + b)); - this.buttonList.add(this.minus100 = new GuiButton(0, this.guiLeft + 82, this.guiTop + 75, 32, 20, "-" + c)); - this.buttonList.add(this.minus1000 = new GuiButton(0, this.guiLeft + 120, this.guiTop + 75, 38, 20, "-" + d)); - - this.buttonList.add( - this.submit = new GuiButton(0, this.guiLeft + 128, this.guiTop + 51, 38, 20, GuiText.Next.getLocal())); - - setOriginGUI(((AEBaseContainer) this.inventorySlots).getTarget()); - if (this.originalGui != null && this.myIcon != null) { - this.buttonList.add( - this.originalGuiBtn = new GuiTabButton( - this.guiLeft + 151, - this.guiTop - 4, - this.myIcon, - this.myIcon.getDisplayName(), - itemRender)); - this.originalGuiBtn.setHideEdge(13); - } - - this.amountBox = new MEGuiTextField(61, 12); - this.amountBox.x = this.guiLeft + 60; - this.amountBox.y = this.guiTop + 55; - this.amountBox.setMaxStringLength(16); - this.amountBox.setFocused(true); - } - - protected int getIncrementQuantity(int i) { - return AEConfig.instance.craftItemsByStackAmounts(i); - } - - @Override - public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) { - this.bindTexture(getBackground()); - this.drawTexturedModalRect(offsetX, offsetY, 0, 0, this.xSize, this.ySize); - } - - @Override - protected void keyTyped(final char character, final int key) { - if (!this.checkHotbarKeys(key)) { - if (key == Keyboard.KEY_RETURN || key == Keyboard.KEY_NUMPADENTER) { - this.actionPerformed(this.submit); - } - this.amountBox.textboxKeyTyped(character, key); - super.keyTyped(character, key); - } - } - - @Override - protected void actionPerformed(final GuiButton btn) { - super.actionPerformed(btn); - if (btn == this.originalGuiBtn) { - InventoryHandler.switchGui(originalGui); - } - final boolean isPlus = btn == this.plus1 || btn == this.plus10 || btn == this.plus100 || btn == this.plus1000; - final boolean isMinus = btn == this.minus1 || btn == this.minus10 - || btn == this.minus100 - || btn == this.minus1000; - - if (isPlus || isMinus) { - this.addQty(this.getQty(btn)); - } - } - - protected void addQty(final int i) { - try { - long resultI = getAmount(); - if (resultI == 1 && i > 1) { - resultI = 0; - } - resultI += i; - if (resultI < 1) { - resultI = 1; - } - String out = Long.toString(resultI); - this.amountBox.setText(out); - this.amountBox.setCursorPositionEnd(); - } catch (final NumberFormatException ignore) {} - } - - protected abstract void setOriginGUI(Object target); - - protected abstract String getBackground(); - - protected int getAmount() { - try { - String out = this.amountBox.getText(); - double result = Calculator.conversion(out); - if (result <= 0 || Double.isNaN(result)) { - return 0; - } else { - return (int) ArithHelper.round(result, 0); - } - } catch (final NumberFormatException e) { - return 0; - } - } -} diff --git a/src/main/java/com/glodblock/github/client/gui/base/FCGuiEncodeTerminal.java b/src/main/java/com/glodblock/github/client/gui/base/FCGuiEncodeTerminal.java deleted file mode 100644 index f6d294eb..00000000 --- a/src/main/java/com/glodblock/github/client/gui/base/FCGuiEncodeTerminal.java +++ /dev/null @@ -1,199 +0,0 @@ -package com.glodblock.github.client.gui.base; - -import net.minecraft.client.gui.GuiButton; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.Slot; - -import org.lwjgl.input.Keyboard; -import org.lwjgl.input.Mouse; -import org.lwjgl.opengl.GL11; - -import com.glodblock.github.FluidCraft; -import com.glodblock.github.client.gui.GuiFCImgButton; -import com.glodblock.github.client.gui.GuiItemMonitor; -import com.glodblock.github.client.gui.container.base.FCContainerEncodeTerminal; -import com.glodblock.github.common.item.ItemFluidPacket; -import com.glodblock.github.inventory.InventoryHandler; -import com.glodblock.github.inventory.gui.GuiType; -import com.glodblock.github.inventory.slot.SlotSingleItem; -import com.glodblock.github.network.CPacketFluidPatternTermBtns; -import com.glodblock.github.util.ModAndClassUtil; - -import appeng.api.storage.ITerminalHost; -import appeng.api.storage.data.IAEItemStack; -import appeng.client.gui.widgets.GuiImgButton; -import appeng.client.gui.widgets.GuiScrollbar; -import appeng.client.gui.widgets.GuiTabButton; -import appeng.container.slot.AppEngSlot; -import appeng.container.slot.SlotFake; -import appeng.util.item.AEItemStack; - -public abstract class FCGuiEncodeTerminal extends GuiItemMonitor { - - private static final String SUBSTITUTION_DISABLE = "0"; - private static final String SUBSTITUTION_ENABLE = "1"; - private static final String PRIORITY_DISABLE = "0"; - private static final String PRIORITY_ENABLE = "1"; - private static final String MODE_CRAFTING = "1"; - private static final String MODE_PROCESSING = "0"; - public FCContainerEncodeTerminal container; - protected GuiTabButton tabCraftButton; - protected GuiTabButton tabProcessButton; - protected GuiImgButton substitutionsEnabledBtn; - protected GuiImgButton substitutionsDisabledBtn; - protected GuiFCImgButton fluidPrioritizedEnabledBtn; - protected GuiFCImgButton fluidPrioritizedDisabledBtn; - protected GuiImgButton encodeBtn; - protected GuiImgButton invertBtn; - protected GuiImgButton clearBtn; - protected GuiImgButton doubleBtn; - protected GuiImgButton beSubstitutionsEnabledBtn; - protected GuiImgButton beSubstitutionsDisabledBtn; - protected GuiFCImgButton combineEnableBtn; - protected GuiFCImgButton combineDisableBtn; - protected GuiFCImgButton autoFillPatternEnableBtn; - protected GuiFCImgButton autoFillPatternDisableBtn; - protected final GuiScrollbar processingScrollBar = new GuiScrollbar(); - - public FCGuiEncodeTerminal(final InventoryPlayer inventoryPlayer, final ITerminalHost te, - final FCContainerEncodeTerminal c) { - super(inventoryPlayer, te, c); - this.container = (FCContainerEncodeTerminal) this.inventorySlots; - c.setGui(this); - setReservedSpace(81); - } - - @Override - public void initGui() { - super.initGui(); - this.buttonList.add( - this.autoFillPatternEnableBtn = new GuiFCImgButton( - this.guiLeft - 18, - this.offsetY, - "FILL_PATTERN", - "DO_FILL")); - this.buttonList.add( - this.autoFillPatternDisableBtn = new GuiFCImgButton( - this.guiLeft - 18, - this.offsetY, - "NOT_FILL_PATTERN", - "DONT_FILL")); - this.offsetY += 20; - } - - @Override - protected void actionPerformed(final GuiButton btn) { - super.actionPerformed(btn); - if (btn == craftingStatusBtn) { - InventoryHandler.switchGui(GuiType.CRAFTING_STATUS); - } else if (this.tabCraftButton == btn || this.tabProcessButton == btn) { - FluidCraft.proxy.netHandler.sendToServer( - new CPacketFluidPatternTermBtns( - "PatternTerminal.CraftMode", - this.tabProcessButton == btn ? MODE_CRAFTING : MODE_PROCESSING)); - } else if (this.encodeBtn == btn) { - FluidCraft.proxy.netHandler.sendToServer( - new CPacketFluidPatternTermBtns( - "PatternTerminal.Encode", - (isCtrlKeyDown() ? 1 : 0) << 1 | (isShiftKeyDown() ? 1 : 0))); - } else if (this.clearBtn == btn) { - FluidCraft.proxy.netHandler.sendToServer(new CPacketFluidPatternTermBtns("PatternTerminal.Clear", "1")); - } else if (this.substitutionsEnabledBtn == btn || this.substitutionsDisabledBtn == btn) { - FluidCraft.proxy.netHandler.sendToServer( - new CPacketFluidPatternTermBtns( - "PatternTerminal.Substitute", - this.substitutionsEnabledBtn == btn ? SUBSTITUTION_DISABLE : SUBSTITUTION_ENABLE)); - } else if (this.fluidPrioritizedEnabledBtn == btn || this.fluidPrioritizedDisabledBtn == btn) { - FluidCraft.proxy.netHandler.sendToServer( - new CPacketFluidPatternTermBtns( - "PatternTerminal.Prioritize", - isShiftKeyDown() ? "2" : (container.prioritize ? PRIORITY_DISABLE : PRIORITY_ENABLE))); - } else if (this.invertBtn == btn) { - FluidCraft.proxy.netHandler.sendToServer( - new CPacketFluidPatternTermBtns("PatternTerminal.Invert", container.inverted ? "0" : "1")); - } else if (this.combineDisableBtn == btn || this.combineEnableBtn == btn) { - FluidCraft.proxy.netHandler.sendToServer( - new CPacketFluidPatternTermBtns( - "PatternTerminal.Combine", - this.combineDisableBtn == btn ? "1" : "0")); - } else if (ModAndClassUtil.isDoubleButton && doubleBtn == btn) { - int val = Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) ? 1 : 0; - if (Mouse.isButtonDown(1)) val |= 0b10; - FluidCraft.proxy.netHandler - .sendToServer(new CPacketFluidPatternTermBtns("PatternTerminal.Double", String.valueOf(val))); - } else if (ModAndClassUtil.isBeSubstitutionsButton && beSubstitutionsDisabledBtn == btn) { - FluidCraft.proxy.netHandler - .sendToServer(new CPacketFluidPatternTermBtns("PatternTerminal.beSubstitute", "1")); - } else if (ModAndClassUtil.isBeSubstitutionsButton && beSubstitutionsEnabledBtn == btn) { - FluidCraft.proxy.netHandler - .sendToServer(new CPacketFluidPatternTermBtns("PatternTerminal.beSubstitute", "0")); - } else if (this.autoFillPatternDisableBtn == btn || this.autoFillPatternEnableBtn == btn) { - FluidCraft.proxy.netHandler.sendToServer( - new CPacketFluidPatternTermBtns( - "PatternTerminal.AutoFillerPattern", - this.autoFillPatternDisableBtn == btn ? "1" : "0")); - } - } - - @Override - public void drawFG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) { - updateButton(this.tabCraftButton, this.container.isCraftingMode()); - updateButton(this.tabProcessButton, !this.container.isCraftingMode()); - updateButton(this.doubleBtn, !this.container.isCraftingMode()); - updateButton(this.substitutionsEnabledBtn, this.container.substitute); - updateButton(this.substitutionsDisabledBtn, !this.container.substitute); - updateButton(this.combineEnableBtn, !this.container.isCraftingMode() && this.container.combine); - updateButton(this.combineDisableBtn, !this.container.isCraftingMode() && !this.container.combine); - updateButton(this.beSubstitutionsEnabledBtn, this.container.beSubstitute); - updateButton(this.beSubstitutionsDisabledBtn, !this.container.beSubstitute); - updateButton(this.fluidPrioritizedEnabledBtn, this.container.prioritize); - updateButton(this.fluidPrioritizedDisabledBtn, !this.container.prioritize); - updateButton(this.autoFillPatternEnableBtn, this.container.autoFillPattern); - updateButton(this.autoFillPatternDisableBtn, !this.container.autoFillPattern); - super.drawFG(offsetX, offsetY, mouseX, mouseY); - } - - protected void updateButton(GuiButton button, boolean vis) { - if (button != null) { - button.visible = vis; - } - } - - @Override - protected void repositionSlot(final AppEngSlot s) { - if (s.isPlayerSide()) { - s.yDisplayPosition = s.getY() + this.ySize - 78 - 5; - } else { - s.yDisplayPosition = s.getY() + this.ySize - 78 - 3; - } - } - - @Override - public void func_146977_a(final Slot s) { - if (drawSlot0(s)) super.func_146977_a(s); - } - - public boolean drawSlot0(Slot slot) { - if (slot instanceof SlotFake && !this.container.isCraftingMode()) { - AEItemStack stack = AEItemStack.create(slot.getStack()); - super.func_146977_a(new SlotSingleItem(slot)); - if (stack == null) return true; - IAEItemStack fake = stack.copy(); - if (fake.getItemStack().getItem() instanceof ItemFluidPacket) { - if (ItemFluidPacket.getFluidStack(stack) != null && ItemFluidPacket.getFluidStack(stack).amount > 0) - fake.setStackSize(ItemFluidPacket.getFluidStack(stack).amount); - } else return true; - aeRenderItem.setAeStack(fake); - GL11.glTranslatef(0.0f, 0.0f, 200.0f); - aeRenderItem.renderItemOverlayIntoGUI( - fontRendererObj, - mc.getTextureManager(), - stack.getItemStack(), - slot.xDisplayPosition, - slot.yDisplayPosition); - GL11.glTranslatef(0.0f, 0.0f, -200.0f); - return false; - } - return true; - } -} diff --git a/src/main/java/com/glodblock/github/client/gui/base/FCGuiMonitor.java b/src/main/java/com/glodblock/github/client/gui/base/FCGuiMonitor.java deleted file mode 100644 index f945dfde..00000000 --- a/src/main/java/com/glodblock/github/client/gui/base/FCGuiMonitor.java +++ /dev/null @@ -1,914 +0,0 @@ -package com.glodblock.github.client.gui.base; - -import java.io.IOException; -import java.lang.reflect.Field; -import java.util.List; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiButton; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; -import net.minecraft.util.ResourceLocation; - -import org.lwjgl.input.Keyboard; -import org.lwjgl.input.Mouse; - -import com.glodblock.github.FluidCraft; -import com.glodblock.github.client.gui.GuiFluidMonitor; -import com.glodblock.github.client.gui.GuiItemMonitor; -import com.glodblock.github.client.gui.container.base.FCContainerMonitor; -import com.glodblock.github.inventory.InventoryHandler; -import com.glodblock.github.inventory.gui.GuiType; -import com.glodblock.github.network.CPacketInventoryAction; -import com.glodblock.github.util.Ae2ReflectClient; -import com.glodblock.github.util.ModAndClassUtil; - -import appeng.api.config.CraftingStatus; -import appeng.api.config.PinsState; -import appeng.api.config.SearchBoxFocusPriority; -import appeng.api.config.SearchBoxMode; -import appeng.api.config.Settings; -import appeng.api.config.TerminalStyle; -import appeng.api.config.YesNo; -import appeng.api.implementations.tiles.IViewCellStorage; -import appeng.api.storage.ITerminalHost; -import appeng.api.storage.ITerminalPins; -import appeng.api.storage.data.IAEItemStack; -import appeng.api.storage.data.IAEStack; -import appeng.api.storage.data.IDisplayRepo; -import appeng.api.util.IConfigManager; -import appeng.api.util.IConfigurableObject; -import appeng.client.gui.widgets.GuiImgButton; -import appeng.client.gui.widgets.GuiScrollbar; -import appeng.client.gui.widgets.GuiTabButton; -import appeng.client.gui.widgets.IDropToFillTextField; -import appeng.client.gui.widgets.ISortSource; -import appeng.client.gui.widgets.MEGuiTextField; -import appeng.client.me.InternalSlotME; -import appeng.client.me.ItemRepo; -import appeng.client.me.PinSlotME; -import appeng.client.me.SlotDisconnected; -import appeng.client.me.SlotME; -import appeng.container.AEBaseContainer; -import appeng.container.slot.AppEngSlot; -import appeng.container.slot.OptionalSlotFake; -import appeng.container.slot.SlotCraftingMatrix; -import appeng.container.slot.SlotCraftingTerm; -import appeng.container.slot.SlotDisabled; -import appeng.container.slot.SlotFake; -import appeng.container.slot.SlotFakeCraftingMatrix; -import appeng.container.slot.SlotPatternTerm; -import appeng.core.AEConfig; -import appeng.core.AELog; -import appeng.core.localization.ButtonToolTips; -import appeng.core.localization.GuiText; -import appeng.core.sync.network.NetworkHandler; -import appeng.core.sync.packets.PacketInventoryAction; -import appeng.core.sync.packets.PacketPinsUpdate; -import appeng.core.sync.packets.PacketValueConfig; -import appeng.helpers.IPinsHandler; -import appeng.helpers.InventoryAction; -import appeng.integration.IntegrationRegistry; -import appeng.integration.IntegrationType; -import appeng.util.IConfigManagerHost; -import appeng.util.Platform; -import appeng.util.item.AEItemStack; -import codechicken.nei.LayoutManager; -import codechicken.nei.util.TextHistory; - -// TODO why is this copy pasting all the UI code from AE2 instead of reusing it ??? -public abstract class FCGuiMonitor> extends FCBaseMEGui - implements ISortSource, IConfigManagerHost, IDropToFillTextField, IPinsHandler { - - public static int craftingGridOffsetX; - public static int craftingGridOffsetY; - protected static String memoryText = ""; - protected final int offsetX = 9; - protected final int lowerTextureOffset = 0; - public IConfigManager configSrc; - protected final boolean viewCell; - protected final ItemStack[] myCurrentViewCells = new ItemStack[5]; - public FCContainerMonitor monitorableContainer; - public GuiTabButton craftingStatusBtn; - protected IDisplayRepo repo; - protected GuiImgButton craftingStatusImgBtn; - protected MEGuiTextField searchField; - protected int perRow = 9; - protected int reservedSpace = 0; - protected boolean customSortOrder = true; - protected boolean showViewBtn = true; - protected int rows = 0; - protected int maxRows = Integer.MAX_VALUE; - protected int standardSize; - protected int offsetY; - protected GuiImgButton ViewBox; - protected GuiImgButton SortByBox; - protected GuiImgButton SortDirBox; - protected GuiImgButton searchBoxSettings; - protected GuiImgButton terminalStyleBox; - protected GuiImgButton searchStringSave; - protected GuiImgButton typeFilter; - protected GuiImgButton pinsStateButton; - protected boolean hasShiftKeyDown = false; - private PinsState pinsState; - public final boolean hasPinHost; - private boolean canBeAutoFocused; - private boolean isAutoFocused; - protected int currentMouseY; - protected int currentMouseX; - - @SuppressWarnings("unchecked") - public FCGuiMonitor(final InventoryPlayer inventoryPlayer, final ITerminalHost te, final FCContainerMonitor c) { - super(inventoryPlayer, c); - final GuiScrollbar scrollbar = new GuiScrollbar(); - this.setScrollBar(scrollbar); - this.xSize = 195; - this.ySize = 204; - this.standardSize = this.xSize; - this.configSrc = ((IConfigurableObject) this.inventorySlots).getConfigManager(); - (this.monitorableContainer = (FCContainerMonitor) this.inventorySlots).setGui(this); - this.viewCell = te instanceof IViewCellStorage; - pinsState = (PinsState) configSrc.getSetting(Settings.PINS_STATE); - hasPinHost = te instanceof ITerminalPins && !(this instanceof GuiFluidMonitor); - } - - public int getOffsetY() { - return offsetY; - } - - public void setOffsetY(int y) { - offsetY = y; - } - - public abstract void postUpdate(final List list, boolean resort); - - protected void setScrollBar() { - this.getScrollBar().setTop(18).setLeft(175).setHeight(this.rows * 18 - 2); - this.getScrollBar().setRange( - 0, - (this.repo.size() + pinsState.ordinal() * 9 + this.perRow - 1) / this.perRow - this.rows, - Math.max(1, this.rows / 6)); - } - - @Override - protected void actionPerformed(final GuiButton btn) { - memoryText = this.searchField.getText(); - if (btn == this.craftingStatusBtn || btn == this.craftingStatusImgBtn) { - InventoryHandler.switchGui(GuiType.CRAFTING_STATUS); - } - if (btn instanceof final GuiImgButton iBtn) { - final boolean backwards = Mouse.isButtonDown(1); - if (iBtn.getSetting() != Settings.ACTIONS) { - final Enum cv = iBtn.getCurrentValue(); - final Enum next = Platform.rotateEnum(cv, backwards, iBtn.getSetting().getPossibleValues()); - if (btn == this.terminalStyleBox) { - AEConfig.instance.settings.putSetting(iBtn.getSetting(), next); - } else if (btn == this.searchBoxSettings) { - AEConfig.instance.settings.putSetting(iBtn.getSetting(), next); - } else if (ModAndClassUtil.isSaveText && btn == this.searchStringSave) { - AEConfig.instance.preserveSearchBar = next == YesNo.YES; - } else if (btn == this.pinsStateButton) { - try { - if (next.ordinal() >= rows) return; // ignore to avoid hiding terminal inventory - - final PacketPinsUpdate p = new PacketPinsUpdate((PinsState) next); - NetworkHandler.instance.sendToServer(p); - } catch (final IOException e) { - AELog.debug(e); - } - } else { - try { - NetworkHandler.instance - .sendToServer(new PacketValueConfig(iBtn.getSetting().name(), next.name())); - } catch (final IOException e) { - AELog.debug(e); - } - } - iBtn.set(next); - if (next.getClass() == SearchBoxMode.class || next.getClass() == TerminalStyle.class) { - super.scheduleGuiResize(); - } - } - } - super.actionPerformed(btn); - } - - private void adjustPinsSize() { - final int pinMaxSize = rows - 1; - if (pinsState.ordinal() <= pinMaxSize) return; - - try { - PinsState newState = PinsState.fromOrdinal(pinMaxSize); - final PacketPinsUpdate p = new PacketPinsUpdate(newState); - NetworkHandler.instance.sendToServer(p); - } catch (final IOException e) { - AELog.debug(e); - } - } - - @Override - public void initGui() { - Keyboard.enableRepeatEvents(true); - - this.maxRows = this.getMaxRows(); - this.perRow = AEConfig.instance.getConfigManager().getSetting(Settings.TERMINAL_STYLE) != TerminalStyle.FULL ? 9 - : 9 + ((this.width - this.standardSize) / 18); - - final boolean hasNEI = IntegrationRegistry.INSTANCE.isEnabled(IntegrationType.NEI); - - final int NEI = hasNEI ? 1 : 0; - int top = hasNEI ? 22 : 0; - - final int magicNumber = 114 + 1; - final int extraSpace = this.height - magicNumber - NEI - top - this.reservedSpace; - - this.rows = (int) Math.floor(extraSpace / 18.0); - if (this.rows > this.maxRows) { - this.rows = this.maxRows; - } - - if (hasNEI) { - this.rows--; - } - - if (this.rows < 3) { - this.rows = 3; - } - - this.getMeSlots().clear(); - - // make sure we have space at least for one row of normal slots, because pins not adjusted by scroll bar - adjustPinsSize(); - - int pinsRows = pinsState.ordinal(); - for (int y = 0; y < pinsRows; y++) { - for (int x = 0; x < this.perRow; x++) { - this.getMeSlots() - .add(new PinSlotME(this.repo, x + y * this.perRow, this.offsetX + x * 18, y * 18 + 18)); - } - } - - for (int y = 0; y < this.rows - pinsRows; y++) { - for (int x = 0; x < this.perRow; x++) { - this.getMeSlots().add( - new InternalSlotME( - this.repo, - x + y * this.perRow, - this.offsetX + x * 18, - 18 + y * 18 + pinsRows * 18)); - } - } - - if (AEConfig.instance.getConfigManager().getSetting(Settings.TERMINAL_STYLE) != TerminalStyle.FULL) { - this.xSize = this.standardSize + ((this.perRow - 9) * 18); - } else { - this.xSize = this.standardSize; - } - - super.initGui(); - this.setScrollBar(); - // full size : 204 - // extra slots : 72 - // slot 18 - - this.ySize = magicNumber + this.rows * 18 + this.reservedSpace; - final int unusedSpace = this.height - this.ySize; - this.guiTop = (int) Math.floor(unusedSpace / (unusedSpace < 0 ? 3.8f : 2.0f)); - - this.offsetY = this.guiTop + 8; - - buttonList.clear(); - if (this.customSortOrder) { - this.buttonList.add( - this.SortByBox = new GuiImgButton( - this.guiLeft - 18, - this.offsetY, - Settings.SORT_BY, - this.configSrc.getSetting(Settings.SORT_BY))); - this.offsetY += 20; - } - if (this.showViewBtn) { - this.buttonList.add( - this.ViewBox = new GuiImgButton( - this.guiLeft - 18, - this.offsetY, - Settings.VIEW_MODE, - this.configSrc.getSetting(Settings.VIEW_MODE))); - this.offsetY += 20; - } - if (ModAndClassUtil.isTypeFilter && this instanceof GuiItemMonitor) { - this.buttonList.add( - this.typeFilter = new GuiImgButton( - this.guiLeft - 18, - this.offsetY, - Settings.TYPE_FILTER, - this.configSrc.getSetting(Settings.TYPE_FILTER))); - this.offsetY += 20; - } - - this.buttonList.add( - this.SortDirBox = new GuiImgButton( - this.guiLeft - 18, - this.offsetY, - Settings.SORT_DIRECTION, - this.configSrc.getSetting(Settings.SORT_DIRECTION))); - this.offsetY += 20; - - this.buttonList.add( - this.searchBoxSettings = new GuiImgButton( - this.guiLeft - 18, - this.offsetY, - Settings.SEARCH_MODE, - AEConfig.instance.settings.getSetting(Settings.SEARCH_MODE))); - this.offsetY += 20; - - if (ModAndClassUtil.isSaveText) { - this.buttonList.add( - this.searchStringSave = new GuiImgButton( - this.guiLeft - 18, - this.offsetY, - Settings.SAVE_SEARCH, - AEConfig.instance.preserveSearchBar ? YesNo.YES : YesNo.NO)); - this.offsetY += 20; - } - - this.buttonList.add( - this.terminalStyleBox = new GuiImgButton( - this.guiLeft - 18, - this.offsetY, - Settings.TERMINAL_STYLE, - AEConfig.instance.settings.getSetting(Settings.TERMINAL_STYLE))); - this.offsetY += 20; - - this.searchField = new MEGuiTextField(90, 12) { - - @Override - public void onTextChange(final String oldText) { - final String text = getText(); - repo.setSearchString(text); - repo.updateView(); - setScrollBar(); - } - }; - this.searchField.x = this.guiLeft + Math.max(80, this.offsetX); - this.searchField.y = this.guiTop + 4; - this.searchField.setMaxStringLength(25); - if (ModAndClassUtil.isSearchStringTooltip) - searchField.setMessage(ButtonToolTips.SearchStringTooltip.getLocal()); - - if (this.viewCell) { - if (ModAndClassUtil.isCraftStatus && AEConfig.instance.getConfigManager() - .getSetting(Settings.CRAFTING_STATUS).equals(CraftingStatus.BUTTON)) { - this.buttonList.add( - this.craftingStatusImgBtn = new GuiImgButton( - this.guiLeft - 18, - this.offsetY, - Settings.CRAFTING_STATUS, - AEConfig.instance.settings.getSetting(Settings.CRAFTING_STATUS))); - this.offsetY += 20; - } else { - this.buttonList.add( - this.craftingStatusBtn = new GuiTabButton( - this.guiLeft + 170, - this.guiTop - 4, - 2 + 11 * 16, - GuiText.CraftingStatus.getLocal(), - itemRender)); - this.craftingStatusBtn.setHideEdge(13); // GuiTabButton implementation // - } - } - - if (hasPinHost) { - this.buttonList.add( - this.pinsStateButton = new GuiImgButton( - this.guiLeft + 177, - this.guiTop + 18 + (rows * 18) + 26, - Settings.PINS_STATE, - configSrc.getSetting(Settings.PINS_STATE))); - } - - final Enum setting = AEConfig.instance.settings.getSetting(Settings.SEARCH_MODE); - this.canBeAutoFocused = SearchBoxMode.AUTOSEARCH == setting || SearchBoxMode.NEI_AUTOSEARCH == setting; - this.searchField.setFocused(this.canBeAutoFocused); - this.isAutoFocused = this.canBeAutoFocused; - - if (ModAndClassUtil.isSearchBar && (AEConfig.instance.preserveSearchBar || this.isSubGui())) { - setSearchString(memoryText, false); - } - if (this.isSubGui()) { - this.repo.updateView(); - this.setScrollBar(); - } - - craftingGridOffsetX = Integer.MAX_VALUE; - craftingGridOffsetY = Integer.MAX_VALUE; - - for (final Object s : this.inventorySlots.inventorySlots) { - if (s instanceof AppEngSlot) { - if (((Slot) s).xDisplayPosition < 195 || s instanceof SlotDisabled) { - this.repositionSlot((AppEngSlot) s); - } - } - - if (s instanceof SlotCraftingMatrix || s instanceof SlotFakeCraftingMatrix) { - final Slot g = (Slot) s; - if (g.xDisplayPosition > 0 && g.yDisplayPosition > 0) { - craftingGridOffsetX = Math.min(craftingGridOffsetX, g.xDisplayPosition); - craftingGridOffsetY = Math.min(craftingGridOffsetY, g.yDisplayPosition); - } - } - } - - craftingGridOffsetX -= 25; - craftingGridOffsetY -= 6; - initGuiDone(); - } - - public void setSearchString(String memoryText, boolean updateView) { - this.searchField.setText(memoryText); - this.searchField.setCursorPositionEnd(); - this.repo.setSearchString(memoryText); - if (updateView) { - this.repo.updateView(); - this.setScrollBar(); - } - } - - @Override - protected void mouseClicked(final int xCoord, final int yCoord, final int btn) { - this.searchField.mouseClicked(xCoord, yCoord, btn); - isAutoFocused = false; - super.mouseClicked(xCoord, yCoord, btn); - } - - @Override - public void handleMouseInput() { - final int wheel = Mouse.getEventDWheel(); - final int x = Mouse.getEventX() * this.width / this.mc.displayWidth; - final int y = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight; - - if (wheel != 0 && this.searchField.isMouseIn(x, y) && isCtrlKeyDown()) { - final Enum searchMode = AEConfig.instance.settings.getSetting(Settings.SEARCH_MODE); - if (searchMode == SearchBoxMode.NEI_MANUAL_SEARCH || searchMode == SearchBoxMode.NEI_AUTOSEARCH) { - try { - Field cls = LayoutManager.searchField.getClass().getDeclaredField("history"); - cls.setAccessible(true); - TextHistory history = ((TextHistory) cls.get("get")); - TextHistory.Direction direction; - if (wheel > 0) { - direction = TextHistory.Direction.PREVIOUS; - } else { - direction = TextHistory.Direction.NEXT; - } - history.get(direction, this.searchField.getText()).map(newText -> { - setSearchString(newText, true); - return true; - }).orElse(false); - return; - } catch (NoSuchFieldException | IllegalAccessException ignore) {} - } - } - super.handleMouseInput(); - } - - @Override - protected void handleMouseClick(final Slot slot, final int slotIdx, final int ctrlDown, final int mouseButton) { - final EntityPlayer player = Minecraft.getMinecraft().thePlayer; - if (mouseButton == 3) { - if (slot instanceof OptionalSlotFake || slot instanceof SlotFakeCraftingMatrix) { - if (slot.getHasStack()) { - InventoryAction action = InventoryAction.SET_PATTERN_VALUE; - if (isCtrlKeyDown()) { - action = InventoryAction.RENAME_PATTERN_ITEM; - } - IAEItemStack stack = AEItemStack.create(slot.getStack()); - ((AEBaseContainer) this.inventorySlots).setTargetStack(stack); - for (int i = 0; i < this.inventorySlots.inventorySlots.size(); i++) { - if (slot.equals(this.inventorySlots.inventorySlots.get(i))) { - FluidCraft.proxy.netHandler.sendToServer(new CPacketInventoryAction(action, i, 0, stack)); - } - } - return; - } - } - } - - if (slot instanceof SlotFake) { - InventoryAction action = ctrlDown == 1 ? InventoryAction.SPLIT_OR_PLACE_SINGLE - : InventoryAction.PICKUP_OR_SET_DOWN; - if (Keyboard.isKeyDown(Keyboard.KEY_LMENU) || Keyboard.isKeyDown(Keyboard.KEY_RMENU)) { - if (action == InventoryAction.SPLIT_OR_PLACE_SINGLE) { - action = InventoryAction.MOVE_REGION; - } else { - action = InventoryAction.PICKUP_SINGLE; - } - } - if (this.drag_click.size() > 1) { - return; - } - final PacketInventoryAction p = new PacketInventoryAction(action, slotIdx, 0); - NetworkHandler.instance.sendToServer(p); - return; - } - - if (slot instanceof SlotPatternTerm) { - if (mouseButton == 6) { - return; // prevents weird double clicks - } - try { - NetworkHandler.instance.sendToServer(((SlotPatternTerm) slot).getRequest(isShiftKeyDown())); - } catch (final IOException e) { - AELog.debug(e); - } - } else if (slot instanceof SlotCraftingTerm) { - if (mouseButton == 6) { - return; // prevents weird double clicks - } - InventoryAction action; - if (isShiftKeyDown()) { - action = InventoryAction.CRAFT_SHIFT; - } else { - // Craft a stack on right-click, craft a single one on left-click - action = (mouseButton == 1) ? InventoryAction.CRAFT_STACK : InventoryAction.CRAFT_ITEM; - } - final PacketInventoryAction p = new PacketInventoryAction(action, slotIdx, 0); - NetworkHandler.instance.sendToServer(p); - return; - } - - if (Keyboard.isKeyDown(Keyboard.KEY_SPACE)) { - if (this.enableSpaceClicking() && !(slot instanceof SlotPatternTerm)) { - IAEItemStack stack = null; - if (slot instanceof SlotME) { - stack = ((SlotME) slot).getAEStack(); - } - int slotNum = Ae2ReflectClient.getInventorySlots(this).size(); - if (!(slot instanceof SlotME) && slot != null) { - slotNum = slot.slotNumber; - } - ((AEBaseContainer) this.inventorySlots).setTargetStack(stack); - final PacketInventoryAction p = new PacketInventoryAction(InventoryAction.MOVE_REGION, slotNum, 0); - NetworkHandler.instance.sendToServer(p); - return; - } - } - - if (slot instanceof SlotDisconnected) { - if (this.drag_click.size() > 1) { - return; - } - InventoryAction action = null; - switch (mouseButton) { - case 0: // pickup / set-down. - { - ItemStack heldStack = player.inventory.getItemStack(); - if (slot.getStack() == null && heldStack != null) action = InventoryAction.SPLIT_OR_PLACE_SINGLE; - else if (slot.getStack() != null && (heldStack == null || heldStack.stackSize <= 1)) - action = InventoryAction.PICKUP_OR_SET_DOWN; - } - break; - case 1: - action = ctrlDown == 1 ? InventoryAction.PICKUP_SINGLE : InventoryAction.SHIFT_CLICK; - break; - case 3: // creative dupe: - if (player.capabilities.isCreativeMode) { - action = InventoryAction.CREATIVE_DUPLICATE; - } - break; - default: - case 4: // drop item: - case 6: - } - if (action != null) { - final PacketInventoryAction p = new PacketInventoryAction( - action, - slot.getSlotIndex(), - ((SlotDisconnected) slot).getSlot().getId()); - NetworkHandler.instance.sendToServer(p); - } - return; - } - - if (slot instanceof SlotME sme) { - InventoryAction action = null; - IAEItemStack stack = null; - switch (mouseButton) { - case 0: // pickup / set-down. - action = ctrlDown == 1 ? InventoryAction.SPLIT_OR_PLACE_SINGLE : InventoryAction.PICKUP_OR_SET_DOWN; - if (sme.isPin() && player.inventory.getItemStack() != null) { - final PacketInventoryAction p = new PacketInventoryAction( - InventoryAction.SET_PIN, - sme.getPinIndex(), - 0); - NetworkHandler.instance.sendToServer(p); - return; - } - - stack = sme.getAEStack(); - if (stack != null && action == InventoryAction.PICKUP_OR_SET_DOWN - && stack.getStackSize() == 0 - && player.inventory.getItemStack() == null) { - action = InventoryAction.AUTO_CRAFT; - } - break; - case 1: - if (sme.isPin() && ctrlDown == 1) { // clear pin - final PacketInventoryAction p = new PacketInventoryAction( - InventoryAction.SET_PIN, - sme.getPinIndex(), - -1); - NetworkHandler.instance.sendToServer(p); - return; - } - - action = ctrlDown == 1 ? InventoryAction.PICKUP_SINGLE : InventoryAction.SHIFT_CLICK; - stack = ((SlotME) slot).getAEStack(); - break; - case 3: // creative dupe: - stack = ((SlotME) slot).getAEStack(); - stack = transformItem(stack); // for fluid terminal - if (stack != null && stack.isCraftable()) { - action = InventoryAction.AUTO_CRAFT; - } else if (player.capabilities.isCreativeMode) { - final IAEItemStack slotItem = ((SlotME) slot).getAEStack(); - if (slotItem != null) { - action = InventoryAction.CREATIVE_DUPLICATE; - } - } - break; - default: - case 4: // drop item: - case 6: - } - if (action == InventoryAction.AUTO_CRAFT) { - ((AEBaseContainer) this.inventorySlots).setTargetStack(stack); - FluidCraft.proxy.netHandler.sendToServer( - new CPacketInventoryAction(action, Ae2ReflectClient.getInventorySlots(this).size(), 0, stack)); - } else if (action != null) { - ((AEBaseContainer) this.inventorySlots).setTargetStack(stack); - final PacketInventoryAction p = new PacketInventoryAction( - action, - Ae2ReflectClient.getInventorySlots(this).size(), - 0); - NetworkHandler.instance.sendToServer(p); - } - - return; - } - - super.handleMouseClick(slot, slotIdx, ctrlDown, mouseButton); - } - - protected IAEItemStack transformItem(IAEItemStack stack) { - return stack; - } - - @Override - public void onGuiClosed() { - super.onGuiClosed(); - Keyboard.enableRepeatEvents(false); - memoryText = this.searchField.getText(); - } - - @Override - public void handleKeyboardInput() { - super.handleKeyboardInput(); - - // Pause the terminal when holding shift - this.repo.setPaused(hasShiftDown()); - } - - private boolean hasShiftDown() { - return Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT); - } - - public void bindTextureBack(final String file) { - final ResourceLocation loc = new ResourceLocation(FluidCraft.MODID, "textures/" + file); - this.mc.getTextureManager().bindTexture(loc); - } - - @Override - public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) { - this.bindTextureBack(this.getBackground()); - final int x_width = 195; - this.drawTexturedModalRect(offsetX, offsetY, 0, 0, x_width, 18); - if (this.viewCell) { - this.drawTexturedModalRect(offsetX + x_width, offsetY, x_width, 0, 46, 128); - } - for (int x = 0; x < this.rows; x++) { - this.drawTexturedModalRect(offsetX, offsetY + 18 + x * 18, 0, 18, x_width, 18); - } - this.drawTexturedModalRect( - offsetX, - offsetY + 16 + this.rows * 18 + this.lowerTextureOffset, - 0, - 106 - 18 - 18, - x_width, - 99 + this.reservedSpace - this.lowerTextureOffset); - if (this.viewCell) { - boolean update = false; - for (int i = 0; i < 5; i++) { - if (this.myCurrentViewCells[i] != this.monitorableContainer.getCellViewSlot(i).getStack()) { - update = true; - this.myCurrentViewCells[i] = this.monitorableContainer.getCellViewSlot(i).getStack(); - } - } - if (update) { - this.repo.setViewCell(this.myCurrentViewCells); - } - } - if (this.searchField != null) { - this.searchField.drawTextBox(); - } - - this.currentMouseX = mouseX; - this.currentMouseY = mouseY; - } - - protected String getBackground() { - return "gui/terminal.png"; - } - - @Override - protected boolean isPowered() { - return this.repo.hasPower(); - } - - protected int getMaxRows() { - return AEConfig.instance.getConfigManager().getSetting(Settings.TERMINAL_STYLE) == TerminalStyle.SMALL ? 6 - : Integer.MAX_VALUE; - } - - protected void repositionSlot(final AppEngSlot s) { - s.yDisplayPosition = s.getY() + this.ySize - 78 - 5; - } - - @Override - protected void keyTyped(final char character, final int key) { - if (character == ' ' && this.searchField.getText().isEmpty()) { - return; - } - - boolean skipHotbarCheck = searchField.isFocused() - && (AEConfig.instance.searchBoxFocusPriority == SearchBoxFocusPriority.ALWAYS - || (AEConfig.instance.searchBoxFocusPriority == SearchBoxFocusPriority.NO_AUTOSEARCH - && !isAutoFocused)); - - if (!skipHotbarCheck && checkHotbarKeys(key)) { - return; - } - - final boolean mouseInGui = this - .isPointInRegion(0, 0, this.xSize, this.ySize, this.currentMouseX, this.currentMouseY); - - if (this.canBeAutoFocused && !searchField.isFocused() && mouseInGui) { - searchField.setFocused(true); - isAutoFocused = true; - } - - if (!searchField.textboxKeyTyped(character, key)) { - super.keyTyped(character, key); - } - } - - @Override - public void updateScreen() { - this.repo.setPowered(this.monitorableContainer.isPowered()); - super.updateScreen(); - } - - @Override - public Enum getSortBy() { - return this.configSrc.getSetting(Settings.SORT_BY); - } - - @Override - public Enum getSortDir() { - return this.configSrc.getSetting(Settings.SORT_DIRECTION); - } - - @Override - public Enum getSortDisplay() { - return this.configSrc.getSetting(Settings.VIEW_MODE); - } - - @Override - public Enum getTypeFilter() { - return this.configSrc.getSetting(Settings.TYPE_FILTER); - } - - @Override - public void updateSetting(final IConfigManager manager, @SuppressWarnings("rawtypes") final Enum settingName, - @SuppressWarnings("rawtypes") final Enum newValue) { - if (this.SortByBox != null) { - this.SortByBox.set(this.configSrc.getSetting(Settings.SORT_BY)); - } - - if (this.SortDirBox != null) { - this.SortDirBox.set(this.configSrc.getSetting(Settings.SORT_DIRECTION)); - } - - if (this.ViewBox != null) { - this.ViewBox.set(this.configSrc.getSetting(Settings.VIEW_MODE)); - } - if (this.typeFilter != null) { - this.typeFilter.set(this.configSrc.getSetting(Settings.TYPE_FILTER)); - } - - if (this.pinsStateButton != null) { - pinsState = (PinsState) this.configSrc.getSetting(Settings.PINS_STATE); - this.pinsStateButton.set(pinsState); - - initGui(); - } - - this.repo.updateView(); - } - - public int getReservedSpace() { - return this.reservedSpace; - } - - public void setReservedSpace(final int reservedSpace) { - this.reservedSpace = reservedSpace; - } - - public boolean isCustomSortOrder() { - return this.customSortOrder; - } - - public void setCustomSortOrder(final boolean customSortOrder) { - this.customSortOrder = customSortOrder; - } - - public int getStandardSize() { - return this.standardSize; - } - - public void setStandardSize(final int standardSize) { - this.standardSize = standardSize; - } - - public boolean isOverSearchField(int x, int y) { - return searchField.isMouseIn(x, y); - } - - public boolean hideItemPanelSlot(int tx, int ty, int tw, int th) { - if (this.viewCell) { - int rw = 33; - int rh = 14 + myCurrentViewCells.length * 18; - - if (tw <= 0 || th <= 0) { - return false; - } - - int rx = this.guiLeft + this.xSize; - int ry = this.guiTop; - - rw += rx; - rh += ry; - tw += tx; - th += ty; - - // overflow || intersect - return (rw < rx || rw > tx) && (rh < ry || rh > ty) && (tw < tx || tw > rx) && (th < ty || th > ry); - } - return false; - } - - @Override - public boolean isOverTextField(int mousex, int mousey) { - return searchField.isMouseIn(mousex, mousey); - } - - @Override - public void setAEPins(IAEItemStack[] pins) { - if (repo instanceof ItemRepo) repo.setAEPins(pins); - } - - @Override - public void setPinsState(PinsState state) { - configSrc.putSetting(Settings.PINS_STATE, state); - } - - @SuppressWarnings("SameParameterValue") - protected boolean isPointInRegion(int rectX, int rectY, int rectWidth, int rectHeight, int pointX, int pointY) { - pointX -= this.guiLeft; - pointY -= this.guiTop; - return pointX >= rectX - 1 && pointX < rectX + rectWidth + 1 - && pointY >= rectY - 1 - && pointY < rectY + rectHeight + 1; - } - - // Moving items via hotbar keys in terminals isn't working anyway. - // Let's disable hotbar keys processing for terminal slots to allow proper input of numbers in the search field - @Override - protected boolean checkHotbarKeys(int keyCode) { - if (theSlot instanceof SlotME) { - return false; - } - return super.checkHotbarKeys(keyCode); - } -} diff --git a/src/main/java/com/glodblock/github/client/gui/container/ContainerCraftingWireless.java b/src/main/java/com/glodblock/github/client/gui/container/ContainerCraftingWireless.java deleted file mode 100644 index df3732e4..00000000 --- a/src/main/java/com/glodblock/github/client/gui/container/ContainerCraftingWireless.java +++ /dev/null @@ -1,109 +0,0 @@ -package com.glodblock.github.client.gui.container; - -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.InventoryCrafting; -import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.CraftingManager; - -import com.glodblock.github.inventory.ItemBiggerAppEngInventory; -import com.glodblock.github.inventory.item.IWirelessCraftTerminal; -import com.glodblock.github.inventory.item.IWirelessTerminal; - -import appeng.container.ContainerNull; -import appeng.container.slot.SlotCraftingMatrix; -import appeng.container.slot.SlotCraftingTerm; -import appeng.helpers.IContainerCraftingPacket; -import appeng.tile.inventory.AppEngInternalInventory; -import appeng.tile.inventory.IAEAppEngInventory; -import appeng.tile.inventory.InvOperation; - -public class ContainerCraftingWireless extends ContainerItemMonitor - implements IAEAppEngInventory, IContainerCraftingPacket { - - private final IWirelessCraftTerminal it; - private final SlotCraftingMatrix[] craftingSlots = new SlotCraftingMatrix[9]; - private final SlotCraftingTerm outputSlot; - - public ContainerCraftingWireless(final InventoryPlayer ip, final IWirelessTerminal monitorable) { - super(ip, monitorable, false); - this.it = (IWirelessCraftTerminal) monitorable; - final IInventory crafting = this.it.getInventoryByName("crafting"); - for (int y = 0; y < 3; y++) { - for (int x = 0; x < 3; x++) { - this.addSlotToContainer( - this.craftingSlots[x + y * 3] = new SlotCraftingMatrix( - this, - crafting, - x + y * 3, - 37 + x * 18, - -72 + y * 18) { - - @Override - public void onSlotChanged() { - if (this.inventory instanceof ItemBiggerAppEngInventory i) { - i.markDirty(); - } - super.onSlotChanged(); - } - }); - } - } - AppEngInternalInventory output = new AppEngInternalInventory(this, 1); - this.addSlotToContainer( - this.outputSlot = new SlotCraftingTerm( - this.getPlayerInv().player, - this.getActionSource(), - this.getPowerSource(), - monitorable, - crafting, - crafting, - output, - 131, - -72 + 18, - this)); - this.bindPlayerInventory(ip, 0, 0); - this.onCraftMatrixChanged(crafting); - } - - @Override - protected boolean isWirelessTerminal() { - return true; - } - - @Override - public void onCraftMatrixChanged(final IInventory par1IInventory) { - final ContainerNull cn = new ContainerNull(); - final InventoryCrafting ic = new InventoryCrafting(cn, 3, 3); - for (int x = 0; x < 9; x++) { - ic.setInventorySlotContents(x, this.craftingSlots[x].getStack()); - } - this.outputSlot - .putStack(CraftingManager.getInstance().findMatchingRecipe(ic, this.getPlayerInv().player.worldObj)); - } - - @Override - public void saveChanges() { - // NO-OP - } - - @Override - public void onChangeInventory(final IInventory inv, final int slot, final InvOperation mc, - final ItemStack removedStack, final ItemStack newStack) { - // NO-OP - } - - @Override - public IInventory getInventoryByName(final String name) { - if (name.equals("player")) { - return this.getInventoryPlayer(); - } - return this.it.getInventoryByName(name); - } - - @Override - public boolean useRealItems() { - return true; - } - -} diff --git a/src/main/java/com/glodblock/github/client/gui/container/ContainerDualInterface.java b/src/main/java/com/glodblock/github/client/gui/container/ContainerDualInterface.java deleted file mode 100644 index 21151255..00000000 --- a/src/main/java/com/glodblock/github/client/gui/container/ContainerDualInterface.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.glodblock.github.client.gui.container; - -import net.minecraft.entity.player.InventoryPlayer; - -import com.glodblock.github.common.tile.TileFluidInterface; - -import appeng.api.config.Settings; -import appeng.api.config.SidelessMode; -import appeng.api.util.IConfigManager; -import appeng.container.guisync.GuiSync; -import appeng.container.implementations.ContainerInterface; -import appeng.helpers.IInterfaceHost; - -public class ContainerDualInterface extends ContainerInterface { - - @GuiSync(11) - public SidelessMode sidelessMode; - - private final boolean isTile; - - public ContainerDualInterface(InventoryPlayer ip, IInterfaceHost te) { - super(ip, te); - this.sidelessMode = SidelessMode.SIDELESS; - this.isTile = te instanceof TileFluidInterface; - } - - public SidelessMode getSidelessMode() { - return this.sidelessMode; - } - - @Override - protected void loadSettingsFromHost(IConfigManager cm) { - super.loadSettingsFromHost(cm); - this.sidelessMode = this.isTile ? (SidelessMode) cm.getSetting(Settings.SIDELESS_MODE) : SidelessMode.SIDELESS; - } -} diff --git a/src/main/java/com/glodblock/github/client/gui/container/ContainerEssentiaMonitor.java b/src/main/java/com/glodblock/github/client/gui/container/ContainerEssentiaMonitor.java deleted file mode 100644 index 587eb23d..00000000 --- a/src/main/java/com/glodblock/github/client/gui/container/ContainerEssentiaMonitor.java +++ /dev/null @@ -1,159 +0,0 @@ -package com.glodblock.github.client.gui.container; - -import java.util.HashMap; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; - -import org.apache.commons.lang3.tuple.MutablePair; - -import com.glodblock.github.FluidCraft; -import com.glodblock.github.crossmod.thaumcraft.AspectUtil; -import com.glodblock.github.inventory.item.IWirelessTerminal; -import com.glodblock.github.network.CPacketFluidUpdate; -import com.glodblock.github.network.SPacketFluidUpdate; -import com.glodblock.github.util.Util; - -import appeng.api.config.Actionable; -import appeng.api.storage.data.IAEFluidStack; -import appeng.container.slot.SlotPlayerHotBar; -import appeng.container.slot.SlotPlayerInv; -import appeng.util.Platform; - -public class ContainerEssentiaMonitor extends ContainerFluidPortableCell { - - public ContainerEssentiaMonitor(InventoryPlayer ip, IWirelessTerminal monitorable) { - super(ip, monitorable); - } - - @Override - public ItemStack transferStackInSlot(final EntityPlayer p, final int idx) { - if (Platform.isClient()) { - Slot clickSlot = (Slot) this.inventorySlots.get(idx); - if ((clickSlot instanceof SlotPlayerInv || clickSlot instanceof SlotPlayerHotBar) && clickSlot.getHasStack() - && AspectUtil.isEssentiaContainer(clickSlot.getStack())) { - int index = Util.findItemInPlayerInvSlot(p, clickSlot.getStack()); - FluidCraft.proxy.netHandler.sendToServer(new CPacketFluidUpdate(index)); - } - } - return super.transferStackInSlot(p, idx); - } - - @Override - public void postChange(IAEFluidStack clientSelectedFluid, EntityPlayer player, int slotIndex, boolean shift) { - ItemStack targetStack; - if (slotIndex == -1) { - targetStack = player.inventory.getItemStack(); - } else { - targetStack = player.inventory.getStackInSlot(slotIndex); - } - final int containersRequested = shift ? targetStack.stackSize : 1; - - IAEFluidStack storedFluid = this.monitor.getStorageList().findPrecise(clientSelectedFluid); - ItemStack out = targetStack.copy(); - out.stackSize = 1; - if (AspectUtil.isEmptyEssentiaContainer(targetStack) && AspectUtil.isEssentiaGas(storedFluid)) { - // add essentia to jars - if (storedFluid.getStackSize() / AspectUtil.R <= 0) { - return; - } - final IAEFluidStack toExtract = storedFluid.copy(); - MutablePair fillStack = AspectUtil.fillEssentiaFromGas(out, toExtract.getFluidStack()); - if (fillStack == null || fillStack.right == null || fillStack.left <= 0) { - return; - } - toExtract.setStackSize((long) fillStack.left * containersRequested); - IAEFluidStack tmp = this.host.getFluidInventory() - .extractItems(toExtract, Actionable.SIMULATE, this.getActionSource()); - if (tmp == null) { - return; - } - fillStack.right.stackSize = (int) (tmp.getStackSize() / fillStack.left); - this.dropItem(fillStack.right); - out.stackSize = fillStack.right.stackSize; - if (AspectUtil.isEssentiaContainer(fillStack.right)) { - this.host.getFluidInventory().extractItems(toExtract, Actionable.MODULATE, this.getActionSource()); - if ((int) (tmp.getStackSize() % fillStack.left) / AspectUtil.R > 0) { - this.dropItem( - AspectUtil.setAspectAmount( - fillStack.right, - (int) (tmp.getStackSize() % fillStack.left) / AspectUtil.R, - AspectUtil.getAspectFromGas(toExtract)), - 1); - out.stackSize++; - } - } - } else if (!AspectUtil.isEmptyEssentiaContainer(targetStack)) { - // add essentia to ae network - ItemStack containerStack = targetStack.copy(); - containerStack.stackSize = containersRequested; - IAEFluidStack fluidStack = AspectUtil.getAEGasFromContainer(containerStack); - if (fluidStack == null) { - return; - } - final IAEFluidStack aeFluidStack = fluidStack.copy(); - // simulate result is incorrect. so I'm using other solution and ec2 both mod have same issues - final IAEFluidStack notInserted = this.host.getFluidInventory() - .injectItems(aeFluidStack, Actionable.MODULATE, this.getActionSource()); - MutablePair drainStack = AspectUtil - .drainEssentiaFromGas(out.copy(), aeFluidStack.getFluidStack()); - if (notInserted != null && notInserted.getStackSize() > 0 && drainStack != null) { - if (fluidStack.getStackSize() == notInserted.getStackSize()) { - return; - } - aeFluidStack.decStackSize(notInserted.getStackSize()); - - if (drainStack.left > aeFluidStack.getStackSize() && AspectUtil.isEssentiaContainer(drainStack.right)) { - aeFluidStack.setStackSize(drainStack.left - aeFluidStack.getStackSize()); - this.host.getFluidInventory() - .extractItems(aeFluidStack, Actionable.MODULATE, this.getActionSource()); - return; - } - - // drop empty item - this.dropItem(drainStack.right, (int) (aeFluidStack.getStackSize() / drainStack.left)); - out.stackSize = (int) (notInserted.getStackSize() / drainStack.left); - if (AspectUtil.isEssentiaContainer(drainStack.right)) { - if (notInserted.getStackSize() % drainStack.left > 0) { - fluidStack.setStackSize((notInserted.getStackSize() % drainStack.left)); - AspectUtil.fillEssentiaFromGas(drainStack.right, fluidStack.getFluidStack()); - this.dropItem(drainStack.right, 1); - } - } - if (slotIndex == -1) out.stackSize = targetStack.stackSize - out.stackSize; - } else if (drainStack != null) { - if (slotIndex == -1) { - out.stackSize = targetStack.stackSize; - } else { - out.stackSize = (int) (targetStack.stackSize - (aeFluidStack.getStackSize() / drainStack.left)); - } - this.dropItem(drainStack.right, targetStack.stackSize); // drop empty item - } - } else { - return; - } - if (slotIndex == -1) { - player.inventory.getItemStack().stackSize = player.inventory.getItemStack().stackSize - out.stackSize; - if (player.inventory.getItemStack().stackSize > 0) { - FluidCraft.proxy.netHandler.sendTo( - new SPacketFluidUpdate(new HashMap<>(), player.inventory.getItemStack()), - (EntityPlayerMP) player); - } else { - player.inventory.setItemStack(null); - FluidCraft.proxy.netHandler.sendTo(new SPacketFluidUpdate(new HashMap<>()), (EntityPlayerMP) player); - } - } else { - player.inventory.setInventorySlotContents(slotIndex, out.stackSize > 0 ? out : null); - } - this.detectAndSendChanges(); - } - - @Override - protected boolean isEssentiaMode() { - return true; - } - -} diff --git a/src/main/java/com/glodblock/github/client/gui/container/ContainerFluidCraftConfirm.java b/src/main/java/com/glodblock/github/client/gui/container/ContainerFluidCraftConfirm.java deleted file mode 100644 index 2a858683..00000000 --- a/src/main/java/com/glodblock/github/client/gui/container/ContainerFluidCraftConfirm.java +++ /dev/null @@ -1,98 +0,0 @@ -package com.glodblock.github.client.gui.container; - -import java.util.Objects; - -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.item.ItemStack; -import net.minecraftforge.common.util.ForgeDirection; - -import com.glodblock.github.common.item.ItemBaseWirelessTerminal; -import com.glodblock.github.common.parts.PartFluidPatternTerminal; -import com.glodblock.github.common.parts.PartFluidPatternTerminalEx; -import com.glodblock.github.common.parts.PartLevelTerminal; -import com.glodblock.github.inventory.InventoryHandler; -import com.glodblock.github.inventory.gui.GuiType; -import com.glodblock.github.inventory.item.IWirelessTerminal; -import com.glodblock.github.util.BlockPos; - -import appeng.api.networking.IGrid; -import appeng.api.networking.security.IActionHost; -import appeng.api.storage.ITerminalHost; -import appeng.container.implementations.ContainerCraftConfirm; -import appeng.container.implementations.ContainerOptimizePatterns; -import appeng.crafting.v2.CraftingJobV2; -import appeng.tile.misc.TilePatternOptimizationMatrix; - -public class ContainerFluidCraftConfirm extends ContainerCraftConfirm { - - public ContainerFluidCraftConfirm(final InventoryPlayer ip, final ITerminalHost te) { - super(ip, te); - } - - @Override - public void switchToOriginalGUI() { - GuiType originalGui = null; - - final IActionHost ah = this.getActionHost(); - if (ah instanceof PartFluidPatternTerminal) { - originalGui = GuiType.FLUID_PATTERN_TERMINAL; - } - if (ah instanceof PartFluidPatternTerminalEx) { - originalGui = GuiType.FLUID_PATTERN_TERMINAL_EX; - } - if (ah instanceof PartLevelTerminal) { - originalGui = GuiType.LEVEL_TERMINAL; - } - if (ah instanceof IWirelessTerminal) { - ItemStack terminal = ((IWirelessTerminal) ah).getItemStack(); - if (terminal.getItem() instanceof ItemBaseWirelessTerminal) { - originalGui = ((ItemBaseWirelessTerminal) terminal.getItem()).guiGuiType(terminal); - } - } - if (ah instanceof IWirelessTerminal) { - InventoryHandler.openGui( - this.getInventoryPlayer().player, - getWorld(), - new BlockPos(((IWirelessTerminal) ah).getInventorySlot(), 0, 0), - ForgeDirection.UNKNOWN, - originalGui); - } else if (this.getOpenContext() != null) { - InventoryHandler.openGui( - this.getInventoryPlayer().player, - getWorld(), - new BlockPos(this.getOpenContext().getTile()), - Objects.requireNonNull(this.getOpenContext().getSide()), - originalGui); - } - } - - @Override - public void optimizePatterns() { - // only V2 supported - IGrid grid = this.getGrid(); - - if (result instanceof CraftingJobV2 && !this.isSimulation() - && grid != null - && !grid.getMachines(TilePatternOptimizationMatrix.class).isEmpty()) { - final IActionHost ah = this.getActionHost(); - if (ah instanceof IWirelessTerminal) { - InventoryHandler.openGui( - this.getInventoryPlayer().player, - getWorld(), - new BlockPos(((IWirelessTerminal) ah).getInventorySlot(), 0, 0), - ForgeDirection.UNKNOWN, - GuiType.FLUID_OPTIMIZE_PATTERNS_ITEM); - } else if (this.getOpenContext() != null) { - InventoryHandler.openGui( - this.getInventoryPlayer().player, - getWorld(), - new BlockPos(this.getOpenContext().getTile()), - Objects.requireNonNull(this.getOpenContext().getSide()), - GuiType.FLUID_OPTIMIZE_PATTERNS); - } - if (this.getPlayerInv().player.openContainer instanceof ContainerOptimizePatterns cop) { - cop.setResult(result); - } - } - } -} diff --git a/src/main/java/com/glodblock/github/client/gui/container/ContainerFluidIO.java b/src/main/java/com/glodblock/github/client/gui/container/ContainerFluidIO.java deleted file mode 100644 index ed537e02..00000000 --- a/src/main/java/com/glodblock/github/client/gui/container/ContainerFluidIO.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.glodblock.github.client.gui.container; - -import net.minecraft.entity.player.InventoryPlayer; - -import com.glodblock.github.client.gui.container.base.FCContainerFluidConfigurable; -import com.glodblock.github.common.parts.PartFluidExportBus; -import com.glodblock.github.common.parts.base.FCSharedFluidBus; - -import appeng.api.config.SchedulingMode; -import appeng.api.config.Settings; -import appeng.api.config.YesNo; -import appeng.api.util.IConfigManager; -import appeng.tile.inventory.AppEngInternalAEInventory; - -public class ContainerFluidIO extends FCContainerFluidConfigurable { - - private final FCSharedFluidBus bus; - - public ContainerFluidIO(InventoryPlayer ip, FCSharedFluidBus te) { - super(ip, te); - this.bus = te; - } - - public FCSharedFluidBus getBus() { - return this.bus; - } - - @Override - public AppEngInternalAEInventory getFakeFluidInv() { - return (AppEngInternalAEInventory) this.bus.getInventoryByName("config"); - } - - @Override - protected void loadSettingsFromHost(IConfigManager cm) { - super.loadSettingsFromHost(cm); - if (this.getUpgradeable() instanceof PartFluidExportBus) { - this.setCraftingMode((YesNo) cm.getSetting(Settings.CRAFT_ONLY)); - this.setSchedulingMode((SchedulingMode) cm.getSetting(Settings.SCHEDULING_MODE)); - } - } - - public void setSchedulingMode(final SchedulingMode schedulingMode) { - this.schedulingMode = schedulingMode; - } -} diff --git a/src/main/java/com/glodblock/github/client/gui/container/ContainerFluidInterface.java b/src/main/java/com/glodblock/github/client/gui/container/ContainerFluidInterface.java index f72ec718..9e4617b8 100644 --- a/src/main/java/com/glodblock/github/client/gui/container/ContainerFluidInterface.java +++ b/src/main/java/com/glodblock/github/client/gui/container/ContainerFluidInterface.java @@ -15,11 +15,11 @@ import com.glodblock.github.inventory.slot.OptionalFluidSlotFakeTypeOnly; import com.glodblock.github.network.SPacketFluidUpdate; import appeng.api.storage.data.IAEFluidStack; -import appeng.container.AEBaseContainer; +import appeng.container.ContainerSubGui; import appeng.container.slot.IOptionalSlotHost; import appeng.util.item.AEFluidStack; -public class ContainerFluidInterface extends AEBaseContainer implements IOptionalSlotHost { +public class ContainerFluidInterface extends ContainerSubGui implements IOptionalSlotHost { private final IDualHost tile; diff --git a/src/main/java/com/glodblock/github/client/gui/container/ContainerFluidLevelEmitter.java b/src/main/java/com/glodblock/github/client/gui/container/ContainerFluidLevelEmitter.java deleted file mode 100644 index 5e8e72b6..00000000 --- a/src/main/java/com/glodblock/github/client/gui/container/ContainerFluidLevelEmitter.java +++ /dev/null @@ -1,99 +0,0 @@ -package com.glodblock.github.client.gui.container; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.IInventory; - -import com.glodblock.github.client.gui.container.base.FCContainerFluidConfigurable; -import com.glodblock.github.common.parts.PartFluidLevelEmitter; -import com.glodblock.github.inventory.slot.OptionalFluidSlotFakeTypeOnly; - -import appeng.api.config.RedstoneMode; -import appeng.api.config.SecurityPermissions; -import appeng.api.config.Settings; -import appeng.client.gui.widgets.MEGuiTextField; -import appeng.container.guisync.GuiSync; -import appeng.tile.inventory.AppEngInternalAEInventory; -import appeng.util.Platform; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -public class ContainerFluidLevelEmitter extends FCContainerFluidConfigurable { - - private final PartFluidLevelEmitter lvlEmitter; - - @SideOnly(Side.CLIENT) - private MEGuiTextField textField; - - @GuiSync(2) - public long EmitterValue = -1; - - public ContainerFluidLevelEmitter(final InventoryPlayer ip, final PartFluidLevelEmitter te) { - super(ip, te); - this.lvlEmitter = te; - } - - public PartFluidLevelEmitter getBus() { - return this.lvlEmitter; - } - - public AppEngInternalAEInventory getFakeFluidInv() { - return (AppEngInternalAEInventory) this.lvlEmitter.getInventoryByName("config"); - } - - @Override - protected void setupConfig() { - final IInventory inv = this.getUpgradeable().getInventoryByName("config"); - this.addSlotToContainer(new OptionalFluidSlotFakeTypeOnly(inv, null, this, 0, 17, 42, 0, 0, 0)); - } - - @SideOnly(Side.CLIENT) - public void setTextField(final MEGuiTextField level) { - this.textField = level; - } - - public void setLevel(final long l, final EntityPlayer player) { - this.lvlEmitter.setReportingValue(l); - this.EmitterValue = l; - } - - @Override - protected boolean supportCapacity() { - return false; - } - - @Override - public int availableUpgrades() { - return 0; - } - - public void setRedStoneMode(final RedstoneMode rsMode) { - this.rsMode = rsMode; - } - - @Override - public void detectAndSendChanges() { - this.verifyPermissions(SecurityPermissions.BUILD, false); - - if (Platform.isServer()) { - this.EmitterValue = this.lvlEmitter.getReportingValue(); - this.setRedStoneMode( - (RedstoneMode) this.getUpgradeable().getConfigManager().getSetting(Settings.REDSTONE_EMITTER)); - } - - this.standardDetectAndSendChanges(); - } - - @Override - public void onUpdate(final String field, final Object oldValue, final Object newValue) { - if (field.equals("EmitterValue")) { - if (this.textField != null) { - this.textField.setText(String.valueOf(this.EmitterValue)); - - if (String.valueOf(oldValue).equals("-1")) { - this.textField.setCursorPositionEnd(); - } - } - } - } -} diff --git a/src/main/java/com/glodblock/github/client/gui/container/ContainerFluidMonitor.java b/src/main/java/com/glodblock/github/client/gui/container/ContainerFluidMonitor.java deleted file mode 100644 index 16b7f782..00000000 --- a/src/main/java/com/glodblock/github/client/gui/container/ContainerFluidMonitor.java +++ /dev/null @@ -1,560 +0,0 @@ -package com.glodblock.github.client.gui.container; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.ICrafting; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; -import net.minecraftforge.common.util.ForgeDirection; -import net.minecraftforge.fluids.FluidContainerRegistry; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.IFluidContainerItem; - -import com.glodblock.github.FluidCraft; -import com.glodblock.github.client.gui.container.base.FCContainerMonitor; -import com.glodblock.github.common.item.ItemFluidPacket; -import com.glodblock.github.network.CPacketFluidUpdate; -import com.glodblock.github.network.SPacketFluidUpdate; -import com.glodblock.github.network.SPacketMEUpdateBuffer; -import com.glodblock.github.util.Util; - -import appeng.api.AEApi; -import appeng.api.config.Actionable; -import appeng.api.implementations.tiles.IViewCellStorage; -import appeng.api.networking.IGrid; -import appeng.api.networking.IGridHost; -import appeng.api.networking.IGridNode; -import appeng.api.networking.energy.IEnergyGrid; -import appeng.api.networking.energy.IEnergySource; -import appeng.api.networking.security.BaseActionSource; -import appeng.api.networking.storage.IBaseMonitor; -import appeng.api.networking.storage.IStorageGrid; -import appeng.api.storage.ITerminalHost; -import appeng.api.storage.data.IAEFluidStack; -import appeng.api.storage.data.IItemList; -import appeng.container.slot.SlotPlayerHotBar; -import appeng.container.slot.SlotPlayerInv; -import appeng.container.slot.SlotRestrictedInput; -import appeng.me.helpers.ChannelPowerSrc; -import appeng.util.Platform; -import appeng.util.item.AEFluidStack; - -public class ContainerFluidMonitor extends FCContainerMonitor { - - protected final IItemList fluids = AEApi.instance().storage().createFluidList(); - /** - * Index of tuple which indicates remaining tanks that are remaining (not emptied/filled) - */ - protected static final int REM_IDX = 0; - /** - * Index of tuple which indicates remaining tanks that are acted upon (emptied/filled) - */ - protected static final int ACT_IDX = 1; - /** - * Index of tuple which indicates tanks that are partially emptied/filled - */ - protected static final int PARTIAL_IDX = 2; - - public ContainerFluidMonitor(final InventoryPlayer ip, final ITerminalHost monitorable) { - this(ip, monitorable, true); - } - - protected ContainerFluidMonitor(final InventoryPlayer ip, final ITerminalHost monitorable, - final boolean bindInventory) { - super(ip, monitorable, bindInventory); - if (Platform.isServer()) { - this.serverCM = monitorable.getConfigManager(); - if (monitorable instanceof IGridHost) { - final IGridNode node = ((IGridHost) monitorable).getGridNode(ForgeDirection.UNKNOWN); - if (node != null) { - this.networkNode = node; - final IGrid g = node.getGrid(); - if (g != null) { - this.setPowerSource(new ChannelPowerSrc(this.networkNode, g.getCache(IEnergyGrid.class))); - IStorageGrid storageGrid = g.getCache(IStorageGrid.class); - this.monitor = storageGrid.getFluidInventory(); - if (this.monitor == null) { - this.setValidContainer(false); - } else { - this.monitor.addListener(this, null); - } - } - } else { - this.setValidContainer(false); - } - } else { - this.monitor = monitorable.getFluidInventory(); - this.monitor.addListener(this, null); - this.setPowerSource((IEnergySource) monitorable); - } - } else { - this.monitor = null; - } - - this.canAccessViewCells = false; - if (monitorable instanceof IViewCellStorage) { - for (int y = 0; y < 5; y++) { - this.cellView[y] = new SlotRestrictedInput( - SlotRestrictedInput.PlacableItemType.VIEW_CELL, - ((IViewCellStorage) monitorable).getViewCellStorage(), - y, - 206, - y * 18 + 8, - this.getInventoryPlayer()); - this.cellView[y].setAllowEdit(this.canAccessViewCells); - this.addSlotToContainer(this.cellView[y]); - } - } - - if (bindInventory) { - this.bindPlayerInventory(ip, 0, 0); - } - } - - @Override - public ItemStack transferStackInSlot(final EntityPlayer p, final int idx) { - if (Platform.isClient() && !isEssentiaMode()) { - Slot clickSlot = (Slot) this.inventorySlots.get(idx); - if ((clickSlot instanceof SlotPlayerInv || clickSlot instanceof SlotPlayerHotBar) && clickSlot.getHasStack() - && Util.FluidUtil.isFluidContainer(clickSlot.getStack())) { - int index = Util.findItemInPlayerInvSlot(p, clickSlot.getStack()); - FluidCraft.proxy.netHandler.sendToServer(new CPacketFluidUpdate(index)); - } - } - return super.transferStackInSlot(p, idx); - } - - @Override - protected void processItemList() { - if (!this.fluids.isEmpty()) { - final IItemList monitorCache = this.monitor.getStorageList(); - List toSend = new ArrayList<>(); - for (final IAEFluidStack is : this.fluids) { - final IAEFluidStack send = monitorCache.findPrecise(is); - if (send != null) { - toSend.add(send); - } else { - is.setStackSize(0); - toSend.add(is); - } - } - for (final Object c : this.crafters) { - if (c instanceof EntityPlayerMP) { - SPacketMEUpdateBuffer.scheduleFluidUpdate((EntityPlayerMP) c, toSend); - } - } - this.fluids.resetStatus(); - } - } - - @Override - protected void queueInventory(final ICrafting c) { - if (Platform.isServer() && c instanceof EntityPlayerMP && this.monitor != null) { - final IItemList monitorCache = this.monitor.getStorageList(); - List toSend = new ArrayList<>(); - for (final IAEFluidStack is : monitorCache) { - toSend.add(is); - } - SPacketMEUpdateBuffer.scheduleFluidUpdate((EntityPlayerMP) c, toSend); - } - } - - @Override - public void postChange(IBaseMonitor monitor, Iterable change, - BaseActionSource actionSource) { - for (final IAEFluidStack is : change) { - this.fluids.add(is); - } - } - - protected void dropItem(ItemStack is) { - if (is == null || is.stackSize <= 0) return; - ItemStack itemStack = is.copy(); - int i = itemStack.getMaxStackSize(); - while (itemStack.stackSize > 0) { - if (i > itemStack.stackSize) { - if (!getPlayerInv().addItemStackToInventory(itemStack.copy())) { - getPlayerInv().player.entityDropItem(itemStack.copy(), 0); - } - break; - } else { - itemStack.stackSize -= i; - ItemStack item = itemStack.copy(); - item.stackSize = i; - if (!getPlayerInv().addItemStackToInventory(item)) { - getPlayerInv().player.entityDropItem(item, 0); - } - } - } - } - - protected void dropItem(ItemStack itemStack, int stackSize) { - if (itemStack == null || itemStack.stackSize <= 0) return; - ItemStack is = itemStack.copy(); - is.stackSize = stackSize; - this.dropItem(is); - } - - /** - * Two operations, insert and extract. - * - * @param slotIndex The slot. If index == -1, the cursor held itemstack. Else, slotIndex indicates which slot was - * shift clicked on. - */ - public void postChange(IAEFluidStack fluid, EntityPlayer player, int slotIndex, boolean shift) { - ItemStack targetStack; - if (slotIndex == -1) { - targetStack = player.inventory.getItemStack(); - } else { - targetStack = player.inventory.getStackInSlot(slotIndex); - } - // The primary output itemstack - if (Util.FluidUtil.isEmpty(targetStack) && fluid != null) { - // Situation 1.a: Empty fluid container, and nonnull slot - extractFluid(fluid, player, slotIndex, shift); - } else if (!Util.FluidUtil.isEmpty(targetStack)) { - // Situation 2.a: We are holding a non-empty container. - insertFluid(player, slotIndex, shift); - // End of situation 2.a - } - // No op (Any other situation) - this.detectAndSendChanges(); - } - - /** - * The insert operation. For input, we have a filled container stack. For outputs, we have the following: - *
    - *
  1. Leftover filled container stack
  2. - *
  3. Empty containers
  4. - *
  5. Partially filled container x1
  6. - *
- * In order above, the itemstack at `slotIndex` is transformed into the output. - */ - private void insertFluid(EntityPlayer player, int slotIndex, boolean shift) { - final ItemStack targetStack; - if (slotIndex == -1) { - targetStack = player.inventory.getItemStack(); - } else { - targetStack = player.inventory.getStackInSlot(slotIndex); - } - final int containersRequestedToInsert = shift ? targetStack.stackSize : 1; - - // Step 1: Determine container characteristics and verify fluid to be extractable - final int fluidPerContainer; - final FluidStack fluidStackPerContainer; - final boolean partialInsertSupported; - if (targetStack.getItem() instanceof IFluidContainerItem fcItem) { - ItemStack test = targetStack.copy(); - test.stackSize = 1; - fluidStackPerContainer = fcItem.drain(test, Integer.MAX_VALUE, false); - if (fluidStackPerContainer == null || fluidStackPerContainer.amount == 0) { - return; - } - - fluidPerContainer = fluidStackPerContainer.amount; - partialInsertSupported = true; - } else if (FluidContainerRegistry.isContainer(targetStack)) { - ItemStack emptyTank = FluidContainerRegistry.drainFluidContainer(targetStack); - if (emptyTank == null) { - return; - } - - fluidStackPerContainer = FluidContainerRegistry.getFluidForFilledItem(targetStack); - fluidPerContainer = fluidStackPerContainer.amount; - partialInsertSupported = false; - } else { - return; - } - - // Step 2: determine network capacity - final IAEFluidStack totalFluid = AEFluidStack.create(fluidStackPerContainer); - totalFluid.setStackSize((long) fluidPerContainer * containersRequestedToInsert); - - final IAEFluidStack notInsertable = this.host.getFluidInventory() - .injectItems(totalFluid, Actionable.SIMULATE, this.getActionSource()); - - final long insertableFluid; - if (notInsertable == null || notInsertable.getStackSize() == 0) { - insertableFluid = totalFluid.getStackSize(); - } else { - long insertable = totalFluid.getStackSize() - notInsertable.getStackSize(); - if (partialInsertSupported) { - insertableFluid = insertable; - } else { - // avoid remainder - insertableFluid = insertable - (insertable % fluidPerContainer); - } - } - totalFluid.setStackSize(insertableFluid); - - // Step 3: perform insert - final long totalInserted; - final IAEFluidStack notInserted = this.host.getFluidInventory() - .injectItems(totalFluid, Actionable.MODULATE, this.getActionSource()); - if (notInserted != null && notInserted.getStackSize() > 0) { - // User has a setup that causes discrepancy between simulation and modulation. Likely double storage bus. - long total = totalFluid.getStackSize() - notInserted.getStackSize(); - if (partialInsertSupported) { - totalInserted = total; - } else { - // We cant have partially filled containers -> user will receive a fluid packet as last resort - long overflowAmount = fluidPerContainer - (total % fluidPerContainer); - IAEFluidStack overflow = AEFluidStack.create(fluidStackPerContainer); - overflow.setStackSize(overflowAmount); - dropItem(ItemFluidPacket.newStack(overflow)); - totalInserted = total + overflowAmount; - } - } else { - totalInserted = totalFluid.getStackSize(); - } - - // Step 4: calculate outputs - final int emptiedTanks; - final int partialDrain; - if (fluidPerContainer > 0) { - emptiedTanks = (int) (totalInserted / fluidPerContainer); - partialDrain = (int) (totalInserted % fluidPerContainer); - } else { - emptiedTanks = containersRequestedToInsert; - partialDrain = 0; - } - final int partialTanks = partialDrain > 0 && partialInsertSupported ? 1 : 0; - final int usedTanks = emptiedTanks + partialTanks; - final int untouchedTanks = targetStack.stackSize - usedTanks; - - final ItemStack emptiedTanksStack; - final ItemStack partialTanksStack; - - if (targetStack.getItem() instanceof IFluidContainerItem fcItem) { - if (emptiedTanks > 0) { - final ItemStack testDrainStack = targetStack.copy(); - testDrainStack.stackSize = 1; - fcItem.drain(testDrainStack, fluidPerContainer, true); - if (testDrainStack.stackSize == 0) { - emptiedTanksStack = null; - } else { - emptiedTanksStack = testDrainStack.copy(); - emptiedTanksStack.stackSize = emptiedTanks; - } - } else { - emptiedTanksStack = null; - } - if (partialTanks > 0) { - partialTanksStack = targetStack.copy(); - partialTanksStack.stackSize = 1; - fcItem.drain(partialTanksStack, partialDrain, true); - } else { - partialTanksStack = null; - } - } else { - if (emptiedTanks > 0) { - emptiedTanksStack = FluidContainerRegistry.drainFluidContainer(targetStack); - emptiedTanksStack.stackSize = emptiedTanks; - } else { - emptiedTanksStack = null; - } - // Not possible > see Step 2 and Step 3 - partialTanksStack = null; - } - - // Done. Put the output in the inventory or ground, and update stack size. - boolean shouldSendStack = true; - if (slotIndex == -1) { - // Item is in mouse hand - if (untouchedTanks > 0) { - targetStack.stackSize = untouchedTanks; - adjustStack(targetStack); - dropItem(emptiedTanksStack); - dropItem(partialTanksStack); - } else if (emptiedTanksStack != null) { - adjustStack(emptiedTanksStack); - player.inventory.setItemStack(emptiedTanksStack); - dropItem(partialTanksStack); - } else if (partialTanksStack != null) { - player.inventory.setItemStack(partialTanksStack); - } else { - player.inventory.setItemStack(null); - shouldSendStack = false; - } - } else { - // Shift clicked in - if (untouchedTanks > 0) { - targetStack.stackSize = untouchedTanks; - adjustStack(targetStack); - dropItem(emptiedTanksStack); - dropItem(partialTanksStack); - } else if (emptiedTanksStack != null) { - adjustStack(emptiedTanksStack); - player.inventory.setInventorySlotContents(slotIndex, emptiedTanksStack); - dropItem(partialTanksStack); - } else if (partialTanksStack != null) { - player.inventory.setInventorySlotContents(slotIndex, partialTanksStack); - } else { - player.inventory.setInventorySlotContents(slotIndex, null); - } - } - if (shouldSendStack) { - FluidCraft.proxy.netHandler.sendTo( - new SPacketFluidUpdate(new HashMap<>(), player.inventory.getItemStack()), - (EntityPlayerMP) player); - } else { - FluidCraft.proxy.netHandler.sendTo(new SPacketFluidUpdate(new HashMap<>()), (EntityPlayerMP) player); - } - } - - /** - * The extract operation. For input, we have an empty container stack. For outputs, we have the following: - *
    - *
  1. Leftover empty container stack
  2. - *
  3. Filled containers (full)
  4. - *
  5. Partially filled container x1
  6. - *
- * In order above, the itemstack at `slotIndex` is transformed into the output. - */ - private void extractFluid(IAEFluidStack clientRequestedFluid, EntityPlayer player, int slotIndex, boolean shift) { - if (slotIndex != -1) { - // shift-click from inventory cant fill fluids - return; - } - final ItemStack targetStack = player.inventory.getItemStack(); - final int containersRequestedToExtract = shift ? targetStack.stackSize : 1; - - final FluidStack clientRequestedFluidStack = clientRequestedFluid.getFluidStack(); - clientRequestedFluidStack.amount = Integer.MAX_VALUE; - - // Step 1: Determine container characteristics and verify fluid to be insertable - final int fluidPerContainer; - final boolean partialInsertSupported; - if (targetStack.getItem() instanceof IFluidContainerItem fcItem) { - ItemStack testStack = targetStack.copy(); - testStack.stackSize = 1; - fluidPerContainer = fcItem.fill(testStack, clientRequestedFluidStack, false); - if (fluidPerContainer == 0) { - return; - } - partialInsertSupported = true; - } else if (FluidContainerRegistry.isContainer(targetStack)) { - fluidPerContainer = FluidContainerRegistry.getContainerCapacity(clientRequestedFluidStack, targetStack); - partialInsertSupported = false; - } else { - return; - } - - // Step 2: determine fluid in network - final IAEFluidStack totalRequestedFluid = clientRequestedFluid.copy(); - totalRequestedFluid.setStackSize((long) fluidPerContainer * containersRequestedToExtract); - - final IAEFluidStack availableFluid = this.host.getFluidInventory() - .extractItems(totalRequestedFluid, Actionable.SIMULATE, this.getActionSource()); - if (availableFluid == null || availableFluid.getStackSize() == 0) { - return; - } - - if (availableFluid.getStackSize() != totalRequestedFluid.getStackSize() && !partialInsertSupported) { - availableFluid.decStackSize(availableFluid.getStackSize() % fluidPerContainer); - } - - // Step 3: perform extract - final IAEFluidStack extracted = this.host.getFluidInventory() - .extractItems(availableFluid, Actionable.MODULATE, this.getActionSource()); - final long totalExtracted = extracted != null ? extracted.getStackSize() : 0; - - // Step 4: calculate outputs - final int filledTanks = (int) (totalExtracted / fluidPerContainer); - final int partialFill = (int) (totalExtracted % fluidPerContainer); - final int partialTanks = partialFill > 0 && partialInsertSupported ? 1 : 0; - final int usedTanks = filledTanks + partialTanks; - final int untouchedTanks = targetStack.stackSize - usedTanks; - - final ItemStack filledTanksStack; - final ItemStack partialTanksStack; - - if (targetStack.getItem() instanceof IFluidContainerItem fcItem) { - if (filledTanks > 0) { - filledTanksStack = targetStack.copy(); - filledTanksStack.stackSize = 1; - FluidStack toInsert = extracted.getFluidStack().copy(); - toInsert.amount = fluidPerContainer; - fcItem.fill(filledTanksStack, toInsert, true); - filledTanksStack.stackSize = filledTanks; - } else { - filledTanksStack = null; - } - if (partialTanks > 0) { - partialTanksStack = targetStack.copy(); - partialTanksStack.stackSize = 1; - FluidStack toInsert = extracted.getFluidStack().copy(); - toInsert.amount = partialFill; - fcItem.fill(partialTanksStack, toInsert, true); - } else { - partialTanksStack = null; - } - } else { - if (filledTanks > 0) { - FluidStack toInsert = extracted.getFluidStack().copy(); - toInsert.amount = fluidPerContainer; - filledTanksStack = FluidContainerRegistry.fillFluidContainer(toInsert, targetStack); - filledTanksStack.stackSize = filledTanks; - } else { - filledTanksStack = null; - } - if (partialFill > 0) { - // User has a setup that causes discrepancy between simulation and modulation. Likely double storage - // bus. - // We cant have partially filled containers -> user will receive a fluid packet as last resort - IAEFluidStack overflow = extracted.copy(); - overflow.setStackSize(partialFill); - dropItem(ItemFluidPacket.newStack(overflow)); - } - partialTanksStack = null; - } - - // Done. Put the output in the inventory or ground, and update stack size. - // We can assume slotIndex == -1, since we don't actually allow extraction via shift click. - boolean shouldSendStack = true; - if (untouchedTanks > 0) { - ItemStack emptyStack = player.inventory.getItemStack(); - emptyStack.stackSize = untouchedTanks; - adjustStack(emptyStack); - dropItem(filledTanksStack); - dropItem(partialTanksStack); - } else if (filledTanksStack != null) { - adjustStack(filledTanksStack); - player.inventory.setItemStack(filledTanksStack); - dropItem(partialTanksStack); - } else if (partialTanksStack != null) { - player.inventory.setItemStack(partialTanksStack); - } else { - player.inventory.setItemStack(null); - shouldSendStack = false; - } - if (shouldSendStack) { - FluidCraft.proxy.netHandler.sendTo( - new SPacketFluidUpdate(new HashMap<>(), player.inventory.getItemStack()), - (EntityPlayerMP) player); - } else { - FluidCraft.proxy.netHandler.sendTo(new SPacketFluidUpdate(new HashMap<>()), (EntityPlayerMP) player); - } - } - - void adjustStack(ItemStack stack) { - if (stack != null && stack.stackSize > stack.getMaxStackSize()) { - dropItem(stack, stack.stackSize - stack.getMaxStackSize()); - stack.stackSize = stack.getMaxStackSize(); - } - } - - protected boolean isEssentiaMode() { - return false; - } - - @Override - protected boolean isWirelessTerminal() { - return false; - } -} diff --git a/src/main/java/com/glodblock/github/client/gui/container/ContainerFluidOptimizePatterns.java b/src/main/java/com/glodblock/github/client/gui/container/ContainerFluidOptimizePatterns.java deleted file mode 100644 index dbe7654d..00000000 --- a/src/main/java/com/glodblock/github/client/gui/container/ContainerFluidOptimizePatterns.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.glodblock.github.client.gui.container; - -import java.util.Objects; - -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.world.World; -import net.minecraftforge.common.util.ForgeDirection; - -import com.glodblock.github.common.item.ItemBaseWirelessTerminal; -import com.glodblock.github.common.parts.PartFluidPatternTerminal; -import com.glodblock.github.common.parts.PartFluidPatternTerminalEx; -import com.glodblock.github.common.parts.PartLevelTerminal; -import com.glodblock.github.inventory.InventoryHandler; -import com.glodblock.github.inventory.gui.GuiType; -import com.glodblock.github.inventory.item.IWirelessTerminal; -import com.glodblock.github.util.BlockPos; - -import appeng.api.networking.security.IActionHost; -import appeng.api.storage.ITerminalHost; -import appeng.container.implementations.ContainerOptimizePatterns; - -public class ContainerFluidOptimizePatterns extends ContainerOptimizePatterns { - - public ContainerFluidOptimizePatterns(InventoryPlayer ip, ITerminalHost te) { - super(ip, te); - } - - public World getWorld() { - return this.getPlayerInv().player.worldObj; - } - - @Override - public void switchToOriginalGUI() { - GuiType originalGui = null; - - final IActionHost ah = this.getActionHost(); - if (ah instanceof PartFluidPatternTerminal) { - originalGui = GuiType.FLUID_PATTERN_TERMINAL; - } - if (ah instanceof PartFluidPatternTerminalEx) { - originalGui = GuiType.FLUID_PATTERN_TERMINAL_EX; - } - if (ah instanceof PartLevelTerminal) { - originalGui = GuiType.LEVEL_TERMINAL; - } - if (ah instanceof IWirelessTerminal) { - ItemStack terminal = ((IWirelessTerminal) ah).getItemStack(); - if (terminal.getItem() instanceof ItemBaseWirelessTerminal) { - originalGui = ((ItemBaseWirelessTerminal) terminal.getItem()).guiGuiType(terminal); - } - } - if (ah instanceof IWirelessTerminal) { - InventoryHandler.openGui( - this.getInventoryPlayer().player, - getWorld(), - new BlockPos(((IWirelessTerminal) ah).getInventorySlot(), 0, 0), - ForgeDirection.UNKNOWN, - originalGui); - } else if (this.getOpenContext() != null) { - InventoryHandler.openGui( - this.getInventoryPlayer().player, - getWorld(), - new BlockPos(this.getOpenContext().getTile()), - Objects.requireNonNull(this.getOpenContext().getSide()), - originalGui); - } - } -} diff --git a/src/main/java/com/glodblock/github/client/gui/container/ContainerFluidPatternExWireless.java b/src/main/java/com/glodblock/github/client/gui/container/ContainerFluidPatternExWireless.java deleted file mode 100644 index 636ef6c6..00000000 --- a/src/main/java/com/glodblock/github/client/gui/container/ContainerFluidPatternExWireless.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.glodblock.github.client.gui.container; - -import net.minecraft.entity.player.InventoryPlayer; - -import com.glodblock.github.inventory.item.IWirelessTerminal; - -public class ContainerFluidPatternExWireless extends ContainerFluidPatternTerminalEx { - - public ContainerFluidPatternExWireless(InventoryPlayer ip, IWirelessTerminal monitorable) { - super(ip, monitorable); - } - - @Override - protected boolean isWirelessTerminal() { - return true; - } -} diff --git a/src/main/java/com/glodblock/github/client/gui/container/ContainerFluidPatternTerminal.java b/src/main/java/com/glodblock/github/client/gui/container/ContainerFluidPatternTerminal.java deleted file mode 100644 index 6988496e..00000000 --- a/src/main/java/com/glodblock/github/client/gui/container/ContainerFluidPatternTerminal.java +++ /dev/null @@ -1,161 +0,0 @@ -package com.glodblock.github.client.gui.container; - -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.InventoryCrafting; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.CraftingManager; - -import com.glodblock.github.client.gui.container.base.FCContainerEncodeTerminal; - -import appeng.api.storage.ITerminalHost; -import appeng.container.slot.OptionalSlotFake; -import appeng.container.slot.SlotFakeCraftingMatrix; -import appeng.container.slot.SlotPatternOutputs; -import appeng.container.slot.SlotPatternTerm; -import appeng.util.Platform; - -public class ContainerFluidPatternTerminal extends FCContainerEncodeTerminal { - - public ContainerFluidPatternTerminal(final InventoryPlayer ip, final ITerminalHost monitorable) { - super(ip, monitorable); - final IInventory output = this.patternTerminal.getInventoryByName("output"); - final IInventory patternInv = this.patternTerminal.getInventoryByName("pattern"); - this.craftingSlots = new SlotFakeCraftingMatrix[9]; - this.outputSlots = new OptionalSlotFake[3]; - for (int y = 0; y < 3; y++) { - for (int x = 0; x < 3; x++) { - this.addSlotToContainer( - this.craftingSlots[x + y * 3] = new SlotFakeCraftingMatrix( - this.crafting, - x + y * 3, - 18 + x * 18, - -76 + y * 18)); - } - } - - this.addSlotToContainer( - this.craftSlot = new SlotPatternTerm( - ip.player, - this.getActionSource(), - this.getPowerSource(), - monitorable, - this.crafting, - patternInv, - this.cOut, - 110, - -76 + 18, - this, - 2, - this)); - this.craftSlot.setIIcon(-1); - - for (int y = 0; y < 3; y++) { - this.addSlotToContainer( - this.outputSlots[y] = new SlotPatternOutputs(output, this, y, 110, -76 + y * 18, 0, 0, 1)); - this.outputSlots[y].setRenderDisabled(false); - } - this.updateOrderOfOutputSlots(); - } - - private void updateOrderOfOutputSlots() { - if (!this.isCraftingMode()) { - this.craftSlot.xDisplayPosition = -9000; - for (int y = 0; y < 3; y++) { - this.outputSlots[y].xDisplayPosition = this.outputSlots[y].getX(); - } - } else { - this.craftSlot.xDisplayPosition = this.craftSlot.getX(); - for (int y = 0; y < 3; y++) { - this.outputSlots[y].xDisplayPosition = -9000; - } - } - } - - protected boolean validPatternSlot(Slot slot) { - return slot instanceof SlotFakeCraftingMatrix || slot instanceof SlotPatternOutputs; - } - - @Override - public void putStackInSlot(final int par1, final ItemStack par2ItemStack) { - super.putStackInSlot(par1, par2ItemStack); - this.getAndUpdateOutput(); - } - - @Override - public void putStacksInSlots(final ItemStack[] par1ArrayOfItemStack) { - super.putStacksInSlots(par1ArrayOfItemStack); - this.getAndUpdateOutput(); - } - - private ItemStack getAndUpdateOutput() { - final InventoryCrafting ic = new InventoryCrafting(this, 3, 3); - - for (int x = 0; x < ic.getSizeInventory(); x++) { - ic.setInventorySlotContents(x, this.crafting.getStackInSlot(x)); - } - - final ItemStack is = CraftingManager.getInstance().findMatchingRecipe(ic, this.getPlayerInv().player.worldObj); - this.cOut.setInventorySlotContents(0, is); - return is; - } - - @Override - protected ItemStack[] getOutputs() { - if (this.isCraftingMode()) { - final ItemStack out = this.getAndUpdateOutput(); - if (out != null && out.stackSize > 0) { - return new ItemStack[] { out }; - } - } - return super.getOutputs(); - } - - @Override - public boolean isSlotEnabled(final int idx) { - if (idx == 1) { - return Platform.isServer() ? !this.patternTerminal.isCraftingRecipe() : !this.isCraftingMode(); - } else if (idx == 2) { - return Platform.isServer() ? this.patternTerminal.isCraftingRecipe() : this.isCraftingMode(); - } else { - return false; - } - } - - @Override - public void detectAndSendChanges() { - super.detectAndSendChanges(); - if (Platform.isServer()) { - if (this.isCraftingMode() != this.patternTerminal.isCraftingRecipe()) { - this.setCraftingMode(this.patternTerminal.isCraftingRecipe()); - this.updateOrderOfOutputSlots(); - } - } - } - - @Override - public void onUpdate(final String field, final Object oldValue, final Object newValue) { - super.onUpdate(field, oldValue, newValue); - if (field.equals("craftingMode")) { - this.getAndUpdateOutput(); - this.updateOrderOfOutputSlots(); - } - } - - public void clear() { - super.clear(); - this.getAndUpdateOutput(); - } - - private void setCraftingMode(final boolean craftingMode) { - this.craftingMode = craftingMode; - } - - @Override - public void doubleStacks(int val) { - if (!isCraftingMode()) { - super.doubleStacks(val); - } - } -} diff --git a/src/main/java/com/glodblock/github/client/gui/container/ContainerFluidPatternTerminalEx.java b/src/main/java/com/glodblock/github/client/gui/container/ContainerFluidPatternTerminalEx.java deleted file mode 100644 index a2a74702..00000000 --- a/src/main/java/com/glodblock/github/client/gui/container/ContainerFluidPatternTerminalEx.java +++ /dev/null @@ -1,153 +0,0 @@ -package com.glodblock.github.client.gui.container; - -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.Slot; - -import com.glodblock.github.client.gui.container.base.FCContainerEncodeTerminal; - -import appeng.api.storage.ITerminalHost; -import appeng.container.slot.IOptionalSlotHost; -import appeng.container.slot.OptionalSlotFake; -import appeng.helpers.InventoryAction; -import appeng.util.Platform; - -public class ContainerFluidPatternTerminalEx extends FCContainerEncodeTerminal { - - private static final int CRAFTING_GRID_PAGES = 2; - private static final int CRAFTING_GRID_WIDTH = 4; - private static final int CRAFTING_GRID_HEIGHT = 4; - private static final int CRAFTING_GRID_SLOTS = CRAFTING_GRID_WIDTH * CRAFTING_GRID_HEIGHT; - - public ContainerFluidPatternTerminalEx(final InventoryPlayer ip, final ITerminalHost monitorable) { - super(ip, monitorable); - this.craftingSlots = new ProcessingSlotFake[CRAFTING_GRID_SLOTS * CRAFTING_GRID_PAGES]; - this.outputSlots = new ProcessingSlotFake[CRAFTING_GRID_SLOTS * CRAFTING_GRID_PAGES]; - final IInventory output = this.getPatternTerminal().getInventoryByName("output"); - for (int page = 0; page < CRAFTING_GRID_PAGES; page++) { - for (int y = 0; y < CRAFTING_GRID_HEIGHT; y++) { - for (int x = 0; x < CRAFTING_GRID_WIDTH; x++) { - this.addSlotToContainer( - this.craftingSlots[x + y * CRAFTING_GRID_WIDTH - + page * CRAFTING_GRID_SLOTS] = new ProcessingSlotFake( - crafting, - this, - x + y * CRAFTING_GRID_WIDTH + page * CRAFTING_GRID_SLOTS, - 15, - -83, - x, - y, - x + 4)); - } - } - for (int x = 0; x < CRAFTING_GRID_WIDTH; x++) { - for (int y = 0; y < CRAFTING_GRID_HEIGHT; y++) { - this.addSlotToContainer( - this.outputSlots[x * CRAFTING_GRID_HEIGHT + y - + page * CRAFTING_GRID_SLOTS] = new ProcessingSlotFake( - output, - this, - x * CRAFTING_GRID_HEIGHT + y + page * CRAFTING_GRID_SLOTS, - 112, - -83, - -x, - y, - x)); - } - } - } - this.craftingMode = false; - } - - @Override - public boolean isSlotEnabled(final int idx) { - if (idx < 4) // outputs - { - return inverted || idx == 0; - } else { - return !inverted || idx == 4; - } - } - - protected boolean validPatternSlot(Slot slot) { - return slot instanceof ProcessingSlotFake; - } - - @Override - public void detectAndSendChanges() { - if (Platform.isServer()) { - if (inverted != patternTerminal.isInverted() || activePage != patternTerminal.getActivePage()) { - inverted = patternTerminal.isInverted(); - activePage = patternTerminal.getActivePage(); - offsetSlots(); - } - } - super.detectAndSendChanges(); - } - - private void offsetSlots() { - for (int page = 0; page < CRAFTING_GRID_PAGES; page++) { - for (int y = 0; y < CRAFTING_GRID_HEIGHT; y++) { - for (int x = 0; x < CRAFTING_GRID_WIDTH; x++) { - ((ProcessingSlotFake) this.craftingSlots[x + y * CRAFTING_GRID_WIDTH + page * CRAFTING_GRID_SLOTS]) - .setHidden(page != activePage || x > 0 && inverted); - ((ProcessingSlotFake) this.outputSlots[x * CRAFTING_GRID_HEIGHT + y + page * CRAFTING_GRID_SLOTS]) - .setHidden(page != activePage || x > 0 && !inverted); - } - } - } - } - - @Override - public void onUpdate(String field, Object oldValue, Object newValue) { - super.onUpdate(field, oldValue, newValue); - if (field.equals("inverted") || field.equals("activePage")) { - offsetSlots(); - } - } - - @Override - public void onSlotChange(final Slot s) { - if (s == this.patternSlotOUT && Platform.isServer()) { - inverted = patternTerminal.isInverted(); - } - super.onSlotChange(s); - } - - @Override - public void doAction(EntityPlayerMP player, InventoryAction action, int slotId, long id) { - this.craftingMode = false; - super.doAction(player, action, slotId, id); - } - - @Override - public void encode() { - this.craftingMode = false; - super.encode(); - } - - @Override - public boolean isCraftingMode() { - return false; - } - - private static class ProcessingSlotFake extends OptionalSlotFake { - - private static final int POSITION_SHIFT = 9000; - private boolean hidden = false; - - public ProcessingSlotFake(IInventory inv, IOptionalSlotHost containerBus, int idx, int x, int y, int offX, - int offY, int groupNum) { - super(inv, containerBus, idx, x, y, offX, offY, groupNum); - this.setRenderDisabled(false); - } - - public void setHidden(boolean hide) { - if (this.hidden != hide) { - this.hidden = hide; - this.xDisplayPosition += (hide ? -1 : 1) * POSITION_SHIFT; - } - } - } -} diff --git a/src/main/java/com/glodblock/github/client/gui/container/ContainerFluidPatternWireless.java b/src/main/java/com/glodblock/github/client/gui/container/ContainerFluidPatternWireless.java deleted file mode 100644 index 063e7bdc..00000000 --- a/src/main/java/com/glodblock/github/client/gui/container/ContainerFluidPatternWireless.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.glodblock.github.client.gui.container; - -import net.minecraft.entity.player.InventoryPlayer; - -import com.glodblock.github.inventory.item.IWirelessTerminal; - -public class ContainerFluidPatternWireless extends ContainerFluidPatternTerminal { - - public ContainerFluidPatternWireless(InventoryPlayer ip, IWirelessTerminal monitorable) { - super(ip, monitorable); - } - - @Override - protected boolean isWirelessTerminal() { - return true; - } -} diff --git a/src/main/java/com/glodblock/github/client/gui/container/ContainerFluidPortableCell.java b/src/main/java/com/glodblock/github/client/gui/container/ContainerFluidPortableCell.java deleted file mode 100644 index bb4dde1d..00000000 --- a/src/main/java/com/glodblock/github/client/gui/container/ContainerFluidPortableCell.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.glodblock.github.client.gui.container; - -import net.minecraft.entity.player.InventoryPlayer; - -import com.glodblock.github.inventory.item.IFluidPortableCell; - -public class ContainerFluidPortableCell extends ContainerFluidMonitor { - - public ContainerFluidPortableCell(final InventoryPlayer ip, final IFluidPortableCell monitorable) { - super(ip, monitorable, false); - this.bindPlayerInventory(ip, 0, 0); - } - - @Override - protected boolean isWirelessTerminal() { - return true; - } - -} diff --git a/src/main/java/com/glodblock/github/client/gui/container/ContainerFluidStorageBus.java b/src/main/java/com/glodblock/github/client/gui/container/ContainerFluidStorageBus.java deleted file mode 100644 index 5f7787d1..00000000 --- a/src/main/java/com/glodblock/github/client/gui/container/ContainerFluidStorageBus.java +++ /dev/null @@ -1,191 +0,0 @@ -package com.glodblock.github.client.gui.container; - -import java.util.Iterator; - -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.IInventory; - -import com.glodblock.github.client.gui.container.base.FCContainerFluidConfigurable; -import com.glodblock.github.common.item.ItemFluidPacket; -import com.glodblock.github.common.parts.PartFluidStorageBus; -import com.glodblock.github.inventory.slot.OptionalFluidSlotFakeTypeOnly; - -import appeng.api.AEApi; -import appeng.api.config.AccessRestriction; -import appeng.api.config.SecurityPermissions; -import appeng.api.config.Settings; -import appeng.api.config.StorageFilter; -import appeng.api.config.Upgrades; -import appeng.api.storage.IMEInventory; -import appeng.api.storage.data.IAEFluidStack; -import appeng.api.storage.data.IItemList; -import appeng.container.guisync.GuiSync; -import appeng.container.slot.SlotRestrictedInput; -import appeng.tile.inventory.AppEngInternalAEInventory; -import appeng.util.IterationCounter; -import appeng.util.Platform; -import appeng.util.iterators.NullIterator; - -public class ContainerFluidStorageBus extends FCContainerFluidConfigurable { - - public final PartFluidStorageBus bus; - - @GuiSync(3) - public AccessRestriction rwMode = AccessRestriction.READ_WRITE; - - @GuiSync(4) - public StorageFilter storageFilter = StorageFilter.EXTRACTABLE_ONLY; - - public ContainerFluidStorageBus(InventoryPlayer ip, PartFluidStorageBus te) { - super(ip, te); - this.bus = te; - } - - @Override - protected int getHeight() { - return 251; - } - - @Override - protected void setupConfig() { - final int xo = 8; - final int yo = 23 + 6; - final IInventory upgrades = getUpgradeable().getInventoryByName("upgrades"); - final IInventory config = getUpgradeable().getInventoryByName("config"); - for (int y = 0; y < 7; y++) { - for (int x = 0; x < 9; x++) { - this.addSlotToContainer( - new OptionalFluidSlotFakeTypeOnly(config, null, this, y * 9 + x, xo, yo, x, y, y)); - } - } - this.addSlotToContainer( - (new SlotRestrictedInput( - SlotRestrictedInput.PlacableItemType.UPGRADES, - upgrades, - 0, - 187, - 8, - this.getInventoryPlayer())).setNotDraggable()); - this.addSlotToContainer( - (new SlotRestrictedInput( - SlotRestrictedInput.PlacableItemType.UPGRADES, - upgrades, - 1, - 187, - 8 + 18, - this.getInventoryPlayer())).setNotDraggable()); - this.addSlotToContainer( - (new SlotRestrictedInput( - SlotRestrictedInput.PlacableItemType.UPGRADES, - upgrades, - 2, - 187, - 8 + 18 * 2, - this.getInventoryPlayer())).setNotDraggable()); - this.addSlotToContainer( - (new SlotRestrictedInput( - SlotRestrictedInput.PlacableItemType.UPGRADES, - upgrades, - 3, - 187, - 8 + 18 * 3, - this.getInventoryPlayer())).setNotDraggable()); - this.addSlotToContainer( - (new SlotRestrictedInput( - SlotRestrictedInput.PlacableItemType.UPGRADES, - upgrades, - 4, - 187, - 8 + 18 * 4, - this.getInventoryPlayer())).setNotDraggable()); - } - - @Override - protected boolean isValidForConfig(int slot, IAEFluidStack fs) { - if (this.supportCapacity()) { - final int upgrades = getUpgradeable().getInstalledUpgrades(Upgrades.CAPACITY); - final int y = slot / 9; - return y < upgrades + 2; - } - return true; - } - - @Override - protected boolean supportCapacity() { - return true; - } - - @Override - public int availableUpgrades() { - return 5; - } - - @Override - public void detectAndSendChanges() { - this.verifyPermissions(SecurityPermissions.BUILD, false); - - if (Platform.isServer()) { - this.setReadWriteMode((AccessRestriction) getUpgradeable().getConfigManager().getSetting(Settings.ACCESS)); - this.setStorageFilter( - (StorageFilter) getUpgradeable().getConfigManager().getSetting(Settings.STORAGE_FILTER)); - } - - this.standardDetectAndSendChanges(); - } - - @Override - public boolean isSlotEnabled(final int idx) { - if (getUpgradeable().getInstalledUpgrades(Upgrades.ORE_FILTER) > 0) return false; - final int upgrades = getUpgradeable().getInstalledUpgrades(Upgrades.CAPACITY); - return upgrades > (idx - 2); - } - - public void clear() { - AppEngInternalAEInventory h = this.bus.getConfig(); - for (int i = 0; i < h.getSizeInventory(); ++i) { - h.setInventorySlotContents(i, null); - } - this.detectAndSendChanges(); - } - - public void partition() { - AppEngInternalAEInventory h = this.bus.getConfig(); - final IMEInventory cellInv = this.bus.getInternalHandler(); - Iterator i = new NullIterator<>(); - if (cellInv != null) { - final IItemList list = cellInv - .getAvailableItems(AEApi.instance().storage().createFluidList(), IterationCounter.fetchNewId()); - i = list.iterator(); - } - - for (int x = 0; x < h.getSizeInventory(); x++) { - if (i.hasNext() && this.isSlotEnabled((x / 9) - 2)) { - h.setInventorySlotContents(x, ItemFluidPacket.newStack(i.next())); - } else { - h.setInventorySlotContents(x, null); - } - } - this.detectAndSendChanges(); - } - - public AccessRestriction getReadWriteMode() { - return this.rwMode; - } - - public StorageFilter getStorageFilter() { - return this.storageFilter; - } - - @Override - public AppEngInternalAEInventory getFakeFluidInv() { - return (AppEngInternalAEInventory) this.bus.getInventoryByName("config"); - } - - private void setReadWriteMode(final AccessRestriction rwMode) { - this.rwMode = rwMode; - } - - private void setStorageFilter(final StorageFilter storageFilter) { - this.storageFilter = storageFilter; - } -} diff --git a/src/main/java/com/glodblock/github/client/gui/container/ContainerInterfaceWireless.java b/src/main/java/com/glodblock/github/client/gui/container/ContainerInterfaceWireless.java deleted file mode 100644 index 1f05b5cd..00000000 --- a/src/main/java/com/glodblock/github/client/gui/container/ContainerInterfaceWireless.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.glodblock.github.client.gui.container; - -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.entity.player.InventoryPlayer; - -import com.glodblock.github.client.gui.container.base.FCBaseContainer; -import com.glodblock.github.inventory.item.IWirelessTerminal; - -import appeng.container.implementations.ContainerInterfaceTerminal; -import appeng.helpers.InventoryAction; -import appeng.util.Platform; - -public class ContainerInterfaceWireless extends FCBaseContainer { - - ContainerInterfaceTerminal delegateContainer; - - public ContainerInterfaceWireless(final InventoryPlayer ip, final IWirelessTerminal monitorable) { - super(ip, monitorable); - - delegateContainer = new ContainerInterfaceTerminal(ip, monitorable); - - this.bindPlayerInventory(ip, 14, 3); - } - - @Override - public void detectAndSendChanges() { - if (Platform.isClient()) { - return; - } - super.detectAndSendChanges(); - - delegateContainer.detectAndSendChanges(); - } - - @Override - public void doAction(final EntityPlayerMP player, final InventoryAction action, final int slot, final long id) { - delegateContainer.doAction(player, action, slot, id); - } - - @Override - protected boolean isWirelessTerminal() { - return true; - } -} diff --git a/src/main/java/com/glodblock/github/client/gui/container/ContainerItemMonitor.java b/src/main/java/com/glodblock/github/client/gui/container/ContainerItemMonitor.java deleted file mode 100644 index a3d69a5c..00000000 --- a/src/main/java/com/glodblock/github/client/gui/container/ContainerItemMonitor.java +++ /dev/null @@ -1,152 +0,0 @@ -package com.glodblock.github.client.gui.container; - -import java.util.ArrayList; -import java.util.List; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.ICrafting; -import net.minecraftforge.common.util.ForgeDirection; - -import com.glodblock.github.client.gui.container.base.FCContainerMonitor; -import com.glodblock.github.network.SPacketMEUpdateBuffer; - -import appeng.api.AEApi; -import appeng.api.implementations.tiles.IViewCellStorage; -import appeng.api.networking.IGrid; -import appeng.api.networking.IGridHost; -import appeng.api.networking.IGridNode; -import appeng.api.networking.energy.IEnergyGrid; -import appeng.api.networking.energy.IEnergySource; -import appeng.api.networking.security.BaseActionSource; -import appeng.api.networking.storage.IBaseMonitor; -import appeng.api.networking.storage.IStorageGrid; -import appeng.api.storage.ITerminalHost; -import appeng.api.storage.data.IAEItemStack; -import appeng.api.storage.data.IItemList; -import appeng.container.slot.SlotRestrictedInput; -import appeng.me.helpers.ChannelPowerSrc; -import appeng.util.Platform; - -public class ContainerItemMonitor extends FCContainerMonitor { - - private final IItemList items = AEApi.instance().storage().createItemList(); - - public ContainerItemMonitor(final InventoryPlayer ip, final ITerminalHost monitorable) { - this(ip, monitorable, true); - } - - protected ContainerItemMonitor(final InventoryPlayer ip, final ITerminalHost monitorable, - final boolean bindInventory) { - super(ip, monitorable, bindInventory); - if (Platform.isServer()) { - this.serverCM = monitorable.getConfigManager(); - if (monitorable instanceof IGridHost) { - final IGridNode node = ((IGridHost) monitorable).getGridNode(ForgeDirection.UNKNOWN); - if (node != null) { - this.networkNode = node; - final IGrid g = node.getGrid(); - if (g != null) { - this.setPowerSource(new ChannelPowerSrc(this.networkNode, g.getCache(IEnergyGrid.class))); - IStorageGrid storageGrid = g.getCache(IStorageGrid.class); - this.monitor = storageGrid.getItemInventory(); - if (this.monitor == null) { - this.setValidContainer(false); - } else { - this.monitor.addListener(this, null); - this.setCellInventory(this.monitor); - } - } - } else { - this.setValidContainer(false); - } - } else { - this.monitor = monitorable.getItemInventory(); - this.monitor.addListener(this, null); - this.setCellInventory(this.monitor); - this.setPowerSource((IEnergySource) monitorable); - } - } else { - this.monitor = null; - } - - this.canAccessViewCells = false; - if (monitorable instanceof IViewCellStorage) { - for (int y = 0; y < 5; y++) { - this.cellView[y] = new SlotRestrictedInput( - SlotRestrictedInput.PlacableItemType.VIEW_CELL, - ((IViewCellStorage) monitorable).getViewCellStorage(), - y, - 206, - y * 18 + 8, - this.getInventoryPlayer()); - this.cellView[y].setAllowEdit(this.canAccessViewCells); - this.addSlotToContainer(this.cellView[y]); - } - } - - if (bindInventory) { - this.bindPlayerInventory(ip, 0, 0); - } - } - - @Override - protected void processItemList() { - if (!this.items.isEmpty()) { - final IItemList monitorCache = this.monitor.getStorageList(); - List toSend = new ArrayList<>(); - for (final IAEItemStack is : this.items) { - final IAEItemStack send = monitorCache.findPrecise(is); - if (send != null) { - toSend.add(send); - } else { - is.setStackSize(0); - toSend.add(is); - } - } - for (final Object c : this.crafters) { - if (c instanceof EntityPlayer) { - SPacketMEUpdateBuffer.scheduleItemUpdate((EntityPlayerMP) c, toSend); - } - } - this.items.resetStatus(); - } - } - - @Override - protected void queueInventory(final ICrafting c) { - if (Platform.isServer() && c instanceof EntityPlayer && this.monitor != null) { - final IItemList monitorCache = this.monitor.getStorageList(); - List toSend = new ArrayList<>(); - for (final IAEItemStack is : monitorCache) { - toSend.add(is); - } - SPacketMEUpdateBuffer.scheduleItemUpdate((EntityPlayerMP) c, toSend); - } - } - - @Override - public void removeCraftingFromCrafters(final ICrafting c) { - super.removeCraftingFromCrafters(c); - if (this.crafters.isEmpty() && this.monitor != null) { - this.monitor.removeListener(this); - if (c instanceof EntityPlayerMP) { - SPacketMEUpdateBuffer.clear((EntityPlayerMP) c); - } - } - } - - @Override - public void postChange(final IBaseMonitor monitor, final Iterable change, - final BaseActionSource source) { - for (final IAEItemStack is : change) { - this.items.add(is); - } - } - - @Override - protected boolean isWirelessTerminal() { - return false; - } -} diff --git a/src/main/java/com/glodblock/github/client/gui/container/ContainerLevelMaintainer.java b/src/main/java/com/glodblock/github/client/gui/container/ContainerLevelMaintainer.java index 81ab4629..dbcf5b3e 100644 --- a/src/main/java/com/glodblock/github/client/gui/container/ContainerLevelMaintainer.java +++ b/src/main/java/com/glodblock/github/client/gui/container/ContainerLevelMaintainer.java @@ -7,19 +7,26 @@ import net.minecraft.item.ItemStack; import com.glodblock.github.FluidCraft; import com.glodblock.github.common.tile.TileLevelMaintainer; -import com.glodblock.github.inventory.AeItemStackHandler; import com.glodblock.github.inventory.slot.SlotFluidConvertingFake; import com.glodblock.github.network.SPacketLevelMaintainerGuiUpdate; import appeng.api.config.SecurityPermissions; -import appeng.container.AEBaseContainer; +import appeng.api.storage.StorageName; +import appeng.api.storage.data.IAEStack; +import appeng.container.ContainerSubGui; +import appeng.container.interfaces.IVirtualSlotHolder; +import appeng.core.sync.network.NetworkHandler; +import appeng.core.sync.packets.PacketVirtualSlot; import appeng.helpers.InventoryAction; +import appeng.tile.inventory.IAEStackInventory; import appeng.util.Platform; +import appeng.util.item.AEItemStack; +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; -public class ContainerLevelMaintainer extends AEBaseContainer { +public class ContainerLevelMaintainer extends ContainerSubGui implements IVirtualSlotHolder { private final TileLevelMaintainer tile; - private final SlotFluidConvertingFake[] requestSlots = new SlotFluidConvertingFake[TileLevelMaintainer.REQ_COUNT]; private static final int UPDATE_INTERVAL = 20; private boolean isFirstUpdate = true; @@ -28,12 +35,7 @@ public class ContainerLevelMaintainer extends AEBaseContainer { public ContainerLevelMaintainer(InventoryPlayer ipl, TileLevelMaintainer tile) { super(ipl, tile); this.tile = tile; - AeItemStackHandler request = new AeItemStackHandler(tile.getRequestSlots()); - for (int y = 0; y < TileLevelMaintainer.REQ_COUNT; y++) { - SlotFluidConvertingFake slot = new SlotFluidConvertingFake(request, y, 27, 20 + y * 19); - addSlotToContainer(slot); - requestSlots[y] = slot; - } + bindPlayerInventory(ipl, 0, 130); } @@ -41,10 +43,6 @@ public class ContainerLevelMaintainer extends AEBaseContainer { return tile; } - public SlotFluidConvertingFake[] getRequestSlots() { - return this.requestSlots; - } - @Override public void doAction(EntityPlayerMP player, InventoryAction action, int slotId, long id) { if (getSlot(slotId) instanceof SlotFluidConvertingFake slot) { @@ -70,12 +68,15 @@ public class ContainerLevelMaintainer extends AEBaseContainer { return null; } - for (int i = 0; i < this.getRequestSlots().length; i++) { - SlotFluidConvertingFake slot = this.getRequestSlots()[i]; - if (!slot.getHasStack()) { - ItemStack itemStack = this.inventorySlots.get(idx).getStack(); - tile.updateStack(i, itemStack.copy()); - break; + ItemStack clickedStack = this.inventorySlots.get(idx).getStack(); + if (clickedStack != null) { + IAEStackInventory inventory = this.getTile().getAEStackInventory(); + for (int i = 0; i < inventory.getSizeInventory(); i++) { + IAEStack stack = inventory.getAEStackInSlot(i); + if (stack == null) { + tile.updateStack(i, AEItemStack.create(clickedStack)); + break; + } } } @@ -98,10 +99,36 @@ public class ContainerLevelMaintainer extends AEBaseContainer { } public void updateGui() { + if (this.isFirstUpdate) { + Int2ObjectMap> list = new Int2ObjectOpenHashMap<>(); + for (int i = 0; i < this.tile.requests.length; i++) { + TileLevelMaintainer.RequestInfo info = this.tile.requests[i]; + list.put(i, info != null ? info.getAEStack() : null); + } + NetworkHandler.instance.sendTo( + new PacketVirtualSlot(StorageName.NONE, list), + (EntityPlayerMP) this.getInventoryPlayer().player); + } FluidCraft.proxy.netHandler.sendTo( new SPacketLevelMaintainerGuiUpdate(this.tile.requests, !this.isFirstUpdate), (EntityPlayerMP) this.getInventoryPlayer().player); this.isFirstUpdate = false; this.updateCount = 0; } + + @Override + public void receiveSlotStacks(StorageName invName, Int2ObjectMap> slotStacks) { + for (var entry : slotStacks.int2ObjectEntrySet()) { + this.tile.updateStack(entry.getIntKey(), entry.getValue()); + } + if (!this.tile.getWorldObj().isRemote) { + for (var player : this.crafters) { + NetworkHandler.instance + .sendTo(new PacketVirtualSlot(StorageName.NONE, slotStacks), (EntityPlayerMP) player); + FluidCraft.proxy.netHandler.sendTo( + new SPacketLevelMaintainerGuiUpdate(this.tile.requests, false), + (EntityPlayerMP) player); + } + } + } } diff --git a/src/main/java/com/glodblock/github/client/gui/container/ContainerLevelTerminal.java b/src/main/java/com/glodblock/github/client/gui/container/ContainerLevelTerminal.java index 49e7183f..bd83b674 100644 --- a/src/main/java/com/glodblock/github/client/gui/container/ContainerLevelTerminal.java +++ b/src/main/java/com/glodblock/github/client/gui/container/ContainerLevelTerminal.java @@ -9,26 +9,30 @@ import java.util.Set; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.item.ItemStack; import net.minecraftforge.common.util.ForgeDirection; import org.jetbrains.annotations.Nullable; import com.glodblock.github.FluidCraft; -import com.glodblock.github.api.registries.ILevelViewable; -import com.glodblock.github.api.registries.LevelItemInfo; import com.glodblock.github.client.gui.container.base.FCBaseContainer; import com.glodblock.github.common.parts.PartLevelTerminal; import com.glodblock.github.coremod.registries.LevelTerminalRegistry; +import com.glodblock.github.inventory.gui.GuiType; import com.glodblock.github.inventory.item.IWirelessTerminal; +import com.glodblock.github.loader.ItemAndBlockHolder; import com.glodblock.github.network.SPacketLevelTerminalUpdate; +import com.glodblock.github.util.FluidPrimaryGui; +import appeng.api.features.ILevelViewable; +import appeng.api.features.LevelItemInfo; import appeng.api.networking.IGrid; import appeng.api.networking.IGridHost; import appeng.api.networking.IGridNode; import appeng.api.networking.security.IActionHost; import appeng.api.storage.ITerminalHost; import appeng.api.util.DimensionalCoord; +import appeng.container.ContainerOpenContext; +import appeng.container.PrimaryGui; import appeng.util.Platform; public class ContainerLevelTerminal extends FCBaseContainer { @@ -150,7 +154,7 @@ public class ContainerLevelTerminal extends FCBaseContainer { knownTracker.infoList[i] = null; if (update == null) update = new SPacketLevelTerminalUpdate(); update.addOverwriteSlotEntry(knownTracker.id, i, null); - } else if (!ItemStack.areItemStacksEqual(prev[i].stack, curr[i].stack) + } else if (!Platform.isStacksIdentical(prev[i].stack, curr[i].stack) || prev[i].quantity == curr[i].quantity || prev[i].batchSize == curr[i].batchSize || prev[i].state == curr[i].state) { @@ -238,4 +242,15 @@ public class ContainerLevelTerminal extends FCBaseContainer { this.infoList = machine.getLevelItemInfoList(); } } + + @Override + public PrimaryGui getPrimaryGui() { + + ContainerOpenContext context = getOpenContext(); + return new FluidPrimaryGui( + GuiType.LEVEL_TERMINAL, + ItemAndBlockHolder.LEVEL_TERMINAL.stack(), + context.getTile(), + context.getSide()); + } } diff --git a/src/main/java/com/glodblock/github/client/gui/container/ContainerLevelWireless.java b/src/main/java/com/glodblock/github/client/gui/container/ContainerLevelWireless.java index 286b9921..0e16910a 100644 --- a/src/main/java/com/glodblock/github/client/gui/container/ContainerLevelWireless.java +++ b/src/main/java/com/glodblock/github/client/gui/container/ContainerLevelWireless.java @@ -2,7 +2,13 @@ package com.glodblock.github.client.gui.container; import net.minecraft.entity.player.InventoryPlayer; +import com.glodblock.github.inventory.gui.GuiType; import com.glodblock.github.inventory.item.IWirelessTerminal; +import com.glodblock.github.loader.ItemAndBlockHolder; +import com.glodblock.github.util.FluidPrimaryGui; + +import appeng.container.ContainerOpenContext; +import appeng.container.PrimaryGui; public class ContainerLevelWireless extends ContainerLevelTerminal { @@ -14,4 +20,15 @@ public class ContainerLevelWireless extends ContainerLevelTerminal { protected boolean isWirelessTerminal() { return true; } + + @Override + public PrimaryGui getPrimaryGui() { + + ContainerOpenContext context = getOpenContext(); + return new FluidPrimaryGui( + GuiType.WIRELESS_LEVEL_TERMINAL, + ItemAndBlockHolder.WIRELESS_LEVEL_TERM.stack(), + context.getTile(), + context.getSide()); + } } diff --git a/src/main/java/com/glodblock/github/client/gui/container/ContainerMagnetFilter.java b/src/main/java/com/glodblock/github/client/gui/container/ContainerMagnetFilter.java index 0f98e886..51090875 100644 --- a/src/main/java/com/glodblock/github/client/gui/container/ContainerMagnetFilter.java +++ b/src/main/java/com/glodblock/github/client/gui/container/ContainerMagnetFilter.java @@ -5,12 +5,12 @@ import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; -import com.glodblock.github.client.gui.container.base.FCBaseContainer; -import com.glodblock.github.inventory.item.IItemTerminal; import com.glodblock.github.inventory.item.IWirelessMagnetFilter; import com.glodblock.github.inventory.item.WirelessMagnet; +import com.glodblock.github.inventory.item.WirelessMagnetCardFilterInventory; import appeng.api.storage.ITerminalHost; +import appeng.container.ContainerSubGui; import appeng.container.guisync.GuiSync; import appeng.container.slot.AppEngSlot; import appeng.container.slot.IOptionalSlotHost; @@ -19,7 +19,7 @@ import appeng.container.slot.SlotFake; import appeng.container.slot.SlotPatternOutputs; import appeng.util.Platform; -public class ContainerMagnetFilter extends FCBaseContainer implements IOptionalSlotHost { +public class ContainerMagnetFilter extends ContainerSubGui implements IOptionalSlotHost { @GuiSync(101) public WirelessMagnet.ListMode listMode; @@ -41,12 +41,14 @@ public class ContainerMagnetFilter extends FCBaseContainer implements IOptionalS protected OptionalSlotFake[] filterSlots; protected final IInventory filter; + private final IWirelessMagnetFilter object; public ContainerMagnetFilter(InventoryPlayer ip, ITerminalHost monitorable) { super(ip, monitorable); - this.filter = ((IItemTerminal) monitorable).getInventoryByName("config"); + this.object = (WirelessMagnetCardFilterInventory) monitorable; + this.filter = object.getInventoryByName("config"); this.filterSlots = new OptionalSlotFake[27]; - oreDictFilter = ((IWirelessMagnetFilter) getHost()).getOreDictFilter(); + oreDictFilter = object.getOreDictFilter(); for (int y = 0; y < 3; y++) { for (int x = 0; x < 9; x++) { this.addSlotToContainer( @@ -62,14 +64,10 @@ public class ContainerMagnetFilter extends FCBaseContainer implements IOptionalS this.filterSlots[x + y * 9].setRenderDisabled(false); } } + this.lockPlayerInventorySlot(this.object.getInventorySlot()); bindPlayerInventory(ip, 0, 126); } - @Override - protected boolean isWirelessTerminal() { - return true; - } - @Override public ItemStack transferStackInSlot(EntityPlayer p, int idx) { AppEngSlot clickSlot = (AppEngSlot) this.inventorySlots.get(idx); @@ -87,14 +85,13 @@ public class ContainerMagnetFilter extends FCBaseContainer implements IOptionalS @Override public void detectAndSendChanges() { - if (Platform.isServer() && this.getPortableCell() instanceof IWirelessMagnetFilter) { - IWirelessMagnetFilter host = (IWirelessMagnetFilter) this.getHost(); - this.listMode = host.getListMode(); - this.meta = host.getMetaMode(); - this.nbt = host.getNBTMode(); - this.ore = host.getOreMode(); - this.oreDict = host.getOreDictMode(); - this.oreDictFilter = host.getOreDictFilter(); + if (Platform.isServer()) { + this.listMode = this.object.getListMode(); + this.meta = this.object.getMetaMode(); + this.nbt = this.object.getNBTMode(); + this.ore = this.object.getOreMode(); + this.oreDict = this.object.getOreDictMode(); + this.oreDictFilter = this.object.getOreDictFilter(); } super.detectAndSendChanges(); } diff --git a/src/main/java/com/glodblock/github/client/gui/container/ContainerPatternMulti.java b/src/main/java/com/glodblock/github/client/gui/container/ContainerPatternMulti.java deleted file mode 100644 index 6199ec44..00000000 --- a/src/main/java/com/glodblock/github/client/gui/container/ContainerPatternMulti.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.glodblock.github.client.gui.container; - -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.world.World; - -import appeng.api.config.SecurityPermissions; -import appeng.api.networking.IGrid; -import appeng.api.networking.security.BaseActionSource; -import appeng.api.networking.security.IActionHost; -import appeng.api.networking.security.PlayerSource; -import appeng.api.storage.ITerminalHost; -import appeng.container.AEBaseContainer; - -public class ContainerPatternMulti extends AEBaseContainer { - - public ContainerPatternMulti(final InventoryPlayer ip, final ITerminalHost te) { - super(ip, te); - } - - @Override - public void detectAndSendChanges() { - super.detectAndSendChanges(); - this.verifyPermissions(SecurityPermissions.CRAFT, false); - } - - public IGrid getGrid() { - final IActionHost h = ((IActionHost) this.getTarget()); - return h.getActionableNode().getGrid(); - } - - public World getWorld() { - return this.getPlayerInv().player.worldObj; - } - - public BaseActionSource getActionSrc() { - return new PlayerSource(this.getPlayerInv().player, (IActionHost) this.getTarget()); - } -} diff --git a/src/main/java/com/glodblock/github/client/gui/container/ContainerPatternValueAmount.java b/src/main/java/com/glodblock/github/client/gui/container/ContainerPatternValueAmount.java deleted file mode 100644 index 27b38762..00000000 --- a/src/main/java/com/glodblock/github/client/gui/container/ContainerPatternValueAmount.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.glodblock.github.client.gui.container; - -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.Slot; - -import appeng.api.config.SecurityPermissions; -import appeng.container.AEBaseContainer; -import appeng.container.guisync.GuiSync; -import appeng.container.slot.SlotInaccessible; -import appeng.tile.inventory.AppEngInternalInventory; - -public class ContainerPatternValueAmount extends AEBaseContainer { - - private final Slot patternValue; - - @GuiSync(11) - public int valueIndex; - - public ContainerPatternValueAmount(final InventoryPlayer ip, final Object te) { - super(ip, te); - this.patternValue = new SlotInaccessible(new AppEngInternalInventory(null, 1), 0, 34, 53); - this.addSlotToContainer(patternValue); - } - - @Override - public void detectAndSendChanges() { - super.detectAndSendChanges(); - this.verifyPermissions(SecurityPermissions.CRAFT, false); - } - - public Slot getPatternValue() { - return patternValue; - } - - public int getValueIndex() { - return valueIndex; - } - - public void setValueIndex(int valueIndex) { - this.valueIndex = valueIndex; - } -} diff --git a/src/main/java/com/glodblock/github/client/gui/container/ContainerRenamer.java b/src/main/java/com/glodblock/github/client/gui/container/ContainerRenamer.java deleted file mode 100644 index 787abc73..00000000 --- a/src/main/java/com/glodblock/github/client/gui/container/ContainerRenamer.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.glodblock.github.client.gui.container; - -import net.minecraft.entity.player.InventoryPlayer; - -import appeng.api.storage.ITerminalHost; -import appeng.container.AEBaseContainer; - -public class ContainerRenamer extends AEBaseContainer { - - public ContainerRenamer(InventoryPlayer ip, ITerminalHost monitorable) { - super(ip, monitorable); - } -} diff --git a/src/main/java/com/glodblock/github/client/gui/container/ContainerSuperStockReplenisher.java b/src/main/java/com/glodblock/github/client/gui/container/ContainerSuperStockReplenisher.java index b8059ce0..20eea6e9 100644 --- a/src/main/java/com/glodblock/github/client/gui/container/ContainerSuperStockReplenisher.java +++ b/src/main/java/com/glodblock/github/client/gui/container/ContainerSuperStockReplenisher.java @@ -3,6 +3,8 @@ package com.glodblock.github.client.gui.container; import java.util.HashMap; import java.util.Map; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiScreen; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.InventoryPlayer; @@ -13,19 +15,36 @@ import net.minecraft.item.ItemStack; import com.glodblock.github.FluidCraft; import com.glodblock.github.common.item.FCBaseItemCell; +import com.glodblock.github.common.item.ItemFluidPacket; import com.glodblock.github.common.tile.TileSuperStockReplenisher; +import com.glodblock.github.inventory.gui.GuiType; import com.glodblock.github.inventory.slot.OptionalFluidSlotFake; +import com.glodblock.github.loader.ItemAndBlockHolder; import com.glodblock.github.network.SPacketSuperStockReplenisherUpdate; +import com.glodblock.github.util.FluidPrimaryGui; +import appeng.api.storage.StorageName; +import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IAEStack; +import appeng.client.gui.implementations.GuiPatternItemRenamer; +import appeng.client.gui.implementations.GuiPatternValueAmount; import appeng.container.AEBaseContainer; +import appeng.container.ContainerOpenContext; +import appeng.container.PrimaryGui; +import appeng.container.interfaces.IVirtualSlotHolder; +import appeng.container.interfaces.IVirtualSlotSource; import appeng.container.slot.IOptionalSlotHost; import appeng.container.slot.SlotPatternOutputs; import appeng.container.slot.SlotRestrictedInput; +import appeng.core.sync.network.NetworkHandler; +import appeng.core.sync.packets.PacketVirtualSlot; import appeng.items.storage.ItemBasicStorageCell; +import appeng.util.Platform; import appeng.util.item.AEItemStack; +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; -public class ContainerSuperStockReplenisher extends AEBaseContainer implements IOptionalSlotHost { +public class ContainerSuperStockReplenisher extends AEBaseContainer + implements IOptionalSlotHost, IVirtualSlotHolder, IVirtualSlotSource { private final TileSuperStockReplenisher tile; private final IInventory configFluids; @@ -151,4 +170,52 @@ public class ContainerSuperStockReplenisher extends AEBaseContainer implements I public TileSuperStockReplenisher getTile() { return tile; } + + @Override + public PrimaryGui getPrimaryGui() { + + ContainerOpenContext context = getOpenContext(); + return new FluidPrimaryGui( + GuiType.GUI_SUPER_STOCK_REPLENISHER, + ItemAndBlockHolder.SUPER_STOCK_RERPLENISHER.stack(), + context.getTile(), + context.getSide()); + } + + @Override + public void receiveSlotStacks(StorageName invName, Int2ObjectMap> slotStacks) { + var entry = slotStacks.int2ObjectEntrySet().iterator().next(); + IAEStack aes = entry.getValue(); + int slotIndex = entry.getIntKey(); + + if (Platform.isServer()) { + for (ICrafting crafter : this.crafters) { + final EntityPlayerMP emp = (EntityPlayerMP) crafter; + NetworkHandler.instance.sendTo(new PacketVirtualSlot(invName, slotIndex, aes), emp); + } + } else { + final GuiScreen gs = Minecraft.getMinecraft().currentScreen; + if (gs instanceof GuiPatternValueAmount gpva) { + gpva.update(); + } else if (gs instanceof GuiPatternItemRenamer gpir) { + gpir.update(); + } + } + } + + @Override + public void updateVirtualSlot(StorageName invName, int slotId, IAEStack aes) { + if (aes instanceof IAEItemStack ais) { + ItemStack newIs; + if (ais.getItem() instanceof ItemFluidPacket) { + newIs = ais.getItemStack(); + newIs.stackSize = 1; + ItemFluidPacket.setFluidAmount(newIs, aes.getStackSize()); + } else { + newIs = ais.getItemStack(); + } + this.inventorySlots.get(slotId).putStack(newIs); + } + } + } diff --git a/src/main/java/com/glodblock/github/client/gui/container/base/FCBaseContainer.java b/src/main/java/com/glodblock/github/client/gui/container/base/FCBaseContainer.java index a4ee98c4..2a230413 100644 --- a/src/main/java/com/glodblock/github/client/gui/container/base/FCBaseContainer.java +++ b/src/main/java/com/glodblock/github/client/gui/container/base/FCBaseContainer.java @@ -3,14 +3,12 @@ package com.glodblock.github.client.gui.container.base; import net.minecraft.entity.player.InventoryPlayer; import com.glodblock.github.inventory.item.IFluidPortableCell; -import com.glodblock.github.inventory.item.IWirelessExtendCard; import com.glodblock.github.inventory.item.WirelessMagnet; import com.glodblock.github.util.Util; import appeng.api.storage.ITerminalHost; import appeng.container.AEBaseContainer; import appeng.container.guisync.GuiSync; -import appeng.util.Platform; public abstract class FCBaseContainer extends AEBaseContainer { @@ -62,13 +60,6 @@ public abstract class FCBaseContainer extends AEBaseContainer { this.getPowerMultiplier(), ((IFluidPortableCell) this.host)); } - - if (Platform.isServer()) { - if (this.host instanceof IWirelessExtendCard wec) { - this.mode = wec.getMagnetCardMode(); - this.restock = wec.isRestock(); - } - } super.detectAndSendChanges(); } diff --git a/src/main/java/com/glodblock/github/client/gui/container/base/FCContainerEncodeTerminal.java b/src/main/java/com/glodblock/github/client/gui/container/base/FCContainerEncodeTerminal.java deleted file mode 100644 index 027b7b0d..00000000 --- a/src/main/java/com/glodblock/github/client/gui/container/base/FCContainerEncodeTerminal.java +++ /dev/null @@ -1,669 +0,0 @@ -package com.glodblock.github.client.gui.container.base; - -import static appeng.util.Platform.writeStackNBT; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; -import java.util.Objects; -import java.util.stream.Collectors; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.ICrafting; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTBase; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraftforge.fluids.FluidStack; - -import com.glodblock.github.client.gui.container.ContainerItemMonitor; -import com.glodblock.github.common.item.ItemFluidDrop; -import com.glodblock.github.common.item.ItemFluidEncodedPattern; -import com.glodblock.github.common.item.ItemFluidPacket; -import com.glodblock.github.inventory.IPatternConsumer; -import com.glodblock.github.inventory.item.IItemPatternTerminal; -import com.glodblock.github.util.Util; - -import appeng.api.AEApi; -import appeng.api.config.Actionable; -import appeng.api.definitions.IDefinitions; -import appeng.api.implementations.ICraftingPatternItem; -import appeng.api.storage.ITerminalHost; -import appeng.api.storage.data.IAEItemStack; -import appeng.container.guisync.GuiSync; -import appeng.container.slot.IOptionalSlotHost; -import appeng.container.slot.OptionalSlotFake; -import appeng.container.slot.SlotFake; -import appeng.container.slot.SlotFakeCraftingMatrix; -import appeng.container.slot.SlotPatternTerm; -import appeng.container.slot.SlotRestrictedInput; -import appeng.helpers.IContainerCraftingPacket; -import appeng.helpers.InventoryAction; -import appeng.tile.inventory.AppEngInternalInventory; -import appeng.tile.inventory.IAEAppEngInventory; -import appeng.tile.inventory.InvOperation; -import appeng.util.Platform; -import appeng.util.item.AEFluidStack; -import appeng.util.item.AEItemStack; - -public abstract class FCContainerEncodeTerminal extends ContainerItemMonitor - implements IAEAppEngInventory, IOptionalSlotHost, IContainerCraftingPacket, IPatternConsumer { - - public static final int MULTIPLE_OF_BUTTON_CLICK = 2; - public static final int MULTIPLE_OF_BUTTON_CLICK_ON_SHIFT = 8; - protected final IItemPatternTerminal patternTerminal; - protected final AppEngInternalInventory cOut = new AppEngInternalInventory(null, 1); - protected final IInventory crafting; - protected final SlotRestrictedInput patternSlotIN; - protected final SlotRestrictedInput patternSlotOUT; - protected SlotFake[] craftingSlots; - protected OptionalSlotFake[] outputSlots; - protected SlotPatternTerm craftSlot; - - @GuiSync(97) - public boolean craftingMode = true; - - @GuiSync(96) - public boolean substitute = false; - - @GuiSync(95) - public boolean combine = false; - - @GuiSync(94) - public boolean beSubstitute = false; - - @GuiSync(93) - public boolean inverted; - - @GuiSync(92) - public int activePage = 0; - - @GuiSync(91) - public boolean prioritize = false; - - @GuiSync(90) - public boolean autoFillPattern = false; - - public FCContainerEncodeTerminal(final InventoryPlayer ip, final ITerminalHost monitorable) { - super(ip, monitorable); - this.patternTerminal = (IItemPatternTerminal) monitorable; - this.inverted = patternTerminal.isInverted(); - final IInventory patternInv = this.patternTerminal.getInventoryByName("pattern"); - this.crafting = this.patternTerminal.getInventoryByName("crafting"); - this.addSlotToContainer( - this.patternSlotIN = new SlotRestrictedInput( - SlotRestrictedInput.PlacableItemType.BLANK_PATTERN, - patternInv, - 0, - 147, - -72 - 9, - this.getInventoryPlayer())); - this.addSlotToContainer( - this.patternSlotOUT = new SlotRestrictedInput( - SlotRestrictedInput.PlacableItemType.ENCODED_PATTERN, - patternInv, - 1, - 147, - -72 + 34, - this.getInventoryPlayer())); - this.patternSlotOUT.setStackLimit(1); - } - - @Override - public void doAction(EntityPlayerMP player, InventoryAction action, int slotId, long id) { - if (this.isCraftingMode()) { - super.doAction(player, action, slotId, id); - return; - } - if (slotId < 0 || slotId >= this.inventorySlots.size()) { - super.doAction(player, action, slotId, id); - return; - } - if (action == InventoryAction.MOVE_REGION) { - super.doAction(player, InventoryAction.MOVE_REGION, slotId, id); - return; - } - if (action == InventoryAction.PICKUP_SINGLE) { - super.doAction(player, InventoryAction.PICKUP_OR_SET_DOWN, slotId, id); - return; - } - Slot slot = getSlot(slotId); - ItemStack stack = player.inventory.getItemStack(); - FluidStack fluid = Util.getFluidFromItem(stack); - - if (fluid == null || fluid.amount <= 0) { - super.doAction(player, action, slotId, id); - return; - } - - if (validPatternSlot(slot)) { - - switch (action) { - case PICKUP_OR_SET_DOWN -> { - slot.putStack(ItemFluidPacket.newStack(fluid)); - return; - } - case SPLIT_OR_PLACE_SINGLE -> { - fluid = Util.getFluidFromItem(Util.copyStackWithSize(stack, 1)); - FluidStack origin = ItemFluidPacket.getFluidStack(slot.getStack()); - if (fluid != null && fluid.equals(origin)) { - fluid.amount += origin.amount; - if (fluid.amount <= 0) fluid = null; - } - slot.putStack(ItemFluidPacket.newStack(fluid)); - return; - } - default -> {} - } - - } - super.doAction(player, action, slotId, id); - } - - protected abstract boolean validPatternSlot(Slot slot); - - @Override - public ItemStack transferStackInSlot(EntityPlayer p, int idx) { - Slot clickSlot = (Slot) this.inventorySlots.get(idx); - ItemStack is = clickSlot.getStack(); - if (is != null && !patternSlotOUT.getHasStack() - && is.stackSize == 1 - && is.getItem() instanceof ICraftingPatternItem) { - ItemStack output = is.copy(); - patternSlotOUT.putStack(output); - p.inventory.setInventorySlotContents(clickSlot.getSlotIndex(), null); - this.detectAndSendChanges(); - return null; - } else { - return super.transferStackInSlot(p, idx); - } - } - - public IItemPatternTerminal getPatternTerminal() { - return this.patternTerminal; - } - - protected static boolean canDoubleStacks(SlotFake[] slots) { - List enabledSlots = Arrays.stream(slots).filter(SlotFake::isEnabled).collect(Collectors.toList()); - long emptySlots = enabledSlots.stream().filter(s -> s.getStack() == null).count(); - long fullSlots = enabledSlots.stream().filter(s -> s.getStack() != null && s.getStack().stackSize * 2 > 127) - .count(); - return fullSlots <= emptySlots; - } - - protected static void doubleStacksInternal(SlotFake[] slots) { - List overFlowStacks = new ArrayList<>(); - List enabledSlots = Arrays.stream(slots).filter(SlotFake::isEnabled).collect(Collectors.toList()); - for (final Slot s : enabledSlots) { - ItemStack st = s.getStack(); - if (st == null) continue; - if (Util.isFluidPacket(st)) { - FluidStack fluidStack = ItemFluidPacket.getFluidStack(st); - if (fluidStack != null) { - fluidStack = ItemFluidPacket.getFluidStack(st).copy(); - if (fluidStack.amount < Integer.MAX_VALUE / 2) fluidStack.amount *= 2; - } - s.putStack(ItemFluidPacket.newStack(fluidStack)); - } else if (st.stackSize * 2 > 127) { - overFlowStacks.add(st.copy()); - } else { - st.stackSize *= 2; - s.putStack(st); - } - } - Iterator ow = overFlowStacks.iterator(); - for (final Slot s : enabledSlots) { - if (!ow.hasNext()) break; - if (s.getStack() != null) continue; - s.putStack(ow.next()); - } - assert !ow.hasNext(); - } - - protected static boolean containsItem(SlotFake[] slots) { - List enabledSlots = Arrays.stream(slots).filter(SlotFake::isEnabled).collect(Collectors.toList()); - long item = enabledSlots.stream().filter(s -> s.getStack() != null && !Util.isFluidPacket(s.getStack())) - .count(); - return item > 0; - } - - protected static boolean containsFluid(SlotFake[] slots) { - List enabledSlots = Arrays.stream(slots).filter(SlotFake::isEnabled).collect(Collectors.toList()); - long fluid = enabledSlots.stream().filter(s -> Util.isFluidPacket(s.getStack())).count(); - return fluid > 0; - } - - protected static boolean nonNullSlot(SlotFake[] slots) { - List enabledSlots = Arrays.stream(slots).filter(SlotFake::isEnabled).collect(Collectors.toList()); - long object = enabledSlots.stream().filter(s -> s.getStack() != null).count(); - return object > 0; - } - - protected ItemStack stampAuthor(ItemStack patternStack) { - if (patternStack.stackTagCompound == null) { - patternStack.stackTagCompound = new NBTTagCompound(); - } - patternStack.stackTagCompound.setString("author", getPlayerInv().player.getCommandSenderName()); - return patternStack; - } - - protected void encodeFluidPattern() { - ItemStack patternStack = AEApi.instance().definitions().items().encodedUltimatePattern().maybeStack(1).orNull(); - if (patternStack != null) { - final NBTTagCompound encodedValue = new NBTTagCompound(); - - final ItemStack[] in = this.getInputs(); - final ItemStack[] out = this.getOutputs(); - - final NBTTagList tagIn = new NBTTagList(); - final NBTTagList tagOut = new NBTTagList(); - - for (final ItemStack i : in) { - if (i != null) { - if (i.getItem() instanceof ItemFluidPacket) { - tagIn.appendTag( - writeStackNBT( - AEFluidStack.create(ItemFluidPacket.getFluidStack(i)), - new NBTTagCompound(), - true)); - } else { - tagIn.appendTag(writeStackNBT(AEItemStack.create(i), new NBTTagCompound(), true)); - } - } - } - - for (final ItemStack i : out) { - if (i != null) { - if (i.getItem() instanceof ItemFluidPacket) { - tagOut.appendTag( - writeStackNBT( - AEFluidStack.create(ItemFluidPacket.getFluidStack(i)), - new NBTTagCompound(), - true)); - } else { - tagOut.appendTag(writeStackNBT(AEItemStack.create(i), new NBTTagCompound(), true)); - } - } - } - - encodedValue.setTag("in", tagIn); - encodedValue.setTag("out", tagOut); - encodedValue.setBoolean("substitute", substitute); - encodedValue.setBoolean("beSubstitute", beSubstitute); - encodedValue.setString("author", this.getPlayerInv().player.getCommandSenderName()); - patternStack.setTagCompound(encodedValue); - patternSlotOUT.putStack(patternStack); - } - } - - protected static IAEItemStack[] collectInventory(Slot[] slots) { - IAEItemStack[] stacks = new IAEItemStack[slots.length]; - for (int i = 0; i < stacks.length; i++) { - ItemStack stack = slots[i].getStack(); - if (stack != null) { - if (stack.getItem() instanceof ItemFluidPacket) { - IAEItemStack dropStack = ItemFluidDrop.newAeStack(ItemFluidPacket.getFluidStack(stack)); - if (dropStack != null) { - stacks[i] = dropStack; - continue; - } - } - } - IAEItemStack aeStack = AEItemStack.create(stack); - stacks[i] = aeStack; - } - return stacks; - } - - @Override - public void saveChanges() { - // NO-OP - } - - public void clear() { - for (final Slot s : this.craftingSlots) { - s.putStack(null); - } - for (final Slot s : this.outputSlots) { - s.putStack(null); - } - this.detectAndSendChanges(); - } - - @Override - public void onChangeInventory(final IInventory inv, final int slot, final InvOperation mc, - final ItemStack removedStack, final ItemStack newStack) { - // NO-OP - } - - public void encodeAndMoveToInventory() { - encode(); - ItemStack output = this.patternSlotOUT.getStack(); - if (output != null) { - if (!getPlayerInv().addItemStackToInventory(output)) { - getPlayerInv().player.entityDropItem(output, 0); - } - this.patternSlotOUT.putStack(null); - } - fillPattern(); - } - - public void encodeAllItemAndMoveToInventory() { - encode(); - ItemStack output = this.patternSlotOUT.getStack(); - if (output != null) { - if (this.patternSlotIN.getStack() != null) output.stackSize += this.patternSlotIN.getStack().stackSize; - if (!getPlayerInv().addItemStackToInventory(output)) { - getPlayerInv().player.entityDropItem(output, 0); - } - this.patternSlotOUT.putStack(null); - this.patternSlotIN.putStack(null); - } - fillPattern(); - } - - private void fillPattern() { - if (this.autoFillPattern && this.getHost().getItemInventory() != null) { - // try to use me network item to fill pattern input slot - final IDefinitions definitions = AEApi.instance().definitions(); - int fillStackSize = this.patternSlotIN.getHasStack() ? 64 - this.patternSlotIN.getStack().stackSize : 64; - if (fillStackSize == 0) return; - for (ItemStack blankPattern : definitions.materials().blankPattern().maybeStack(fillStackSize).asSet()) { - IAEItemStack iBlankPattern = AEApi.instance().storage().createItemStack(blankPattern); - if (this.patternSlotIN.getHasStack() && !iBlankPattern.isSameType(this.patternSlotIN.getStack())) - continue; - IAEItemStack out = this.getHost().getItemInventory() - .extractItems(iBlankPattern, Actionable.MODULATE, this.getActionSource()); - if (out != null) { - ItemStack outPattern; - if (this.patternSlotIN.getHasStack()) { - outPattern = this.patternSlotIN.getStack().copy(); - outPattern.stackSize += out.getItemStack().stackSize; - } else { - outPattern = out.getItemStack(); - } - this.patternSlotIN.putStack(outPattern); - return; - } - } - } - } - - public void encode() { - if (getInputs() != null && getOutputs() != null) { - fillPattern(); - if (isCraftingMode()) { - encodeItemPattern(); - return; - } - ItemStack stack = this.patternSlotOUT.getStack(); - if (stack == null) { - stack = this.patternSlotIN.getStack(); - if (notPattern(stack)) { - return; - } - if (stack.stackSize == 1) { - this.patternSlotIN.putStack(null); - } else { - stack.stackSize--; - } - encodeFluidPattern(); - } else if (!notPattern(stack)) { - encodeFluidPattern(); - } - } - } - - public void encodeItemPattern() { - ItemStack output = this.patternSlotOUT.getStack(); - final ItemStack[] in = this.getInputs(); - final ItemStack[] out = this.getOutputs(); - - // first check the output slots, should either be null, or a pattern - if (output != null && this.notPattern(output)) { - return; - } // if nothing is there we should snag a new pattern. - else if (output == null) { - output = this.patternSlotIN.getStack(); - if (this.notPattern(output)) { - return; // no blanks. - } - - // remove one, and clear the input slot. - output.stackSize--; - if (output.stackSize == 0) { - this.patternSlotIN.putStack(null); - } - - // add a new encoded pattern. - for (final ItemStack encodedPatternStack : AEApi.instance().definitions().items().encodedPattern() - .maybeStack(1).asSet()) { - output = encodedPatternStack; - } - } else if (output.getItem() instanceof ItemFluidEncodedPattern) { - for (final ItemStack encodedPatternStack : AEApi.instance().definitions().items().encodedPattern() - .maybeStack(1).asSet()) { - output = encodedPatternStack; - } - } - - // encode the slot. - final NBTTagCompound encodedValue = new NBTTagCompound(); - - final NBTTagList tagIn = new NBTTagList(); - final NBTTagList tagOut = new NBTTagList(); - - for (final ItemStack i : in) { - tagIn.appendTag(this.createItemTag(i)); - } - - for (final ItemStack i : out) { - tagOut.appendTag(this.createItemTag(i)); - } - - encodedValue.setTag("in", tagIn); - encodedValue.setTag("out", tagOut); - encodedValue.setBoolean("crafting", this.craftingMode); - encodedValue.setBoolean("substitute", this.substitute); - encodedValue.setBoolean("beSubstitute", this.beSubstitute); - encodedValue.setBoolean("prioritize", this.prioritize); - output.setTagCompound(encodedValue); - stampAuthor(output); - this.patternSlotOUT.putStack(output); - } - - protected ItemStack[] getInputs() { - final ArrayList input = new ArrayList<>(); - for (SlotFake craftingSlot : this.craftingSlots) { - input.add(craftingSlot.getStack()); - } - if (input.stream().anyMatch(Objects::nonNull)) { - return input.toArray(new ItemStack[0]); - } - return null; - } - - protected ItemStack[] getOutputs() { - final ArrayList output = new ArrayList<>(); - for (final SlotFake outputSlot : this.outputSlots) { - output.add(outputSlot.getStack()); - } - if (output.stream().anyMatch(Objects::nonNull)) { - return output.toArray(new ItemStack[0]); - } - return null; - } - - protected boolean notPattern(final ItemStack output) { - if (output == null) { - return true; - } - if (output.getItem() instanceof ItemFluidEncodedPattern) { - return false; - } - final IDefinitions definitions = AEApi.instance().definitions(); - - boolean isPattern = definitions.items().encodedPattern().isSameAs(output); - isPattern |= definitions.materials().blankPattern().isSameAs(output); - - boolean isUltimatePattern = definitions.items().encodedUltimatePattern().isSameAs(output); - isUltimatePattern |= definitions.materials().blankPattern().isSameAs(output); - - return !isPattern && !isUltimatePattern; - } - - protected NBTBase createItemTag(final ItemStack i) { - final NBTTagCompound c = new NBTTagCompound(); - if (i != null) { - Util.writeItemStackToNBT(i, c); - } - return c; - } - - @Override - public void detectAndSendChanges() { - super.detectAndSendChanges(); - if (Platform.isServer()) { - this.substitute = this.patternTerminal.isSubstitution(); - this.combine = this.patternTerminal.shouldCombine(); - this.beSubstitute = this.patternTerminal.canBeSubstitute(); - this.prioritize = this.patternTerminal.isPrioritize(); - this.autoFillPattern = this.patternTerminal.isAutoFillPattern(); - } - } - - @Override - public void onSlotChange(final Slot s) { - if (s == this.patternSlotOUT && Platform.isServer()) { - for (final Object crafter : this.crafters) { - final ICrafting icrafting = (ICrafting) crafter; - - for (final Object g : this.inventorySlots) { - if (g instanceof OptionalSlotFake || g instanceof SlotFakeCraftingMatrix) { - final Slot sri = (Slot) g; - icrafting.sendSlotContents(this, sri.slotNumber, sri.getStack()); - } - } - ((EntityPlayerMP) icrafting).isChangingQuantityOnly = false; - } - this.detectAndSendChanges(); - } - } - - @Override - public IInventory getInventoryByName(final String name) { - if (name.equals("player")) { - return this.getInventoryPlayer(); - } - return this.patternTerminal.getInventoryByName(name); - } - - @Override - public boolean useRealItems() { - return false; - } - - public void doubleStacks(int val) { - multiplyOrDivideStacks( - ((val & 1) != 0 ? MULTIPLE_OF_BUTTON_CLICK_ON_SHIFT : MULTIPLE_OF_BUTTON_CLICK) - * ((val & 2) != 0 ? -1 : 1)); - } - - static boolean canMultiplyOrDivide(SlotFake[] slots, int mult) { - if (mult > 0) { - for (Slot s : slots) { - ItemStack st = s.getStack(); - if (st == null) continue; - final long count; - if (st.getItem() instanceof ItemFluidPacket) { - count = ItemFluidPacket.getFluidAmount(st); - } else { - count = s.getStack().stackSize; - } - long result = count * mult; - if (result > Integer.MAX_VALUE) { - return false; - } - } - return true; - } else if (mult < 0) { - mult = Math.abs(mult); - for (Slot s : slots) { - ItemStack st = s.getStack(); - if (st == null) continue; - final long count; - if (st.getItem() instanceof ItemFluidPacket) { - count = ItemFluidPacket.getFluidAmount(st); - } else { - count = s.getStack().stackSize; - } - if (count % mult != 0) { - return false; - } - } - return true; - } - return false; - } - - static void multiplyOrDivideStacksInternal(SlotFake[] slots, int mult) { - List enabledSlots = Arrays.stream(slots).filter(SlotFake::isEnabled).collect(Collectors.toList()); - if (mult > 0) { - for (final Slot s : enabledSlots) { - ItemStack st = s.getStack(); - if (st != null) { - if (st.getItem() instanceof ItemFluidPacket) { - ItemFluidPacket.setFluidAmount(st, ItemFluidPacket.getFluidAmount(st) * mult); - } else { - st.stackSize *= mult; - s.putStack(st); - } - } - } - } else if (mult < 0) { - mult = Math.abs(mult); - for (final Slot s : enabledSlots) { - ItemStack st = s.getStack(); - if (st != null) { - if (st.getItem() instanceof ItemFluidPacket) { - ItemFluidPacket.setFluidAmount(st, ItemFluidPacket.getFluidAmount(st) / mult); - } else { - st.stackSize /= mult; - s.putStack(st); - } - } - } - } - } - - /** - * Multiply or divide a number - * - * @param multi Positive numbers are multiplied and negative numbers are divided - */ - public void multiplyOrDivideStacks(int multi) { - if (!isCraftingMode()) { - if (canMultiplyOrDivide(this.craftingSlots, multi) && canMultiplyOrDivide(this.outputSlots, multi)) { - multiplyOrDivideStacksInternal(this.craftingSlots, multi); - multiplyOrDivideStacksInternal(this.outputSlots, multi); - } - this.detectAndSendChanges(); - } - } - - @Override - public void acceptPattern(IAEItemStack[] inputs, IAEItemStack[] outputs) { - if (this.patternTerminal != null) { - this.patternTerminal.onChangeCrafting(inputs, outputs); - } - } - - public boolean isCraftingMode() { - return this.craftingMode; - } -} diff --git a/src/main/java/com/glodblock/github/client/gui/container/base/FCContainerMonitor.java b/src/main/java/com/glodblock/github/client/gui/container/base/FCContainerMonitor.java deleted file mode 100644 index bb50853f..00000000 --- a/src/main/java/com/glodblock/github/client/gui/container/base/FCContainerMonitor.java +++ /dev/null @@ -1,346 +0,0 @@ -package com.glodblock.github.client.gui.container.base; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -import javax.annotation.Nonnull; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.ICrafting; -import net.minecraft.item.ItemStack; - -import com.glodblock.github.inventory.item.BaseWirelessInventory; -import com.glodblock.github.inventory.item.IWirelessTerminal; -import com.glodblock.github.network.SPacketMEUpdateBuffer; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; - -import appeng.api.config.Actionable; -import appeng.api.config.CraftingAllow; -import appeng.api.config.PinsState; -import appeng.api.config.PowerMultiplier; -import appeng.api.config.SecurityPermissions; -import appeng.api.config.Settings; -import appeng.api.config.SortDir; -import appeng.api.config.SortOrder; -import appeng.api.config.TypeFilter; -import appeng.api.config.ViewItems; -import appeng.api.networking.IGridNode; -import appeng.api.networking.crafting.ICraftingCPU; -import appeng.api.networking.crafting.ICraftingGrid; -import appeng.api.networking.energy.IEnergyGrid; -import appeng.api.networking.security.PlayerSource; -import appeng.api.storage.IMEMonitor; -import appeng.api.storage.IMEMonitorHandlerReceiver; -import appeng.api.storage.ITerminalHost; -import appeng.api.storage.ITerminalPins; -import appeng.api.storage.StorageChannel; -import appeng.api.storage.data.IAEItemStack; -import appeng.api.storage.data.IAEStack; -import appeng.api.util.IConfigManager; -import appeng.api.util.IConfigurableObject; -import appeng.container.guisync.GuiSync; -import appeng.container.slot.SlotRestrictedInput; -import appeng.core.AELog; -import appeng.core.sync.network.NetworkHandler; -import appeng.core.sync.packets.PacketValueConfig; -import appeng.helpers.IPinsHandler; -import appeng.helpers.WirelessTerminalGuiObject; -import appeng.items.contents.PinsHandler; -import appeng.util.ConfigManager; -import appeng.util.IConfigManagerHost; -import appeng.util.Platform; - -public abstract class FCContainerMonitor> extends FCBaseContainer - implements IConfigManagerHost, IConfigurableObject, IMEMonitorHandlerReceiver, IPinsHandler { - - protected final SlotRestrictedInput[] cellView = new SlotRestrictedInput[5]; - protected final IConfigManager clientCM; - protected final ITerminalHost host; - - protected PinsHandler pinsHandler = null; - - @GuiSync(99) - public boolean canAccessViewCells = false; - - @GuiSync(98) - public boolean hasPower = false; - - protected IConfigManagerHost gui; - protected IConfigManager serverCM; - protected IGridNode networkNode; - protected IMEMonitor monitor; - - public FCContainerMonitor(final InventoryPlayer ip, final ITerminalHost monitorable) { - this(ip, monitorable, true); - } - - protected FCContainerMonitor(final InventoryPlayer ip, final ITerminalHost monitorable, - final boolean bindInventory) { - super(ip, monitorable); - this.host = monitorable; - this.clientCM = new ConfigManager(this); - this.clientCM.registerSetting(Settings.SORT_BY, SortOrder.NAME); - this.clientCM.registerSetting(Settings.VIEW_MODE, ViewItems.ALL); - this.clientCM.registerSetting(Settings.SORT_DIRECTION, SortDir.ASCENDING); - this.clientCM.registerSetting(Settings.TYPE_FILTER, TypeFilter.ALL); - this.clientCM.registerSetting(Settings.PINS_STATE, PinsState.DISABLED); // use for GUI - - if (Platform.isServer()) { - if (monitorable instanceof ITerminalPins t && !(monitorable instanceof BaseWirelessInventory bwi - && bwi.getChannel() == StorageChannel.FLUIDS)) { - pinsHandler = t.getPinsHandler(ip.player); - } - } - } - - public IMEMonitor getMonitor() { - return this.monitor; - } - - public IGridNode getNetworkNode() { - return this.networkNode; - } - - @Override - public void detectAndSendChanges() { - if (Platform.isServer()) { - if (isInvalid()) { - this.setValidContainer(false); - } - if (this.serverCM != null) { - for (final Settings set : this.serverCM.getSettings()) { - final Enum sideLocal = this.serverCM.getSetting(set); - final Enum sideRemote = this.clientCM.getSetting(set); - - if (sideLocal != sideRemote) { - this.clientCM.putSetting(set, sideLocal); - for (final Object crafter : this.crafters) { - try { - NetworkHandler.instance.sendTo( - new PacketValueConfig(set.name(), sideLocal.name()), - (EntityPlayerMP) crafter); - } catch (final IOException e) { - AELog.debug(e); - } - } - } - } - } - - if (pinsHandler != null) { - if (clientCM.getSetting(Settings.PINS_STATE) != pinsHandler.getPinsState()) { - this.clientCM.putSetting(Settings.PINS_STATE, pinsHandler.getPinsState()); - updatePins(true); - } else { - updatePins(false); - } - } - - processItemList(); - this.updatePowerStatus(); - final boolean oldAccessible = this.canAccessViewCells; - this.canAccessViewCells = this.host instanceof WirelessTerminalGuiObject - || this.host instanceof IWirelessTerminal - || this.hasAccess(SecurityPermissions.BUILD, false); - if (this.canAccessViewCells != oldAccessible) { - for (int y = 0; y < 5; y++) { - if (this.cellView[y] != null) { - this.cellView[y].setAllowEdit(this.canAccessViewCells); - } - } - } - super.detectAndSendChanges(); - } - } - - private int lastUpdate = 0; - - public void updatePins(boolean forceUpdate) { - if (pinsHandler == null || !(host instanceof ITerminalPins itp)) return; - - boolean isActive = pinsHandler.getPinsState() != PinsState.DISABLED; - ++lastUpdate; - if (!forceUpdate && lastUpdate <= 20) return; - lastUpdate = 0; - if (isActive) { - final ICraftingGrid cc = itp.getGrid().getCache(ICraftingGrid.class); - final ImmutableList cpuList = cc.getCpus().asList(); - - List craftedItems = new ArrayList<>(); - - // fetch the first available crafting output - for (int i = 0; i < cpuList.size(); i++) { - ICraftingCPU cpu = cpuList.get(i); - if (cpu.getCraftingAllowMode() != CraftingAllow.ONLY_NONPLAYER && cpu.getFinalOutput() != null - && cpu.getCurrentJobSource() instanceof PlayerSource src - && src.player == pinsHandler.getPlayer()) { - if (craftedItems.contains(cpu.getFinalOutput())) { - continue; // skip if already added - } - if (cpu.isBusy()) craftedItems.add(0, cpu.getFinalOutput().copy()); - else craftedItems.add(cpu.getFinalOutput().copy()); - } - } - - pinsHandler.addItemsToPins(craftedItems); - } - pinsHandler.update(forceUpdate); - onListUpdate(); // notify the repo that the pins have changed - } - - @Override - public void setPin(ItemStack is, int idx) { - if (pinsHandler == null || !(host instanceof ITerminalPins itp)) return; - - if (is == null) { - final ICraftingGrid cc = itp.getGrid().getCache(ICraftingGrid.class); - final ImmutableSet cpuSet = cc.getCpus(); - for (ICraftingCPU cpu : cpuSet) { - if (cpu.getCraftingAllowMode() != CraftingAllow.ONLY_NONPLAYER && cpu.getFinalOutput() != null - && cpu.getFinalOutput().isSameType(getPin(idx))) { - if (!cpu.isBusy()) { - cpu.resetFinalOutput(); - } else { - return; - } - } - } - } - pinsHandler.setPin(idx, is); - updatePins(true); - } - - @Override - public ItemStack getPin(int idx) { - if (pinsHandler == null) return null; - return pinsHandler.getPin(idx); - } - - public void setPinsState(PinsState pinsState) { - if (pinsHandler == null) return; - clientCM.putSetting(Settings.PINS_STATE, pinsState); - pinsHandler.setPinsState(pinsState); - updatePins(true); - } - - public PinsState getPinsState() { - return pinsHandler != null ? pinsHandler.getPinsState() : PinsState.DISABLED; - } - - public PinsHandler getPinsHandler() { - return pinsHandler; - } - - protected abstract void processItemList(); - - protected boolean isInvalid() { - return this.monitor == null; - } - - protected void updatePowerStatus() { - try { - if (this.networkNode != null) { - this.setPowered(this.networkNode.isActive()); - } else if (this.getPowerSource() instanceof IEnergyGrid) { - this.setPowered(((IEnergyGrid) this.getPowerSource()).isNetworkPowered()); - } else { - this.setPowered( - this.getPowerSource().extractAEPower(1, Actionable.SIMULATE, PowerMultiplier.CONFIG) > 0.8); - } - } catch (final Throwable ignore) {} - } - - @Override - public void onUpdate(final String field, final Object oldValue, final Object newValue) { - if (field.equals("canAccessViewCells")) { - for (int y = 0; y < 5; y++) { - if (this.cellView[y] != null) { - this.cellView[y].setAllowEdit(this.canAccessViewCells); - } - } - } - super.onUpdate(field, oldValue, newValue); - } - - @Override - public void addCraftingToCrafters(final ICrafting c) { - super.addCraftingToCrafters(c); - this.queueInventory(c); - } - - protected abstract void queueInventory(final ICrafting c); - - @Override - public void onContainerClosed(final EntityPlayer player) { - super.onContainerClosed(player); - if (this.monitor != null) { - this.monitor.removeListener(this); - if (player instanceof EntityPlayerMP && Platform.isServer()) { - SPacketMEUpdateBuffer.clear((EntityPlayerMP) player); - } - - } - } - - @Override - public IConfigManager getConfigManager() { - if (Platform.isServer()) { - return this.serverCM; - } - return this.clientCM; - } - - public ItemStack[] getViewCells() { - final ItemStack[] list = new ItemStack[this.cellView.length]; - for (int x = 0; x < this.cellView.length; x++) { - list[x] = this.cellView[x].getStack(); - } - return list; - } - - public SlotRestrictedInput getCellViewSlot(final int index) { - return this.cellView[index]; - } - - public boolean isPowered() { - return this.hasPower; - } - - protected void setPowered(final boolean isPowered) { - this.hasPower = isPowered; - } - - protected IConfigManagerHost getGui() { - return this.gui; - } - - public void setGui(@Nonnull final IConfigManagerHost gui) { - this.gui = gui; - } - - @Override - public boolean isValid(Object verificationToken) { - return true; - } - - @Override - public void onListUpdate() { - for (final Object c : this.crafters) { - if (c instanceof final ICrafting cr) { - this.queueInventory(cr); - } - } - } - - @Override - public void updateSetting(final IConfigManager manager, @SuppressWarnings("rawtypes") final Enum settingName, - @SuppressWarnings("rawtypes") final Enum newValue) { - if (this.getGui() != null) { - this.getGui().updateSetting(manager, settingName, newValue); - } - } -} diff --git a/src/main/java/com/glodblock/github/client/me/EssentiaRepo.java b/src/main/java/com/glodblock/github/client/me/EssentiaRepo.java deleted file mode 100644 index dc750422..00000000 --- a/src/main/java/com/glodblock/github/client/me/EssentiaRepo.java +++ /dev/null @@ -1,145 +0,0 @@ -package com.glodblock.github.client.me; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.Set; -import java.util.regex.Pattern; - -import net.minecraftforge.fluids.Fluid; - -import com.glodblock.github.common.item.ItemFluidDrop; -import com.glodblock.github.crossmod.thaumcraft.AspectUtil; -import com.glodblock.github.util.FluidSorters; - -import appeng.api.config.SearchBoxMode; -import appeng.api.config.Settings; -import appeng.api.config.SortOrder; -import appeng.api.config.ViewItems; -import appeng.api.storage.data.IAEItemStack; -import appeng.client.gui.widgets.IScrollSource; -import appeng.client.gui.widgets.ISortSource; -import appeng.core.AEConfig; - -public class EssentiaRepo extends FluidRepo { - - public EssentiaRepo(final IScrollSource src, final ISortSource sortSrc) { - super(src, sortSrc); - } - - @SuppressWarnings("deprecation") - @Override - public void updateView() { - if (this.paused) { - // Update existing view with new data - for (int i = 0; i < this.view.size(); i++) { - IAEItemStack entry = this.view.get(i); - IAEItemStack serverEntry = this.list.findPrecise(entry); - if (serverEntry == null) { - entry.setStackSize(0); - } else { - this.view.set(i, serverEntry); - } - } - - // Append newly added item stacks to the end of the view - Set viewSet = new HashSet<>(this.view); - ArrayList entriesToAdd = new ArrayList<>(); - for (IAEItemStack serverEntry : this.list) { - if (!viewSet.contains(serverEntry)) { - entriesToAdd.add(serverEntry); - } - } - addEntriesToView(entriesToAdd); - } else { - this.view.clear(); - this.view.ensureCapacity(this.list.size()); - addEntriesToView(this.list); - } - - // Do not sort if paused - if (!this.paused) { - final Enum SortBy = this.sortSrc.getSortBy(); - final Enum SortDir = this.sortSrc.getSortDir(); - - FluidSorters.setDirection((appeng.api.config.SortDir) SortDir); - FluidSorters.init(); - - if (SortBy == SortOrder.MOD) { - this.view.sort(FluidSorters.CONFIG_BASED_SORT_BY_MOD); - } else if (SortBy == SortOrder.AMOUNT) { - this.view.sort(FluidSorters.CONFIG_BASED_SORT_BY_SIZE); - } else if (SortBy == SortOrder.INVTWEAKS) { - this.view.sort(FluidSorters.CONFIG_BASED_SORT_BY_INV_TWEAKS); - } else { - this.view.sort(FluidSorters.CONFIG_BASED_SORT_BY_NAME); - } - } - - // Update the display - this.dsp.clear(); - this.dsp.ensureCapacity(this.list.size()); - for (final IAEItemStack is : this.view) { - this.dsp.add(is.getItemStack()); - } - } - - private void addEntriesToView(Iterable entries) { - final Enum viewMode = this.sortSrc.getSortDisplay(); - final Enum searchMode = AEConfig.instance.settings.getSetting(Settings.SEARCH_MODE); - if (searchMode == SearchBoxMode.NEI_AUTOSEARCH || searchMode == SearchBoxMode.NEI_MANUAL_SEARCH) { - this.updateNEI(this.searchString); - } - - String innerSearch = this.searchString; - - if (innerSearch.startsWith("@")) { - innerSearch = innerSearch.substring(1); - } - - Pattern m; - try { - m = Pattern.compile(innerSearch.toLowerCase(), Pattern.CASE_INSENSITIVE); - } catch (final Throwable ignore) { - try { - m = Pattern.compile(Pattern.quote(innerSearch.toLowerCase()), Pattern.CASE_INSENSITIVE); - } catch (final Throwable __) { - return; - } - } - - for (IAEItemStack is : entries) { - if (!AspectUtil.isEssentiaGas(ItemFluidDrop.getAeFluidStack(is))) { - continue; - } - - if (this.myPartitionList != null) { - if (!this.myPartitionList.isListed(is)) { - continue; - } - } - - if (viewMode == ViewItems.CRAFTABLE && !is.isCraftable()) { - continue; - } - - if (viewMode == ViewItems.CRAFTABLE) { - is = is.copy(); - is.setStackSize(0); - } - - if (viewMode == ViewItems.STORED && is.getStackSize() == 0) { - continue; - } - - Fluid fluid = ItemFluidDrop.getAeFluidStack(is).getFluid(); - if (!AspectUtil.isEssentiaGas(fluid)) { - continue; - } - - if (m.matcher(fluid.getLocalizedName().toLowerCase()).find()) { - this.view.add(is); - } - } - } - -} diff --git a/src/main/java/com/glodblock/github/client/me/FluidRepo.java b/src/main/java/com/glodblock/github/client/me/FluidRepo.java deleted file mode 100644 index 4dc6c749..00000000 --- a/src/main/java/com/glodblock/github/client/me/FluidRepo.java +++ /dev/null @@ -1,296 +0,0 @@ -/* - * This file is part of Applied Energistics 2. Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. Applied - * Energistics 2 is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General - * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any - * later version. Applied Energistics 2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General - * Public License for more details. You should have received a copy of the GNU Lesser General Public License along with - * Applied Energistics 2. If not, see . - */ - -package com.glodblock.github.client.me; - -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.Set; -import java.util.regex.Pattern; - -import javax.annotation.Nonnull; - -import net.minecraft.item.ItemStack; -import net.minecraftforge.fluids.Fluid; - -import com.glodblock.github.api.FluidCraftAPI; -import com.glodblock.github.common.item.ItemFluidDrop; -import com.glodblock.github.util.FluidSorters; -import com.glodblock.github.util.Util; - -import appeng.api.AEApi; -import appeng.api.config.SearchBoxMode; -import appeng.api.config.Settings; -import appeng.api.config.SortOrder; -import appeng.api.config.ViewItems; -import appeng.api.storage.data.IAEItemStack; -import appeng.api.storage.data.IDisplayRepo; -import appeng.api.storage.data.IItemList; -import appeng.client.gui.widgets.IScrollSource; -import appeng.client.gui.widgets.ISortSource; -import appeng.core.AEConfig; -import appeng.items.storage.ItemViewCell; -import appeng.util.prioitylist.IPartitionList; -import cpw.mods.fml.relauncher.ReflectionHelper; - -public class FluidRepo implements IDisplayRepo { - - protected final IItemList list = AEApi.instance().storage().createItemList(); - protected final ArrayList view = new ArrayList<>(); - protected final ArrayList dsp = new ArrayList<>(); - protected final IScrollSource src; - protected final ISortSource sortSrc; - - protected int rowSize = 9; - - protected String searchString = ""; - protected IPartitionList myPartitionList; - protected boolean paused = false; - private String NEIWord = null; - private boolean hasPower; - - public FluidRepo(final IScrollSource src, final ISortSource sortSrc) { - this.src = src; - this.sortSrc = sortSrc; - } - - @Override - public IAEItemStack getReferenceItem(int idx) { - idx += this.src.getCurrentScroll() * this.rowSize; - - if (idx >= this.view.size()) { - return null; - } - return this.view.get(idx); - } - - @Override - public ItemStack getItem(int idx) { - idx += this.src.getCurrentScroll() * this.rowSize; - - if (idx >= this.dsp.size()) { - return null; - } - return this.dsp.get(idx); - } - - @Override - public void postUpdate(final IAEItemStack is) { - final IAEItemStack st = this.list.findPrecise(is); - if (st != null) { - st.reset(); - st.add(is); - } else { - this.list.add(is); - } - } - - @Override - public void setViewCell(final ItemStack[] list) { - this.myPartitionList = ItemViewCell.createFilter(list); - this.updateView(); - } - - @SuppressWarnings("deprecation") - @Override - public void updateView() { - if (this.paused) { - // Update existing view with new data - for (int i = 0; i < this.view.size(); i++) { - IAEItemStack entry = this.view.get(i); - IAEItemStack serverEntry = this.list.findPrecise(entry); - if (serverEntry == null) { - entry.setStackSize(0); - } else { - this.view.set(i, serverEntry); - } - } - - // Append newly added item stacks to the end of the view - Set viewSet = new HashSet<>(this.view); - ArrayList entriesToAdd = new ArrayList<>(); - for (IAEItemStack serverEntry : this.list) { - if (!viewSet.contains(serverEntry)) { - entriesToAdd.add(serverEntry); - } - } - addEntriesToView(entriesToAdd); - } else { - this.view.clear(); - this.view.ensureCapacity(this.list.size()); - addEntriesToView(this.list); - } - - // Do not sort if paused - if (!paused) { - final Enum SortBy = this.sortSrc.getSortBy(); - final Enum SortDir = this.sortSrc.getSortDir(); - - FluidSorters.setDirection((appeng.api.config.SortDir) SortDir); - FluidSorters.init(); - - if (SortBy == SortOrder.MOD) { - this.view.sort(FluidSorters.CONFIG_BASED_SORT_BY_MOD); - } else if (SortBy == SortOrder.AMOUNT) { - this.view.sort(FluidSorters.CONFIG_BASED_SORT_BY_SIZE); - } else if (SortBy == SortOrder.INVTWEAKS) { - this.view.sort(FluidSorters.CONFIG_BASED_SORT_BY_INV_TWEAKS); - } else { - this.view.sort(FluidSorters.CONFIG_BASED_SORT_BY_NAME); - } - } - - this.dsp.clear(); - this.dsp.ensureCapacity(this.list.size()); - for (final IAEItemStack is : this.view) { - this.dsp.add(is.getItemStack()); - } - } - - private void addEntriesToView(Iterable entries) { - final Enum viewMode = this.sortSrc.getSortDisplay(); - final Enum searchMode = AEConfig.instance.settings.getSetting(Settings.SEARCH_MODE); - if (searchMode == SearchBoxMode.NEI_AUTOSEARCH || searchMode == SearchBoxMode.NEI_MANUAL_SEARCH) { - this.updateNEI(this.searchString); - } - - String innerSearch = this.searchString; - - boolean searchMod = false; - if (innerSearch.startsWith("@")) { - searchMod = true; - innerSearch = innerSearch.substring(1); - } - - Pattern m; - try { - m = Pattern.compile(innerSearch.toLowerCase(), Pattern.CASE_INSENSITIVE); - } catch (final Throwable ignore) { - try { - m = Pattern.compile(Pattern.quote(innerSearch.toLowerCase()), Pattern.CASE_INSENSITIVE); - } catch (final Throwable __) { - return; - } - } - - for (IAEItemStack is : entries) { - if (this.myPartitionList != null) { - if (!this.myPartitionList.isListed(is)) { - continue; - } - } - - if (viewMode == ViewItems.CRAFTABLE && !is.isCraftable()) { - continue; - } - - if (viewMode == ViewItems.CRAFTABLE) { - is = is.copy(); - is.setStackSize(0); - } - - if (viewMode == ViewItems.STORED && is.getStackSize() == 0) { - continue; - } - - Fluid fluid = ItemFluidDrop.getAeFluidStack(is).getFluid(); - - if (FluidCraftAPI.instance().isBlacklistedInDisplay(fluid.getClass())) { - continue; - } - - if (searchMod) { - if (m.matcher(Util.getFluidModID(fluid).toLowerCase()).find() - || m.matcher(Util.getFluidModName(fluid).toLowerCase()).find()) { - this.view.add(is); - } - } else { - if (m.matcher(fluid.getLocalizedName().toLowerCase()).find()) { - this.view.add(is); - } - } - } - } - - protected void updateNEI(final String filter) { - try { - if (this.NEIWord == null || !this.NEIWord.equals(filter)) { - final Class c = ReflectionHelper - .getClass(this.getClass().getClassLoader(), "codechicken.nei.LayoutManager"); - final Field fldSearchField = c.getField("searchField"); - final Object searchField = fldSearchField.get(c); - - final Method a = searchField.getClass().getMethod("setText", String.class); - final Method b = searchField.getClass().getMethod("onTextChange", String.class); - - this.NEIWord = filter; - a.invoke(searchField, filter); - b.invoke(searchField, ""); - } - } catch (final Throwable ignore) { - - } - } - - @Override - public int size() { - return this.view.size(); - } - - @Override - public void clear() { - this.list.resetStatus(); - } - - @Override - public boolean hasPower() { - return this.hasPower; - } - - @Override - public void setPowered(final boolean hasPower) { - this.hasPower = hasPower; - } - - public int getRowSize() { - return this.rowSize; - } - - public void setRowSize(final int rowSize) { - this.rowSize = rowSize; - } - - public String getSearchString() { - return this.searchString; - } - - public void setSearchString(@Nonnull final String searchString) { - this.searchString = searchString; - } - - @Override - public boolean isPaused() { - return this.paused; - } - - @Override - public void setPaused(boolean paused) { - if (this.paused != paused) { - this.paused = paused; - - // Update view when un-paused - if (!paused) { - updateView(); - } - } - } -} diff --git a/src/main/java/com/glodblock/github/common/block/BlockFluidInterface.java b/src/main/java/com/glodblock/github/common/block/BlockFluidInterface.java index 33007194..fe42c102 100644 --- a/src/main/java/com/glodblock/github/common/block/BlockFluidInterface.java +++ b/src/main/java/com/glodblock/github/common/block/BlockFluidInterface.java @@ -11,14 +11,12 @@ import net.minecraftforge.common.util.ForgeDirection; import com.glodblock.github.client.render.RenderBlockFluidInterface; import com.glodblock.github.common.tabs.FluidCraftingTabs; import com.glodblock.github.common.tile.TileFluidInterface; -import com.glodblock.github.inventory.InventoryHandler; -import com.glodblock.github.inventory.gui.GuiType; -import com.glodblock.github.util.BlockPos; import com.glodblock.github.util.NameConst; import appeng.api.util.IOrientable; import appeng.block.AEBaseItemBlock; import appeng.core.features.AEFeature; +import appeng.core.sync.GuiBridge; import appeng.tile.misc.TileInterface; import appeng.util.Platform; import cpw.mods.fml.common.registry.GameRegistry; @@ -50,12 +48,7 @@ public class BlockFluidInterface extends FCBaseBlock { final TileInterface tg = this.getTileEntity(world, x, y, z); if (tg != null) { if (Platform.isServer()) { - InventoryHandler.openGui( - player, - world, - new BlockPos(x, y, z), - ForgeDirection.getOrientation(facing), - GuiType.DUAL_INTERFACE); + Platform.openGUI(player, tg, ForgeDirection.getOrientation(facing), GuiBridge.GUI_INTERFACE); } return true; } diff --git a/src/main/java/com/glodblock/github/common/item/FCBaseItemCell.java b/src/main/java/com/glodblock/github/common/item/FCBaseItemCell.java index 3df9d121..85fe2c0b 100644 --- a/src/main/java/com/glodblock/github/common/item/FCBaseItemCell.java +++ b/src/main/java/com/glodblock/github/common/item/FCBaseItemCell.java @@ -1,70 +1,33 @@ package com.glodblock.github.common.item; -import java.text.NumberFormat; -import java.util.Arrays; -import java.util.EnumSet; -import java.util.List; - -import net.minecraft.client.gui.GuiScreen; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; -import net.minecraft.util.EnumChatFormatting; -import net.minecraft.util.StatCollector; -import net.minecraft.world.World; -import net.minecraftforge.common.util.ForgeDirection; -import com.glodblock.github.api.FluidCraftAPI; import com.glodblock.github.common.storage.CellType; -import com.glodblock.github.common.storage.FluidCellInventory; -import com.glodblock.github.common.storage.FluidCellInventoryHandler; -import com.glodblock.github.common.storage.IStorageFluidCell; -import com.glodblock.github.inventory.FluidCellConfig; import com.glodblock.github.loader.ItemAndBlockHolder; -import com.glodblock.github.util.NameConst; import com.google.common.base.Optional; -import appeng.api.AEApi; -import appeng.api.config.FuzzyMode; -import appeng.api.config.IncludeExclude; -import appeng.api.implementations.items.IUpgradeModule; -import appeng.api.storage.IMEInventoryHandler; import appeng.api.storage.StorageChannel; -import appeng.api.storage.data.IAEFluidStack; -import appeng.api.storage.data.IItemList; -import appeng.core.features.AEFeature; -import appeng.core.localization.GuiText; -import appeng.helpers.ICellRestriction; -import appeng.items.AEBaseItem; -import appeng.items.contents.CellUpgrades; -import appeng.util.InventoryAdaptor; -import appeng.util.IterationCounter; -import appeng.util.Platform; -import appeng.util.ReadableNumberConverter; +import appeng.items.AEBaseCell; -public abstract class FCBaseItemCell extends AEBaseItem implements IStorageFluidCell, ICellRestriction { +public abstract class FCBaseItemCell extends AEBaseCell { protected CellType component; - protected long totalBytes; - protected int perType; - protected double idleDrain; - protected int maxType = 1; - private final ReadableNumberConverter format = ReadableNumberConverter.INSTANCE; - @SuppressWarnings("Guava") public FCBaseItemCell(long bytes, int perType, int totalType, double drain) { super(Optional.of(bytes / 1024 + "k")); - this.setFeature(EnumSet.of(AEFeature.StorageCells)); - this.setMaxStackSize(1); this.totalBytes = bytes; this.perType = perType; this.idleDrain = drain; - this.maxType = totalType; + this.totalTypes = totalType; this.component = null; } - public FCBaseItemCell(final Optional subName) { + @Override + public StorageChannel getStorageChannel() { + return StorageChannel.FLUIDS; + } + + public FCBaseItemCell(Optional subName) { super(subName); } @@ -76,226 +39,6 @@ public abstract class FCBaseItemCell extends AEBaseItem implements IStorageFluid return component.stack(1); } - @Override - public long getBytes(ItemStack cellItem) { - return this.totalBytes; - } - - @Override - public int getBytesPerType(ItemStack cellItem) { - return this.perType; - } - - @Override - public boolean isBlackListed(ItemStack cellItem, IAEFluidStack requestedAddition) { - return requestedAddition == null || requestedAddition.getFluid() == null - || FluidCraftAPI.instance().isBlacklistedInStorage(requestedAddition.getFluid().getClass()); - } - - @Override - public void addCheckedInformation(final ItemStack stack, final EntityPlayer player, final List lines, - final boolean displayMoreInfo) { - final IMEInventoryHandler inventory = AEApi.instance().registries().cell() - .getCellInventory(stack, null, StorageChannel.FLUIDS); - - if (inventory instanceof final FluidCellInventoryHandler handler) { - final FluidCellInventory cellInventory = (FluidCellInventory) handler.getCellInv(); - - if (cellInventory != null) { - lines.add( - EnumChatFormatting.WHITE + NumberFormat.getInstance().format(cellInventory.getUsedBytes()) - + EnumChatFormatting.GRAY - + " " - + GuiText.Of.getLocal() - + " " - + EnumChatFormatting.DARK_GREEN - + NumberFormat.getInstance().format(cellInventory.getTotalBytes()) - + " " - + EnumChatFormatting.GRAY - + GuiText.BytesUsed.getLocal()); - lines.add( - EnumChatFormatting.WHITE + NumberFormat.getInstance().format(cellInventory.getStoredFluidTypes()) - + EnumChatFormatting.GRAY - + " " - + GuiText.Of.getLocal() - + " " - + EnumChatFormatting.DARK_GREEN - + cellInventory.getMaxFluidTypes() - + " " - + EnumChatFormatting.GRAY - + GuiText.Types.getLocal()); - - if (GuiScreen.isCtrlKeyDown()) { - if (cellInventory.getStoredFluidTypes() > 0) { - lines.add(StatCollector.translateToLocal(NameConst.TT_CELL_CONTENTS)); - for (IAEFluidStack fluid : cellInventory.getContents()) { - if (fluid != null) { - lines.add( - String.format( - " %s x%s mB", - fluid.getFluidStack().getLocalizedName(), - format.toWideReadableForm(fluid.getStackSize()))); - } - } - } else { - lines.add(StatCollector.translateToLocal(NameConst.TT_CELL_EMPTY)); - } - } else { - lines.add(StatCollector.translateToLocal(NameConst.TT_CTRL_FOR_MORE)); - } - - if (handler.isPreformatted()) { - final String list = (handler.getWhitelist() == IncludeExclude.WHITELIST ? GuiText.Included - : GuiText.Excluded).getLocal(); - lines.add(GuiText.Partitioned.getLocal() + " - " + list + ' ' + GuiText.Precise.getLocal()); - - if (GuiScreen.isShiftKeyDown()) { - lines.add(GuiText.Filter.getLocal() + ": "); - for (IAEFluidStack aeFluidStack : handler.getPartitionInv()) { - if (aeFluidStack != null) lines.add(" " + aeFluidStack.getFluidStack().getLocalizedName()); - } - } else { - lines.add(StatCollector.translateToLocal(NameConst.TT_SHIFT_FOR_MORE)); - } - if (handler.getSticky()) { - lines.add(GuiText.Sticky.getLocal()); - } - } - List restricted = handler.getRestricted(); - if (restricted != null && ((long) restricted.get(0) != 0 || (byte) restricted.get(1) != 0)) { - lines.add(GuiText.Restricted.getLocal()); - if (GuiScreen.isShiftKeyDown()) { - NumberFormat nf = NumberFormat.getNumberInstance(); - if ((long) restricted.get(0) != 0) - lines.add(GuiText.MaxFluid.getLocal() + " " + nf.format((long) restricted.get(0)) + " mB"); - if ((byte) restricted.get(1) != 0) - lines.add(GuiText.MaxTypes.getLocal() + " " + restricted.get(1)); - } - } - } - } - } - - @Override - public boolean storableInStorageCell() { - return false; - } - - @Override - public boolean isStorageCell(ItemStack i) { - return true; - } - - @Override - public double getIdleDrain(ItemStack is) { - return this.idleDrain; - } - - @Override - public int getTotalTypes(final ItemStack cellItem) { - return this.maxType; - } - - @Override - public boolean isEditable(ItemStack is) { - return true; - } - - @Override - public IInventory getUpgradesInventory(ItemStack is) { - return new CellUpgrades(is, 5); - } - - @Override - public IInventory getConfigInventory(ItemStack is) { - return new FluidCellConfig(is); - } - - @Override - public FuzzyMode getFuzzyMode(ItemStack is) { - final String fz = Platform.openNbtData(is).getString("FuzzyMode"); - try { - return FuzzyMode.valueOf(fz); - } catch (final Throwable t) { - return FuzzyMode.IGNORE_ALL; - } - } - - @Override - public void setFuzzyMode(ItemStack is, FuzzyMode fzMode) { - Platform.openNbtData(is).setString("FuzzyMode", fzMode.name()); - } - - @Override - public String getCellData(ItemStack is) { - return totalBytes + "," - + this.getTotalTypes(null) - + "," - + this.getBytesPerType(null) - + "," - + 256 * 8 - + "," - + Platform.openNbtData(is).getByte("cellRestrictionTypes") - + "," - + Platform.openNbtData(is).getLong("cellRestrictionAmount") - + "," - + "fluid"; - } - - @Override - public void setCellRestriction(ItemStack is, String newData) { - List data = Arrays.asList(newData.split(",", 2)); - Platform.openNbtData(is).setByte("cellRestrictionTypes", Byte.parseByte(data.get(0))); - Platform.openNbtData(is).setLong("cellRestrictionAmount", Long.parseLong(data.get(1))); - } - - @SuppressWarnings("unchecked") - protected boolean disassembleDrive(final ItemStack stack, final World world, final EntityPlayer player) { - if (player.isSneaking()) { - if (Platform.isClient()) { - return false; - } - final InventoryPlayer playerInventory = player.inventory; - final IMEInventoryHandler inv = AEApi.instance().registries().cell() - .getCellInventory(stack, null, StorageChannel.FLUIDS); - if (inv != null && playerInventory.getCurrentItem() == stack) { - final InventoryAdaptor ia = InventoryAdaptor.getAdaptor(player, ForgeDirection.UNKNOWN); - final IItemList list = inv - .getAvailableItems(StorageChannel.FLUIDS.createList(), IterationCounter.fetchNewId()); - if (list.isEmpty() && ia != null) { - playerInventory.setInventorySlotContents(playerInventory.currentItem, null); - - // drop core - final ItemStack extraB = ia.addItems(this.component.stack(1)); - if (extraB != null) { - player.dropPlayerItemWithRandomChoice(extraB, false); - } - - // drop upgrades - final IInventory upgradesInventory = this.getUpgradesInventory(stack); - for (int upgradeIndex = 0; upgradeIndex < upgradesInventory.getSizeInventory(); upgradeIndex++) { - final ItemStack upgradeStack = upgradesInventory.getStackInSlot(upgradeIndex); - final ItemStack leftStack = ia.addItems(upgradeStack); - if (leftStack != null && upgradeStack.getItem() instanceof IUpgradeModule) { - player.dropPlayerItemWithRandomChoice(upgradeStack, false); - } - } - - // drop empty storage cell case - final ItemStack extraA = ia.addItems(this.getHousing()); - if (extraA != null) { - player.dropPlayerItemWithRandomChoice(this.getHousing(), false); - } - if (player.inventoryContainer != null) { - player.inventoryContainer.detectAndSendChanges(); - } - return true; - } - } - } - return false; - } - public ItemStack stack(int size) { return new ItemStack(this, size); } diff --git a/src/main/java/com/glodblock/github/common/item/ItemBaseInfinityStorageCell.java b/src/main/java/com/glodblock/github/common/item/ItemBaseInfinityStorageCell.java deleted file mode 100644 index 6d129dba..00000000 --- a/src/main/java/com/glodblock/github/common/item/ItemBaseInfinityStorageCell.java +++ /dev/null @@ -1,93 +0,0 @@ -package com.glodblock.github.common.item; - -import java.util.List; - -import net.minecraft.client.gui.GuiScreen; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.util.StatCollector; - -import com.glodblock.github.api.FluidCraftAPI; -import com.glodblock.github.common.storage.IFluidCellInventory; -import com.glodblock.github.common.storage.IFluidCellInventoryHandler; -import com.glodblock.github.common.storage.IStorageFluidCell; -import com.glodblock.github.util.NameConst; - -import appeng.api.AEApi; -import appeng.api.storage.IMEInventoryHandler; -import appeng.api.storage.StorageChannel; -import appeng.api.storage.data.IAEFluidStack; -import appeng.items.AEBaseItem; -import appeng.items.contents.CellUpgrades; - -public abstract class ItemBaseInfinityStorageCell extends AEBaseItem implements IStorageFluidCell { - - @Override - public long getBytes(ItemStack cellItem) { - return 0; - } - - @Override - public int getBytesPerType(ItemStack cellItem) { - return 0; - } - - @Override - public boolean isBlackListed(ItemStack cellItem, IAEFluidStack requestedAddition) { - return requestedAddition == null || requestedAddition.getFluid() == null - || FluidCraftAPI.instance().isBlacklistedInStorage(requestedAddition.getFluid().getClass()); - } - - @Override - public boolean storableInStorageCell() { - return false; - } - - @Override - public boolean isStorageCell(ItemStack i) { - return true; - } - - @Override - public double getIdleDrain(ItemStack is) { - return 0; - } - - @Override - public int getTotalTypes(ItemStack cellItem) { - return 0; - } - - @Override - public IInventory getUpgradesInventory(ItemStack is) { - return new CellUpgrades(is, 0); - } - - @Override - public void addCheckedInformation(final ItemStack stack, final EntityPlayer player, final List lines, - final boolean displayMoreInfo) { - final IMEInventoryHandler inventory = AEApi.instance().registries().cell() - .getCellInventory(stack, null, StorageChannel.FLUIDS); - - if (inventory instanceof final IFluidCellInventoryHandler handler) { - final IFluidCellInventory cellInventory = handler.getCellInv(); - - if (GuiScreen.isCtrlKeyDown()) { - if (!cellInventory.getContents().isEmpty()) { - lines.add(StatCollector.translateToLocal(NameConst.TT_CELL_CONTENTS)); - for (IAEFluidStack fluid : cellInventory.getContents()) { - if (fluid != null) { - lines.add(String.format(" %s %s", StatCollector.translateToLocal(NameConst.TT_INFINITY_FLUID_STORAGE_TIPS), fluid.getFluidStack().getLocalizedName())); - } - } - } else { - lines.add(StatCollector.translateToLocal(NameConst.TT_CELL_EMPTY)); - } - } else { - lines.add(StatCollector.translateToLocal(NameConst.TT_CTRL_FOR_MORE)); - } - } - } - -} diff --git a/src/main/java/com/glodblock/github/common/item/ItemBaseWirelessTerminal.java b/src/main/java/com/glodblock/github/common/item/ItemBaseWirelessTerminal.java index 219fe7f2..430524ff 100644 --- a/src/main/java/com/glodblock/github/common/item/ItemBaseWirelessTerminal.java +++ b/src/main/java/com/glodblock/github/common/item/ItemBaseWirelessTerminal.java @@ -1,5 +1,6 @@ package com.glodblock.github.common.item; +import static com.glodblock.github.common.item.ItemWirelessUltraTerminal.MODE; import static com.glodblock.github.loader.recipe.WirelessTerminalEnergyRecipe.getEnergyCard; import static com.glodblock.github.loader.recipe.WirelessTerminalRecipe.getInfinityBoosterCard; import static com.glodblock.github.util.Util.DimensionalCoordSide.hasEnergyCard; @@ -9,37 +10,38 @@ import java.util.List; import net.minecraft.client.gui.GuiScreen; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumChatFormatting; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; -import net.minecraftforge.event.ForgeEventFactory; import com.glodblock.github.inventory.InventoryHandler; import com.glodblock.github.inventory.gui.GuiType; import com.glodblock.github.inventory.item.IItemInventory; import com.glodblock.github.util.BlockPos; import com.glodblock.github.util.NameConst; +import com.glodblock.github.util.UltraTerminalModes; import appeng.api.AEApi; -import appeng.api.features.ILocatable; import appeng.api.features.IWirelessTermHandler; -import appeng.api.features.IWirelessTermRegistry; -import appeng.core.localization.PlayerMessages; +import appeng.api.implementations.guiobjects.IGuiItem; +import appeng.api.implementations.guiobjects.IGuiItemObject; +import appeng.core.sync.GuiBridge; +import appeng.helpers.WirelessTerminalGuiObject; import appeng.items.tools.powered.ToolWirelessTerminal; import appeng.util.Platform; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -public class ItemBaseWirelessTerminal extends ToolWirelessTerminal implements IItemInventory { +public class ItemBaseWirelessTerminal extends ToolWirelessTerminal implements IItemInventory, IGuiItem { - protected GuiType type; + protected Object type; public static String infinityBoosterCard = "infinityBoosterCard"; public static String infinityEnergyCard = "InfinityEnergyCard"; - public static String restockItems = "restock"; - public ItemBaseWirelessTerminal(GuiType t) { + public ItemBaseWirelessTerminal(Object t) { super(); this.type = t; } @@ -48,40 +50,7 @@ public class ItemBaseWirelessTerminal extends ToolWirelessTerminal implements II public ItemStack onItemRightClick(final ItemStack item, final World w, final EntityPlayer player) { if (player.isSneaking()) return removeInfinityBoosterCard(player, item); // todo: doesn't work in universal // terminal - if (ForgeEventFactory.onItemUseStart(player, item, 1) > 0) { - if (Platform.isClient()) { - return item; - } - IWirelessTermRegistry term = AEApi.instance().registries().wireless(); - if (!term.isWirelessTerminal(item)) { - player.addChatMessage(PlayerMessages.DeviceNotWirelessTerminal.toChat()); - return item; - } - final IWirelessTermHandler handler = term.getWirelessTerminalHandler(item); - final String unparsedKey = handler.getEncryptionKey(item); - if (unparsedKey.isEmpty()) { - player.addChatMessage(PlayerMessages.DeviceNotLinked.toChat()); - return item; - } - final long parsedKey = Long.parseLong(unparsedKey); - final ILocatable securityStation = AEApi.instance().registries().locatable().getLocatableBy(parsedKey); - if (securityStation == null) { - player.addChatMessage(PlayerMessages.StationCanNotBeLocated.toChat()); - return item; - } - if (handler.hasPower(player, 0.5, item)) { - InventoryHandler.openGui( - player, - w, - new BlockPos(player.inventory.currentItem, 0, 0), - ForgeDirection.UNKNOWN, - this.guiGuiType(item)); - } else { - player.addChatMessage(PlayerMessages.DeviceNotPowered.toChat()); - } - } - - return item; + return super.onItemRightClick(item, w, player); } private ItemStack removeInfinityBoosterCard(final EntityPlayer player, ItemStack is) { @@ -117,7 +86,7 @@ public class ItemBaseWirelessTerminal extends ToolWirelessTerminal implements II if (is == null) { return false; } - return is.getItem() instanceof ItemBaseWirelessTerminal; + return is.getItem() == this; } public ItemStack stack() { @@ -129,12 +98,64 @@ public class ItemBaseWirelessTerminal extends ToolWirelessTerminal implements II return null; } - public GuiType guiGuiType(ItemStack stack) { - return this.type; + public static UltraTerminalModes getMode(ItemStack is) { + Item item = is.getItem(); + if (item instanceof ItemWirelessUltraTerminal) { + if (!is.hasTagCompound()) is.setTagCompound(new NBTTagCompound()); + return UltraTerminalModes.values()[is.getTagCompound().getInteger(MODE)]; + } else if (item instanceof ItemWirelessPatternTerminal) { + return UltraTerminalModes.PATTERN; + } else if (item instanceof ItemWirelessInterfaceTerminal) { + return UltraTerminalModes.INTERFACE; + } else if (item instanceof ItemWirelessLevelTerminal) { + return UltraTerminalModes.LEVEL; + } else { + return UltraTerminalModes.INTERFACE; // any wireless gui object will fit + } } - public static void toggleRestockItemsMode(ItemStack is, boolean state) { - NBTTagCompound data = Platform.openNbtData(is); - data.setBoolean(restockItems, state); + public static void setMode(ItemStack is, UltraTerminalModes utm) { + is.getTagCompound().setInteger(MODE, utm.ordinal()); + } + + @Override + public void openGui(final ItemStack is, final World w, final EntityPlayer player, final Object mode) { + final GuiBridge aeGui; + Item item = is.getItem(); + if (item instanceof ItemWirelessPatternTerminal) { + aeGui = GuiBridge.GUI_PATTERN_TERMINAL; + } else if (item instanceof ItemWirelessInterfaceTerminal) { + aeGui = GuiBridge.GUI_INTERFACE_TERMINAL; + } else if (item instanceof ItemWirelessLevelTerminal) { + InventoryHandler.openGui( + player, + w, + new BlockPos(player.inventory.currentItem, 0, 0), + ForgeDirection.UNKNOWN, + GuiType.WIRELESS_LEVEL_TERMINAL); + return; + } else { + aeGui = GuiBridge.GUI_INTERFACE_TERMINAL; // any wireless gui object will fit + } + Platform.openGUI(player, null, null, aeGui); + } + + @Override + public IGuiItemObject getGuiObject(ItemStack is, World world, EntityPlayer p, int x, int y, int z) { + final IWirelessTermHandler wh = AEApi.instance().registries().wireless().getWirelessTerminalHandler(is); + if (wh == null) return null; + return new WirelessTerminalGuiObject(wh, is, p, world, x, y, z); + } + + @Override + public boolean hasInfinityPower(ItemStack is) { + NBTTagCompound data = is.getTagCompound(); + return data != null && data.hasKey(infinityEnergyCard) && data.getBoolean(infinityEnergyCard); + } + + @Override + public boolean hasInfinityRange(ItemStack is) { + NBTTagCompound data = is.getTagCompound(); + return data != null && data.hasKey(infinityBoosterCard) && data.getBoolean(infinityBoosterCard); } } diff --git a/src/main/java/com/glodblock/github/common/item/ItemBasicFluidStorageCell.java b/src/main/java/com/glodblock/github/common/item/ItemBasicFluidStorageCell.java index f7bc8fb0..d9467926 100644 --- a/src/main/java/com/glodblock/github/common/item/ItemBasicFluidStorageCell.java +++ b/src/main/java/com/glodblock/github/common/item/ItemBasicFluidStorageCell.java @@ -4,18 +4,14 @@ import java.util.EnumSet; import java.util.HashMap; import net.minecraft.client.renderer.texture.IIconRegister; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.IIcon; import net.minecraft.util.StatCollector; -import net.minecraft.world.World; -import net.minecraftforge.event.ForgeEventFactory; import com.glodblock.github.FluidCraft; import com.glodblock.github.common.Config; import com.glodblock.github.common.storage.CellType; -import com.glodblock.github.common.storage.IStorageFluidCell; import com.glodblock.github.common.tabs.FluidCraftingTabs; import com.glodblock.github.loader.IRegister; import com.glodblock.github.loader.ItemAndBlockHolder; @@ -23,14 +19,12 @@ import com.glodblock.github.util.NameConst; import com.google.common.base.Optional; import appeng.api.exceptions.MissingDefinition; -import appeng.core.AEConfig; import appeng.core.features.AEFeature; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -public class ItemBasicFluidStorageCell extends FCBaseItemCell - implements IStorageFluidCell, IRegister { +public class ItemBasicFluidStorageCell extends FCBaseItemCell implements IRegister { private static final HashMap icon = new HashMap<>(); private final int housingValue; @@ -114,19 +108,6 @@ public class ItemBasicFluidStorageCell extends FCBaseItemCell return icon.get(id); } - @Override - public ItemStack onItemRightClick(final ItemStack stack, final World world, final EntityPlayer player) { - this.disassembleDrive(stack, world, player); - return stack; - } - - @Override - public boolean onItemUseFirst(final ItemStack stack, final EntityPlayer player, final World world, final int x, - final int y, final int z, final int side, final float hitX, final float hitY, final float hitZ) { - if (ForgeEventFactory.onItemUseStart(player, stack, 1) <= 0) return true; - return this.disassembleDrive(stack, world, player); - } - @Override public ItemStack getContainerItem(final ItemStack itemStack) { if (this.getHousing() != null) { @@ -135,11 +116,6 @@ public class ItemBasicFluidStorageCell extends FCBaseItemCell throw new MissingDefinition("Tried to use empty storage cells while basic storage cells are defined."); } - @Override - public boolean hasContainerItem(final ItemStack stack) { - return AEConfig.instance.isFeatureEnabled(AEFeature.EnableDisassemblyCrafting); - } - @Override public ItemBasicFluidStorageCell register() { if (!Config.fluidCells) return null; diff --git a/src/main/java/com/glodblock/github/common/item/ItemCreativeFluidStorageCell.java b/src/main/java/com/glodblock/github/common/item/ItemCreativeFluidStorageCell.java index b7452e07..4e6d0887 100644 --- a/src/main/java/com/glodblock/github/common/item/ItemCreativeFluidStorageCell.java +++ b/src/main/java/com/glodblock/github/common/item/ItemCreativeFluidStorageCell.java @@ -2,61 +2,47 @@ package com.glodblock.github.common.item; import java.util.EnumSet; -import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import com.glodblock.github.FluidCraft; -import com.glodblock.github.common.storage.IStorageFluidCell; import com.glodblock.github.common.tabs.FluidCraftingTabs; -import com.glodblock.github.inventory.FluidCellConfig; import com.glodblock.github.loader.IRegister; import com.glodblock.github.util.NameConst; -import appeng.api.config.FuzzyMode; +import appeng.api.storage.StorageChannel; import appeng.core.features.AEFeature; -import appeng.util.Platform; +import appeng.items.AEBaseInfiniteCell; import cpw.mods.fml.common.registry.GameRegistry; -public class ItemCreativeFluidStorageCell extends ItemBaseInfinityStorageCell - implements IStorageFluidCell, IRegister { +public class ItemCreativeFluidStorageCell extends AEBaseInfiniteCell + implements IRegister { public ItemCreativeFluidStorageCell() { - super(); setUnlocalizedName(NameConst.ITEM_CREATIVE_FLUID_STORAGE); setTextureName(FluidCraft.resource(NameConst.ITEM_CREATIVE_FLUID_STORAGE).toString()); this.setFeature(EnumSet.of(AEFeature.StorageCells)); this.setMaxStackSize(1); } - @Override - public IInventory getConfigInventory(ItemStack is) { - return new FluidCellConfig(is); - } - - @Override - public FuzzyMode getFuzzyMode(ItemStack is) { - final String fz = Platform.openNbtData(is).getString("FuzzyMode"); - try { - return FuzzyMode.valueOf(fz); - } catch (final Throwable t) { - return FuzzyMode.IGNORE_ALL; - } - } - - @Override - public boolean isEditable(ItemStack is) { - return true; - } - - @Override - public void setFuzzyMode(ItemStack is, FuzzyMode fzMode) { - Platform.openNbtData(is).setString("FuzzyMode", fzMode.name()); - } - @Override public ItemCreativeFluidStorageCell register() { GameRegistry.registerItem(this, NameConst.ITEM_CREATIVE_FLUID_STORAGE, FluidCraft.MODID); setCreativeTab(FluidCraftingTabs.INSTANCE); return this; } + + @Override + public boolean isEditable(ItemStack is) { + return true; + } + + @Override + public int getTotalTypes(ItemStack cellItem) { + return 63; + } + + @Override + public StorageChannel getStorageChannel() { + return StorageChannel.FLUIDS; + } } diff --git a/src/main/java/com/glodblock/github/common/item/ItemFluidExtremeStorageCell.java b/src/main/java/com/glodblock/github/common/item/ItemFluidExtremeStorageCell.java index c3483675..f96487b9 100644 --- a/src/main/java/com/glodblock/github/common/item/ItemFluidExtremeStorageCell.java +++ b/src/main/java/com/glodblock/github/common/item/ItemFluidExtremeStorageCell.java @@ -1,24 +1,27 @@ package com.glodblock.github.common.item; +import java.util.EnumSet; + import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.world.World; import com.glodblock.github.FluidCraft; import com.glodblock.github.common.Config; -import com.glodblock.github.common.storage.IStorageFluidCell; import com.glodblock.github.common.tabs.FluidCraftingTabs; import com.glodblock.github.loader.IRegister; +import appeng.core.features.AEFeature; import cpw.mods.fml.common.registry.GameRegistry; -public class ItemFluidExtremeStorageCell extends FCBaseItemCell - implements IStorageFluidCell, IRegister { +public class ItemFluidExtremeStorageCell extends FCBaseItemCell implements IRegister { private final String name; public ItemFluidExtremeStorageCell(String name, long bytes, int perType, int totalTypes, double drain) { super(bytes, perType, totalTypes, drain); + this.setFeature(EnumSet.of(AEFeature.StorageCells)); + this.setMaxStackSize(1); setUnlocalizedName(name); this.name = name; setTextureName(FluidCraft.resource(name).toString()); diff --git a/src/main/java/com/glodblock/github/common/item/ItemFluidLevelEmitter.java b/src/main/java/com/glodblock/github/common/item/ItemFluidLevelEmitter.java index 72004215..96191d21 100644 --- a/src/main/java/com/glodblock/github/common/item/ItemFluidLevelEmitter.java +++ b/src/main/java/com/glodblock/github/common/item/ItemFluidLevelEmitter.java @@ -1,5 +1,7 @@ package com.glodblock.github.common.item; +import java.util.List; + import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.util.IIcon; @@ -57,4 +59,11 @@ public class ItemFluidLevelEmitter extends FCBaseItem implements IPartItem { public int getSpriteNumber() { return 0; } + + @Override + public void addInformation(final ItemStack stack, final EntityPlayer player, final List lines, + final boolean displayMoreInfo) { + lines.add("Deprecated, use regular level emitter, hold CTRL for get fluid of container."); + super.addInformation(stack, player, lines, displayMoreInfo); + } } diff --git a/src/main/java/com/glodblock/github/common/item/ItemFluidVoidStorageCell.java b/src/main/java/com/glodblock/github/common/item/ItemFluidVoidStorageCell.java index 9994bbfa..599630dd 100644 --- a/src/main/java/com/glodblock/github/common/item/ItemFluidVoidStorageCell.java +++ b/src/main/java/com/glodblock/github/common/item/ItemFluidVoidStorageCell.java @@ -1,44 +1,20 @@ package com.glodblock.github.common.item; -import java.util.EnumSet; -import java.util.List; - -import net.minecraft.client.gui.GuiScreen; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; - import com.glodblock.github.FluidCraft; -import com.glodblock.github.api.FluidCraftAPI; -import com.glodblock.github.common.storage.IFluidCellInventory; -import com.glodblock.github.common.storage.IFluidCellInventoryHandler; -import com.glodblock.github.common.storage.IStorageFluidCell; import com.glodblock.github.common.tabs.FluidCraftingTabs; -import com.glodblock.github.inventory.FluidCellConfig; import com.glodblock.github.loader.IRegister; import com.glodblock.github.util.NameConst; -import appeng.api.AEApi; -import appeng.api.config.FuzzyMode; -import appeng.api.storage.IMEInventoryHandler; import appeng.api.storage.StorageChannel; -import appeng.api.storage.data.IAEFluidStack; -import appeng.core.features.AEFeature; -import appeng.core.localization.GuiText; -import appeng.items.AEBaseItem; -import appeng.items.contents.CellUpgrades; -import appeng.util.Platform; +import appeng.items.storage.ItemVoidStorageCell; import cpw.mods.fml.common.registry.GameRegistry; -public class ItemFluidVoidStorageCell extends AEBaseItem - implements IStorageFluidCell, IRegister { +public class ItemFluidVoidStorageCell extends ItemVoidStorageCell implements IRegister { public ItemFluidVoidStorageCell() { super(); setUnlocalizedName(NameConst.ITEM_FLUID_VOID_CELL); setTextureName(FluidCraft.resource(NameConst.ITEM_FLUID_VOID_CELL).toString()); - this.setFeature(EnumSet.of(AEFeature.StorageCells)); - this.setMaxStackSize(1); } @Override @@ -49,88 +25,7 @@ public class ItemFluidVoidStorageCell extends AEBaseItem } @Override - public void addCheckedInformation(final ItemStack stack, final EntityPlayer player, final List lines, - final boolean displayMoreInfo) { - final IMEInventoryHandler inventory = AEApi.instance().registries().cell() - .getCellInventory(stack, null, StorageChannel.FLUIDS); - if (inventory instanceof final IFluidCellInventoryHandler handler) { - lines.add(NameConst.i18n(NameConst.TT_ITEM_FLUID_VOID_CELL)); - lines.add(GuiText.VoidCellTooltip.getLocal()); - lines.add(0 + " " + GuiText.Of.getLocal() + " \u00A7k9999\u00A77 " + GuiText.BytesUsed.getLocal()); - final IFluidCellInventory inv = handler.getCellInv(); - if (GuiScreen.isShiftKeyDown()) { - lines.add(GuiText.Filter.getLocal() + ": "); - for (int i = 0; i < inv.getConfigInventory().getSizeInventory(); ++i) { - ItemStack s = inv.getConfigInventory().getStackInSlot(i); - if (s != null) lines.add(s.getDisplayName()); - } - } - } - } - - @Override - public long getBytes(ItemStack cellItem) { - return 0; - } - - @Override - public int getBytesPerType(ItemStack cellItem) { - return 0; - } - - @Override - public boolean isBlackListed(ItemStack cellItem, IAEFluidStack requestedAddition) { - return requestedAddition == null || requestedAddition.getFluid() == null - || FluidCraftAPI.instance().isBlacklistedInStorage(requestedAddition.getFluid().getClass()); - } - - @Override - public boolean storableInStorageCell() { - return true; - } - - @Override - public boolean isStorageCell(ItemStack i) { - return true; - } - - @Override - public double getIdleDrain(ItemStack is) { - return 0; - } - - @Override - public int getTotalTypes(ItemStack cellItem) { - return 0; - } - - @Override - public boolean isEditable(ItemStack is) { - return true; - } - - @Override - public IInventory getUpgradesInventory(ItemStack is) { - return new CellUpgrades(is, 5); - } - - @Override - public IInventory getConfigInventory(ItemStack is) { - return new FluidCellConfig(is); - } - - @Override - public FuzzyMode getFuzzyMode(ItemStack is) { - final String fz = Platform.openNbtData(is).getString("FuzzyMode"); - try { - return FuzzyMode.valueOf(fz); - } catch (final Throwable t) { - return FuzzyMode.IGNORE_ALL; - } - } - - @Override - public void setFuzzyMode(ItemStack is, FuzzyMode fzMode) { - Platform.openNbtData(is).setString("FuzzyMode", fzMode.name()); + public StorageChannel getStorageChannel() { + return StorageChannel.FLUIDS; } } diff --git a/src/main/java/com/glodblock/github/common/item/ItemInfinityWaterStorageCell.java b/src/main/java/com/glodblock/github/common/item/ItemInfinityWaterStorageCell.java index 3ae218b1..f0646c9e 100644 --- a/src/main/java/com/glodblock/github/common/item/ItemInfinityWaterStorageCell.java +++ b/src/main/java/com/glodblock/github/common/item/ItemInfinityWaterStorageCell.java @@ -4,33 +4,28 @@ import static com.glodblock.github.util.Util.FluidUtil.water_bucket; import java.util.EnumSet; -import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import com.glodblock.github.FluidCraft; -import com.glodblock.github.common.storage.IStorageFluidCell; import com.glodblock.github.common.tabs.FluidCraftingTabs; import com.glodblock.github.loader.IRegister; import com.glodblock.github.util.NameConst; +import com.glodblock.github.util.Util; -import appeng.api.config.FuzzyMode; +import appeng.api.storage.StorageChannel; import appeng.core.features.AEFeature; -import appeng.tile.inventory.AppEngInternalInventory; +import appeng.items.AEBaseInfiniteCell; +import appeng.tile.inventory.IAEStackInventory; import cpw.mods.fml.common.registry.GameRegistry; -public class ItemInfinityWaterStorageCell extends ItemBaseInfinityStorageCell - implements IStorageFluidCell, IRegister { +public class ItemInfinityWaterStorageCell extends AEBaseInfiniteCell + implements IRegister { - @Override - public IInventory getConfigInventory(ItemStack is) { - return new InfinityConfig(water_bucket); - } - - public static class InfinityConfig extends AppEngInternalInventory { + public static class InfinityConfig extends IAEStackInventory { public InfinityConfig(final ItemStack is) { super(null, 1); - this.setInventorySlotContents(0, is); + this.putAEStackInSlot(0, Util.getAEFluidFromItem(is)); } @Override @@ -38,7 +33,6 @@ public class ItemInfinityWaterStorageCell extends ItemBaseInfinityStorageCell } public ItemInfinityWaterStorageCell() { - super(); setUnlocalizedName(NameConst.ITEM_INFINITY_WATER_FLUID_STORAGE); setTextureName(FluidCraft.resource(NameConst.ITEM_INFINITY_FLUID_STORAGE).toString()); this.setFeature(EnumSet.of(AEFeature.StorageCells)); @@ -52,17 +46,23 @@ public class ItemInfinityWaterStorageCell extends ItemBaseInfinityStorageCell return this; } + @Override + public IAEStackInventory getConfigAEInventory(ItemStack is) { + return new InfinityConfig(water_bucket); + } + @Override public boolean isEditable(ItemStack is) { return false; } @Override - public FuzzyMode getFuzzyMode(ItemStack is) { - return FuzzyMode.IGNORE_ALL; + public int getTotalTypes(ItemStack cellItem) { + return 1; } @Override - public void setFuzzyMode(ItemStack is, FuzzyMode fzMode) {} - + public StorageChannel getStorageChannel() { + return StorageChannel.FLUIDS; + } } diff --git a/src/main/java/com/glodblock/github/common/item/ItemMultiFluidStorageCell.java b/src/main/java/com/glodblock/github/common/item/ItemMultiFluidStorageCell.java index 73c9ab81..f48648c3 100644 --- a/src/main/java/com/glodblock/github/common/item/ItemMultiFluidStorageCell.java +++ b/src/main/java/com/glodblock/github/common/item/ItemMultiFluidStorageCell.java @@ -4,18 +4,14 @@ import java.util.EnumSet; import java.util.HashMap; import net.minecraft.client.renderer.texture.IIconRegister; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.IIcon; import net.minecraft.util.StatCollector; -import net.minecraft.world.World; -import net.minecraftforge.event.ForgeEventFactory; import com.glodblock.github.FluidCraft; import com.glodblock.github.common.Config; import com.glodblock.github.common.storage.CellType; -import com.glodblock.github.common.storage.IStorageFluidCell; import com.glodblock.github.common.tabs.FluidCraftingTabs; import com.glodblock.github.loader.IRegister; import com.glodblock.github.loader.ItemAndBlockHolder; @@ -23,14 +19,12 @@ import com.glodblock.github.util.NameConst; import com.google.common.base.Optional; import appeng.api.exceptions.MissingDefinition; -import appeng.core.AEConfig; import appeng.core.features.AEFeature; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -public class ItemMultiFluidStorageCell extends FCBaseItemCell - implements IStorageFluidCell, IRegister { +public class ItemMultiFluidStorageCell extends FCBaseItemCell implements IRegister { private static final HashMap icon = new HashMap<>(); private final int housingValue; @@ -43,7 +37,7 @@ public class ItemMultiFluidStorageCell extends FCBaseItemCell this.totalBytes = kilobytes * 1024; this.component = whichCell; this.housingValue = housingValue; - this.maxType = 5; + this.totalTypes = 5; setUnlocalizedName(NameConst.ITEM_MULTI_FLUID_STORAGE + "." + kilobytes); switch (this.component) { @@ -115,24 +109,6 @@ public class ItemMultiFluidStorageCell extends FCBaseItemCell return icon.get(id); } - @Override - public ItemStack onItemRightClick(final ItemStack stack, final World world, final EntityPlayer player) { - this.disassembleDrive(stack, world, player); - return stack; - } - - @Override - public boolean onItemUseFirst(final ItemStack stack, final EntityPlayer player, final World world, final int x, - final int y, final int z, final int side, final float hitX, final float hitY, final float hitZ) { - if (ForgeEventFactory.onItemUseStart(player, stack, 1) <= 0) return true; - return this.disassembleDrive(stack, world, player); - } - - @Override - public boolean hasContainerItem(final ItemStack stack) { - return AEConfig.instance.isFeatureEnabled(AEFeature.EnableDisassemblyCrafting); - } - @Override public ItemStack getContainerItem(final ItemStack itemStack) { if (this.getHousing() != null) { diff --git a/src/main/java/com/glodblock/github/common/item/ItemPartFluidInterface.java b/src/main/java/com/glodblock/github/common/item/ItemPartFluidInterface.java index c2ce3747..c393c492 100644 --- a/src/main/java/com/glodblock/github/common/item/ItemPartFluidInterface.java +++ b/src/main/java/com/glodblock/github/common/item/ItemPartFluidInterface.java @@ -2,7 +2,6 @@ package com.glodblock.github.common.item; import javax.annotation.Nullable; -import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.world.World; @@ -46,7 +45,9 @@ public class ItemPartFluidInterface extends FCBaseItem implements IPartItem { } @Override - public void registerIcons(IIconRegister _iconRegister) {} + protected String getIconString() { + return NameConst.RES_KEY + "fluid_interface"; + } @Override @SideOnly(Side.CLIENT) diff --git a/src/main/java/com/glodblock/github/common/item/ItemPartFluidPatternTerminal.java b/src/main/java/com/glodblock/github/common/item/ItemPartFluidPatternTerminal.java index af64379f..e17bba5d 100644 --- a/src/main/java/com/glodblock/github/common/item/ItemPartFluidPatternTerminal.java +++ b/src/main/java/com/glodblock/github/common/item/ItemPartFluidPatternTerminal.java @@ -1,5 +1,7 @@ package com.glodblock.github.common.item; +import java.util.List; + import javax.annotation.Nullable; import net.minecraft.client.renderer.texture.IIconRegister; @@ -53,4 +55,10 @@ public class ItemPartFluidPatternTerminal extends FCBaseItem implements IPartIte public int getSpriteNumber() { return 0; } + + @Override + @SideOnly(Side.CLIENT) + public void addInformation(ItemStack stack, EntityPlayer player, List toolTip, boolean flag) { + toolTip.add("DEPRECATED!"); + } } diff --git a/src/main/java/com/glodblock/github/common/item/ItemPartFluidPatternTerminalEx.java b/src/main/java/com/glodblock/github/common/item/ItemPartFluidPatternTerminalEx.java index cd458725..06088ccf 100644 --- a/src/main/java/com/glodblock/github/common/item/ItemPartFluidPatternTerminalEx.java +++ b/src/main/java/com/glodblock/github/common/item/ItemPartFluidPatternTerminalEx.java @@ -1,5 +1,7 @@ package com.glodblock.github.common.item; +import java.util.List; + import javax.annotation.Nullable; import net.minecraft.client.renderer.texture.IIconRegister; @@ -53,4 +55,10 @@ public class ItemPartFluidPatternTerminalEx extends FCBaseItem implements IPartI public int getSpriteNumber() { return 0; } + + @Override + @SideOnly(Side.CLIENT) + public void addInformation(ItemStack stack, EntityPlayer player, List toolTip, boolean flag) { + toolTip.add("DEPRECATED!"); + } } diff --git a/src/main/java/com/glodblock/github/common/item/ItemPartFluidStorageBus.java b/src/main/java/com/glodblock/github/common/item/ItemPartFluidStorageBus.java index 194e2b55..b1585a4a 100644 --- a/src/main/java/com/glodblock/github/common/item/ItemPartFluidStorageBus.java +++ b/src/main/java/com/glodblock/github/common/item/ItemPartFluidStorageBus.java @@ -2,7 +2,6 @@ package com.glodblock.github.common.item; import javax.annotation.Nullable; -import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.world.World; @@ -46,7 +45,9 @@ public class ItemPartFluidStorageBus extends FCBaseItem implements IPartItem { } @Override - public void registerIcons(IIconRegister _iconRegister) {} + protected String getIconString() { + return NameConst.RES_KEY + "fluid_storage_bus"; + } @Override @SideOnly(Side.CLIENT) diff --git a/src/main/java/com/glodblock/github/common/item/ItemPartFluidTerminal.java b/src/main/java/com/glodblock/github/common/item/ItemPartFluidTerminal.java index c966c465..c8be0ba6 100644 --- a/src/main/java/com/glodblock/github/common/item/ItemPartFluidTerminal.java +++ b/src/main/java/com/glodblock/github/common/item/ItemPartFluidTerminal.java @@ -45,6 +45,7 @@ public class ItemPartFluidTerminal extends FCBaseItem implements IPartItem { @Override @SideOnly(Side.CLIENT) public void addInformation(ItemStack stack, EntityPlayer player, List toolTip, boolean flag) { + toolTip.add("DEPRECATED!"); if (isShiftKeyDown()) { toolTip.add(NameConst.i18n(NameConst.TT_FLUID_TERMINAL)); } else { @@ -67,4 +68,5 @@ public class ItemPartFluidTerminal extends FCBaseItem implements IPartItem { public int getSpriteNumber() { return 0; } + } diff --git a/src/main/java/com/glodblock/github/common/item/ItemPortableFluidCell.java b/src/main/java/com/glodblock/github/common/item/ItemPortableFluidCell.java index 6cec6095..0dc7863e 100644 --- a/src/main/java/com/glodblock/github/common/item/ItemPortableFluidCell.java +++ b/src/main/java/com/glodblock/github/common/item/ItemPortableFluidCell.java @@ -1,75 +1,38 @@ package com.glodblock.github.common.item; -import java.text.NumberFormat; -import java.util.EnumSet; import java.util.List; import net.minecraft.client.gui.GuiScreen; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; -import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.StatCollector; import net.minecraft.world.World; -import net.minecraftforge.common.util.ForgeDirection; import com.glodblock.github.FluidCraft; import com.glodblock.github.api.FluidCraftAPI; -import com.glodblock.github.common.Config; -import com.glodblock.github.common.storage.IFluidCellInventory; -import com.glodblock.github.common.storage.IFluidCellInventoryHandler; -import com.glodblock.github.common.storage.IStorageFluidCell; import com.glodblock.github.common.tabs.FluidCraftingTabs; -import com.glodblock.github.inventory.FluidCellConfig; -import com.glodblock.github.inventory.InventoryHandler; -import com.glodblock.github.inventory.gui.GuiType; -import com.glodblock.github.inventory.item.IItemInventory; -import com.glodblock.github.inventory.item.PortableFluidCellInventory; import com.glodblock.github.loader.IRegister; -import com.glodblock.github.util.BlockPos; import com.glodblock.github.util.NameConst; import com.glodblock.github.util.RenderUtil; -import com.google.common.base.Optional; -import appeng.api.AEApi; -import appeng.api.config.FuzzyMode; -import appeng.api.storage.IMEInventoryHandler; +import appeng.api.implementations.guiobjects.IGuiItemObject; import appeng.api.storage.StorageChannel; import appeng.api.storage.data.IAEFluidStack; -import appeng.core.features.AEFeature; -import appeng.core.localization.GuiText; +import appeng.api.storage.data.IAEStack; +import appeng.items.AEBasePortableCell; import appeng.items.contents.CellUpgrades; -import appeng.items.tools.powered.powersink.AEBasePoweredItem; -import appeng.util.Platform; +import appeng.items.contents.PortableCellViewer; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -public class ItemPortableFluidCell extends AEBasePoweredItem - implements IStorageFluidCell, IItemInventory, IRegister { +public class ItemPortableFluidCell extends AEBasePortableCell implements IRegister { public ItemPortableFluidCell() { - super(Config.portableCellBattery, Optional.absent()); + super(); setUnlocalizedName(NameConst.ITEM_FLUID_PORTABLE_CELL); setTextureName(FluidCraft.resource(NameConst.ITEM_FLUID_PORTABLE_CELL).toString()); - this.setFeature(EnumSet.of(AEFeature.PortableCell, AEFeature.StorageCells, AEFeature.PoweredTools)); - } - - @Override - public ItemStack onItemRightClick(final ItemStack item, final World w, final EntityPlayer player) { - InventoryHandler.openGui( - player, - w, - new BlockPos(player.inventory.currentItem, 0, 0), - ForgeDirection.UNKNOWN, - GuiType.PORTABLE_FLUID_CELL); - return item; - } - - @SideOnly(Side.CLIENT) - @Override - public boolean isFull3D() { - return false; } @SideOnly(Side.CLIENT) @@ -77,35 +40,6 @@ public class ItemPortableFluidCell extends AEBasePoweredItem public void addCheckedInformation(final ItemStack stack, final EntityPlayer player, final List lines, final boolean displayMoreInfo) { super.addCheckedInformation(stack, player, lines, displayMoreInfo); - final IMEInventoryHandler inventory = AEApi.instance().registries().cell() - .getCellInventory(stack, null, StorageChannel.FLUIDS); - if (inventory instanceof final IFluidCellInventoryHandler handler) { - final IFluidCellInventory cellInventory = handler.getCellInv(); - if (cellInventory != null) { - lines.add( - EnumChatFormatting.WHITE + NumberFormat.getInstance().format(cellInventory.getUsedBytes()) - + EnumChatFormatting.GRAY - + " " - + GuiText.Of.getLocal() - + " " - + EnumChatFormatting.DARK_GREEN - + cellInventory.getTotalBytes() - + " " - + EnumChatFormatting.GRAY - + GuiText.BytesUsed.getLocal()); - lines.add( - EnumChatFormatting.WHITE + NumberFormat.getInstance().format(cellInventory.getStoredFluidTypes()) - + EnumChatFormatting.GRAY - + " " - + GuiText.Of.getLocal() - + " " - + EnumChatFormatting.DARK_GREEN - + cellInventory.getTotalFluidTypes() - + " " - + EnumChatFormatting.GRAY - + GuiText.Types.getLocal()); - } - } if (GuiScreen.isShiftKeyDown()) { lines.addAll( RenderUtil.listFormattedStringToWidth( @@ -116,34 +50,20 @@ public class ItemPortableFluidCell extends AEBasePoweredItem } @Override - public long getBytes(final ItemStack cellItem) { + public long getBytesLong(final ItemStack cellItem) { return 256; } - @Override - public int getBytesPerType(final ItemStack cellItem) { - return 8; - } - @Override public int getTotalTypes(final ItemStack cellItem) { return 5; } @Override - public boolean isBlackListed(ItemStack cellItem, IAEFluidStack requestedAddition) { - return requestedAddition == null || requestedAddition.getFluid() == null - || FluidCraftAPI.instance().isBlacklistedInStorage(requestedAddition.getFluid().getClass()); - } + public boolean isBlackListed(IAEStack requestedAddition) { - @Override - public boolean storableInStorageCell() { - return false; - } - - @Override - public boolean isStorageCell(final ItemStack i) { - return true; + return requestedAddition instanceof IAEFluidStack ifs && (ifs.getFluid() == null + || FluidCraftAPI.instance().isBlacklistedInStorage(ifs.getFluid().getClass())); } @Override @@ -151,34 +71,20 @@ public class ItemPortableFluidCell extends AEBasePoweredItem return 0.5; } - @Override - public boolean isEditable(final ItemStack is) { - return true; - } - @Override public IInventory getUpgradesInventory(final ItemStack is) { return new CellUpgrades(is, 0); } @Override - public IInventory getConfigInventory(final ItemStack is) { - return new FluidCellConfig(is); + public IGuiItemObject getGuiObject(final ItemStack is, final World w, final EntityPlayer p, final int x, + final int y, final int z) { + return new PortableCellViewer(is, x, StorageChannel.FLUIDS); } @Override - public FuzzyMode getFuzzyMode(final ItemStack is) { - final String fz = Platform.openNbtData(is).getString("FuzzyMode"); - try { - return FuzzyMode.valueOf(fz); - } catch (final Throwable t) { - return FuzzyMode.IGNORE_ALL; - } - } - - @Override - public void setFuzzyMode(final ItemStack is, final FuzzyMode fzMode) { - Platform.openNbtData(is).setString("FuzzyMode", fzMode.name()); + public StorageChannel getStorageChannel() { + return StorageChannel.FLUIDS; } @Override @@ -188,11 +94,6 @@ public class ItemPortableFluidCell extends AEBasePoweredItem return this; } - @Override - public Object getInventory(ItemStack stack, World world, int x, int y, int z, EntityPlayer player) { - return new PortableFluidCellInventory(stack, x); - } - public ItemStack stack() { return new ItemStack(this, 1); } diff --git a/src/main/java/com/glodblock/github/common/item/ItemWirelessFluidTerminal.java b/src/main/java/com/glodblock/github/common/item/ItemWirelessFluidTerminal.java index cc2a1348..ef8e64c6 100644 --- a/src/main/java/com/glodblock/github/common/item/ItemWirelessFluidTerminal.java +++ b/src/main/java/com/glodblock/github/common/item/ItemWirelessFluidTerminal.java @@ -8,23 +8,18 @@ import net.minecraft.world.World; import com.glodblock.github.FluidCraft; import com.glodblock.github.common.tabs.FluidCraftingTabs; -import com.glodblock.github.inventory.gui.GuiType; -import com.glodblock.github.inventory.item.WirelessFluidTerminalInventory; import com.glodblock.github.loader.IRegister; import com.glodblock.github.util.NameConst; -import com.glodblock.github.util.Util; import appeng.api.AEApi; -import appeng.api.networking.IGridNode; import appeng.core.features.AEFeature; -import appeng.core.localization.PlayerMessages; import cpw.mods.fml.common.registry.GameRegistry; public class ItemWirelessFluidTerminal extends ItemBaseWirelessTerminal implements IRegister { public ItemWirelessFluidTerminal() { - super(GuiType.WIRELESS_FLUID_TERMINAL); + super(null); AEApi.instance().registries().wireless().registerWirelessHandler(this); this.setFeature(EnumSet.of(AEFeature.WirelessAccessTerminal, AEFeature.PoweredTools)); setUnlocalizedName(NameConst.ITEM_WIRELESS_FLUID_TERMINAL); @@ -40,12 +35,6 @@ public class ItemWirelessFluidTerminal extends ItemBaseWirelessTerminal @Override public Object getInventory(ItemStack stack, World world, int x, int y, int z, EntityPlayer player) { - try { - IGridNode gridNode = Util.getWirelessGrid(stack); - return new WirelessFluidTerminalInventory(stack, x, gridNode, player); - } catch (Exception e) { - player.addChatMessage(PlayerMessages.OutOfRange.toChat()); - } return null; } diff --git a/src/main/java/com/glodblock/github/common/item/ItemWirelessInterfaceTerminal.java b/src/main/java/com/glodblock/github/common/item/ItemWirelessInterfaceTerminal.java index 4b159406..89746041 100644 --- a/src/main/java/com/glodblock/github/common/item/ItemWirelessInterfaceTerminal.java +++ b/src/main/java/com/glodblock/github/common/item/ItemWirelessInterfaceTerminal.java @@ -8,23 +8,22 @@ import net.minecraft.world.World; import com.glodblock.github.FluidCraft; import com.glodblock.github.common.tabs.FluidCraftingTabs; -import com.glodblock.github.inventory.gui.GuiType; -import com.glodblock.github.inventory.item.WirelessInterfaceTerminalInventory; import com.glodblock.github.loader.IRegister; import com.glodblock.github.util.NameConst; -import com.glodblock.github.util.Util; import appeng.api.AEApi; -import appeng.api.networking.IGridNode; +import appeng.api.features.IWirelessTermHandler; +import appeng.api.implementations.guiobjects.IGuiItemObject; import appeng.core.features.AEFeature; -import appeng.core.localization.PlayerMessages; +import appeng.core.sync.GuiBridge; +import appeng.items.contents.WirelessInterfaceTerminalGuiObject; import cpw.mods.fml.common.registry.GameRegistry; public class ItemWirelessInterfaceTerminal extends ItemBaseWirelessTerminal implements IRegister { public ItemWirelessInterfaceTerminal() { - super(GuiType.WIRELESS_INTERFACE_TERMINAL); + super(GuiBridge.GUI_INTERFACE_TERMINAL); AEApi.instance().registries().wireless().registerWirelessHandler(this); this.setFeature(EnumSet.of(AEFeature.WirelessAccessTerminal, AEFeature.PoweredTools)); setUnlocalizedName(NameConst.ITEM_WIRELESS_INTERFACE_TERMINAL); @@ -39,13 +38,9 @@ public class ItemWirelessInterfaceTerminal extends ItemBaseWirelessTerminal } @Override - public Object getInventory(ItemStack stack, World world, int x, int y, int z, EntityPlayer player) { - try { - IGridNode gridNode = Util.getWirelessGrid(stack); - return new WirelessInterfaceTerminalInventory(stack, x, gridNode, player); - } catch (Exception e) { - player.addChatMessage(PlayerMessages.OutOfRange.toChat()); - } - return null; + public IGuiItemObject getGuiObject(ItemStack is, World world, EntityPlayer p, int x, int y, int z) { + final IWirelessTermHandler wh = AEApi.instance().registries().wireless().getWirelessTerminalHandler(is); + if (wh == null) return null; + return new WirelessInterfaceTerminalGuiObject(wh, is, x); } } diff --git a/src/main/java/com/glodblock/github/common/item/ItemWirelessPatternTerminal.java b/src/main/java/com/glodblock/github/common/item/ItemWirelessPatternTerminal.java index 28b50edd..bec3a22f 100644 --- a/src/main/java/com/glodblock/github/common/item/ItemWirelessPatternTerminal.java +++ b/src/main/java/com/glodblock/github/common/item/ItemWirelessPatternTerminal.java @@ -8,23 +8,22 @@ import net.minecraft.world.World; import com.glodblock.github.FluidCraft; import com.glodblock.github.common.tabs.FluidCraftingTabs; -import com.glodblock.github.inventory.gui.GuiType; -import com.glodblock.github.inventory.item.WirelessPatternTerminalInventory; import com.glodblock.github.loader.IRegister; import com.glodblock.github.util.NameConst; -import com.glodblock.github.util.Util; import appeng.api.AEApi; -import appeng.api.networking.IGridNode; +import appeng.api.features.IWirelessTermHandler; +import appeng.api.implementations.guiobjects.IGuiItemObject; import appeng.core.features.AEFeature; -import appeng.core.localization.PlayerMessages; +import appeng.core.sync.GuiBridge; +import appeng.items.contents.WirelessPatternTerminalGuiObject; import cpw.mods.fml.common.registry.GameRegistry; public class ItemWirelessPatternTerminal extends ItemBaseWirelessTerminal implements IRegister { public ItemWirelessPatternTerminal() { - super(GuiType.WIRELESS_FLUID_PATTERN_TERMINAL); + super(GuiBridge.GUI_PATTERN_TERMINAL); AEApi.instance().registries().wireless().registerWirelessHandler(this); this.setFeature(EnumSet.of(AEFeature.WirelessAccessTerminal, AEFeature.PoweredTools)); setUnlocalizedName(NameConst.ITEM_WIRELESS_FLUID_PATTERN_TERMINAL); @@ -39,13 +38,9 @@ public class ItemWirelessPatternTerminal extends ItemBaseWirelessTerminal } @Override - public Object getInventory(ItemStack stack, World world, int x, int y, int z, EntityPlayer player) { - try { - IGridNode gridNode = Util.getWirelessGrid(stack); - return new WirelessPatternTerminalInventory(stack, x, gridNode, player); - } catch (Exception e) { - player.addChatMessage(PlayerMessages.OutOfRange.toChat()); - } - return null; + public IGuiItemObject getGuiObject(ItemStack is, World world, EntityPlayer p, int x, int y, int z) { + final IWirelessTermHandler wh = AEApi.instance().registries().wireless().getWirelessTerminalHandler(is); + if (wh == null) return null; + return new WirelessPatternTerminalGuiObject(wh, is, p, world, x, y, z); } } diff --git a/src/main/java/com/glodblock/github/common/item/ItemWirelessUltraTerminal.java b/src/main/java/com/glodblock/github/common/item/ItemWirelessUltraTerminal.java index 70c3bc9a..37791e41 100644 --- a/src/main/java/com/glodblock/github/common/item/ItemWirelessUltraTerminal.java +++ b/src/main/java/com/glodblock/github/common/item/ItemWirelessUltraTerminal.java @@ -1,8 +1,10 @@ package com.glodblock.github.common.item; +import static appeng.util.Platform.baublesSlotsOffset; +import static appeng.util.Platform.nextEnum; +import static com.glodblock.github.util.Util.GuiHelper.decodeInvType; import static net.minecraft.client.gui.GuiScreen.isShiftKeyDown; -import java.util.ArrayList; import java.util.Arrays; import java.util.EnumSet; import java.util.List; @@ -12,7 +14,6 @@ import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.StatCollector; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; @@ -20,43 +21,44 @@ import net.minecraftforge.common.util.ForgeDirection; import org.apache.commons.lang3.tuple.ImmutablePair; import com.glodblock.github.FluidCraft; +import com.glodblock.github.client.UltraTerminalButtons; import com.glodblock.github.common.tabs.FluidCraftingTabs; import com.glodblock.github.inventory.InventoryHandler; import com.glodblock.github.inventory.gui.GuiType; -import com.glodblock.github.inventory.item.WirelessCraftingTerminalInventory; -import com.glodblock.github.inventory.item.WirelessFluidTerminalInventory; -import com.glodblock.github.inventory.item.WirelessInterfaceTerminalInventory; import com.glodblock.github.inventory.item.WirelessLevelTerminalInventory; import com.glodblock.github.inventory.item.WirelessMagnet; import com.glodblock.github.inventory.item.WirelessMagnetCardFilterInventory; -import com.glodblock.github.inventory.item.WirelessPatternTerminalExInventory; -import com.glodblock.github.inventory.item.WirelessPatternTerminalInventory; import com.glodblock.github.loader.IRegister; -import com.glodblock.github.network.CPacketSwitchGuis; import com.glodblock.github.util.BlockPos; -import com.glodblock.github.util.ModAndClassUtil; import com.glodblock.github.util.NameConst; +import com.glodblock.github.util.UltraTerminalModes; import com.glodblock.github.util.Util; import appeng.api.AEApi; +import appeng.api.features.IWirelessTermHandler; +import appeng.api.implementations.guiobjects.IGuiItem; +import appeng.api.implementations.guiobjects.IGuiItemObject; import appeng.api.networking.IGridNode; +import appeng.container.AEBaseContainer; import appeng.core.features.AEFeature; import appeng.core.localization.PlayerMessages; +import appeng.core.sync.GuiBridge; +import appeng.helpers.ICustomButtonDataObject; +import appeng.helpers.ICustomButtonProvider; +import appeng.helpers.ICustomButtonSource; +import appeng.items.contents.WirelessCraftingTerminalGuiObject; +import appeng.items.contents.WirelessInterfaceTerminalGuiObject; +import appeng.items.contents.WirelessPatternTerminalGuiObject; import appeng.util.Platform; -import baubles.api.BaubleType; import baubles.api.BaublesApi; -import baubles.api.IBauble; -import cpw.mods.fml.common.Optional; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -@Optional.Interface(iface = "baubles.api.IBauble", modid = "Baubles") public class ItemWirelessUltraTerminal extends ItemBaseWirelessTerminal - implements IBauble, IRegister { + implements IRegister, IGuiItem, ICustomButtonSource { - public final static String MODE = "mode_main"; - private final static List guis = new ArrayList<>(); + public final static String MODE = "mode"; public ItemWirelessUltraTerminal() { super(null); @@ -64,15 +66,6 @@ public class ItemWirelessUltraTerminal extends ItemBaseWirelessTerminal this.setFeature(EnumSet.of(AEFeature.WirelessAccessTerminal, AEFeature.PoweredTools)); setUnlocalizedName(NameConst.ITEM_WIRELESS_ULTRA_TERMINAL); setTextureName(FluidCraft.resource(NameConst.ITEM_WIRELESS_ULTRA_TERMINAL).toString()); - guis.add(GuiType.WIRELESS_CRAFTING_TERMINAL); - guis.add(GuiType.WIRELESS_FLUID_PATTERN_TERMINAL); - guis.add(GuiType.WIRELESS_FLUID_PATTERN_TERMINAL_EX); - guis.add(GuiType.WIRELESS_FLUID_TERMINAL); - guis.add(GuiType.WIRELESS_INTERFACE_TERMINAL); - guis.add(GuiType.WIRELESS_LEVEL_TERMINAL); - if (ModAndClassUtil.ThE) { - guis.add(GuiType.WIRELESS_ESSENTIA_TERMINAL); - } } @Override @@ -89,7 +82,7 @@ public class ItemWirelessUltraTerminal extends ItemBaseWirelessTerminal super.addCheckedInformation(stack, player, lines, displayMoreInfo); if (isShiftKeyDown()) { lines.add(StatCollector.translateToLocal(NameConst.TT_ULTRA_TERMINAL)); - lines.add(StatCollector.translateToLocal(NameConst.TT_ULTRA_TERMINAL + "." + guiGuiType(stack))); + lines.add(StatCollector.translateToLocal(NameConst.TT_ULTRA_TERMINAL + "." + getMode(stack))); lines.add(NameConst.i18n(NameConst.TT_ULTRA_TERMINAL_TIPS)); lines.addAll(Arrays.asList(NameConst.i18n(NameConst.TT_ULTRA_TERMINAL_TIPS_DESC).split("\\\\n"))); } else { @@ -99,40 +92,21 @@ public class ItemWirelessUltraTerminal extends ItemBaseWirelessTerminal @Override public String getItemStackDisplayName(ItemStack stack) { - return StatCollector.translateToLocalFormatted("item.wireless_ultra_terminal." + guiGuiType(stack) + ".name"); + return StatCollector.translateToLocalFormatted("item.wireless_ultra_terminal." + getMode(stack) + ".name"); } @Override public Object getInventory(ItemStack stack, World world, int x, int y, int z, EntityPlayer player) { try { - IGridNode gridNode = Util.getWirelessGrid(stack); - final GuiType gui; + final IGridNode gridNode = Util.getWirelessGrid(stack); + + // wireless magnet if (Util.GuiHelper.decodeType(y).getLeft() == Util.GuiHelper.GuiType.ITEM && z == -1) { - gui = GuiType.WIRELESS_MAGNET_FILTER; - } else if (Util.GuiHelper.decodeType(y).getLeft() == Util.GuiHelper.GuiType.ITEM && z > 0) { - gui = getGuis().get(Util.GuiHelper.decodeType(y).getRight()); - } else { - gui = readMode(stack); - } - if (gui == GuiType.WIRELESS_FLUID_PATTERN_TERMINAL) { - return new WirelessPatternTerminalInventory(stack, x, gridNode, player); - } else if (gui == GuiType.WIRELESS_CRAFTING_TERMINAL) { - return new WirelessCraftingTerminalInventory(stack, x, gridNode, player); - } else if (ModAndClassUtil.ThE && gui == GuiType.WIRELESS_ESSENTIA_TERMINAL) { - return new WirelessFluidTerminalInventory(stack, x, gridNode, player); - } else if (gui == GuiType.WIRELESS_FLUID_TERMINAL) { - return new WirelessFluidTerminalInventory(stack, x, gridNode, player); - } else if (gui == GuiType.WIRELESS_INTERFACE_TERMINAL) { - return new WirelessInterfaceTerminalInventory(stack, x, gridNode, player); - } else if (gui == GuiType.WIRELESS_LEVEL_TERMINAL) { - return new WirelessLevelTerminalInventory(stack, x, gridNode, player); - } else if (gui == GuiType.WIRELESS_FLUID_PATTERN_TERMINAL_EX) { - return new WirelessPatternTerminalExInventory(stack, x, gridNode, player); - } else if (gui == GuiType.WIRELESS_MAGNET_FILTER) { return new WirelessMagnetCardFilterInventory(stack, x, gridNode, player); - } else { - this.setMode(GuiType.WIRELESS_FLUID_TERMINAL, stack); // set as default mode - return new WirelessFluidTerminalInventory(stack, x, gridNode, player); + } + + if (z != 0 ? z == UltraTerminalModes.LEVEL.ordinal() : getMode(stack) == UltraTerminalModes.LEVEL) { + return new WirelessLevelTerminalInventory(stack, x, gridNode, player); } } catch (Exception e) { player.addChatMessage(PlayerMessages.OutOfRange.toChat()); @@ -141,73 +115,64 @@ public class ItemWirelessUltraTerminal extends ItemBaseWirelessTerminal } @Override - public ItemStack onItemRightClick(final ItemStack item, final World w, final EntityPlayer player) { + public ItemStack onItemRightClick(final ItemStack is, final World w, final EntityPlayer player) { if (player.isSneaking()) { - setNext(readMode(item), item); - return item; + setMode(is, nextEnum(getMode(is))); + return is; } - readMode(item); - return super.onItemRightClick(item, w, player); + return super.onItemRightClick(is, w, player); } - public static GuiType readMode(ItemStack stack) { - NBTTagCompound data = Platform.openNbtData(stack); - if (data.hasKey(MODE)) { - String GUI = data.getString(MODE); - try { - return GuiType.valueOf(GUI); - } catch (IllegalArgumentException e) { - return GuiType.WIRELESS_CRAFTING_TERMINAL; - } - } else { - return GuiType.WIRELESS_CRAFTING_TERMINAL; + public void switchTerminal(EntityPlayer player, ImmutablePair term, UltraTerminalModes mode) { + if (term != null) { + final ItemStack terminal = term.getRight(); + if (terminal == null) return; + if (mode != null) setMode(terminal, mode); + else mode = getMode(terminal); + + if (AEApi.instance().registries().wireless().performCheck(terminal, player)) + openGui(terminal, player.worldObj, player, mode, term.getLeft()); } } - public void setNext(GuiType type, ItemStack stack) { - boolean f = false; - for (GuiType g : guis) { - if (f) { - setMode(g.toString(), stack); + private void openGui(final ItemStack is, final World w, final EntityPlayer player, final Object mode, + final int slotIndex) { + final GuiBridge aeGui; + final int slot = slotIndex == Integer.MIN_VALUE ? player.inventory.currentItem : slotIndex; + final ImmutablePair invSlotPair = decodeInvType(slotIndex); + + switch (mode instanceof UltraTerminalModes utm ? utm : getMode(is)) { + case CRAFTING -> aeGui = GuiBridge.GUI_CRAFTING_TERMINAL; + case PATTERN -> aeGui = GuiBridge.GUI_PATTERN_TERMINAL; + case PATTERN_EX -> aeGui = GuiBridge.GUI_PATTERN_TERMINAL_EX; + case INTERFACE -> aeGui = GuiBridge.GUI_INTERFACE_TERMINAL; + case LEVEL -> { + InventoryHandler.openGui( + player, + w, + new BlockPos( + slot, + 0, + player.openContainer instanceof AEBaseContainer abc ? abc.getSwitchAbleGuiNext() : 0), + ForgeDirection.UNKNOWN, + GuiType.WIRELESS_LEVEL_TERMINAL); return; } - if (g == type) { - f = true; - } + default -> aeGui = GuiBridge.GUI_ME; } - setMode(guis.get(0).toString(), stack); + + Platform.openGUI( + player, + null, + null, + aeGui, + invSlotPair.getLeft() == Util.GuiHelper.InvType.PLAYER_INV ? slotIndex + : invSlotPair.getRight() + baublesSlotsOffset); } - public void setMode(String mode, ItemStack stack) { - NBTTagCompound data = Platform.openNbtData(stack); - data.setString(MODE, mode); - } - - public void setMode(GuiType mode, ItemStack stack) { - this.setMode(mode.toString(), stack); - } - - public static void switchTerminal(EntityPlayer player, GuiType guiType) { - ImmutablePair term = Util.getUltraWirelessTerm(player); - if (term == null) return; - if (term.getRight().getItem() instanceof ItemWirelessUltraTerminal) { - ((ItemWirelessUltraTerminal) term.getRight().getItem()).setMode(guiType, term.getRight()); - } - if (Platform.isClient()) { - FluidCraft.proxy.netHandler.sendToServer(new CPacketSwitchGuis(guiType, true)); - } else { - InventoryHandler.openGui( - player, - player.worldObj, - new BlockPos( - term.getLeft(), - Util.GuiHelper.encodeType( - guis.indexOf(GuiType.valueOf(guiType.toString())), - Util.GuiHelper.GuiType.ITEM), - 1), - ForgeDirection.UNKNOWN, - guiType); - } + @Override + public void openGui(final ItemStack is, final World w, final EntityPlayer player, final Object mode) { + this.openGui(is, w, player, mode, Integer.MIN_VALUE); } public static boolean hasInfinityBoosterCard(EntityPlayer player) { @@ -219,20 +184,6 @@ public class ItemWirelessUltraTerminal extends ItemBaseWirelessTerminal return false; } - public static List getGuis() { - return guis; - } - - @Override - public GuiType guiGuiType(ItemStack stack) { - return readMode(stack); - } - - @Override - public BaubleType getBaubleType(ItemStack itemStack) { - return BaubleType.RING; - } - @Override public void onWornTick(ItemStack itemStack, EntityLivingBase entityLivingBase) { if (Platform.isServer() && entityLivingBase instanceof EntityPlayer player) { @@ -252,26 +203,6 @@ public class ItemWirelessUltraTerminal extends ItemBaseWirelessTerminal } } - @Override - public void onEquipped(ItemStack itemStack, EntityLivingBase entityLivingBase) { - - } - - @Override - public void onUnequipped(ItemStack itemStack, EntityLivingBase entityLivingBase) { - - } - - @Override - public boolean canEquip(ItemStack itemStack, EntityLivingBase entityLivingBase) { - return true; - } - - @Override - public boolean canUnequip(ItemStack itemStack, EntityLivingBase entityLivingBase) { - return true; - } - @Override public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int slot, boolean p_77663_5_) { if (entityIn instanceof EntityPlayer player) { @@ -280,4 +211,21 @@ public class ItemWirelessUltraTerminal extends ItemBaseWirelessTerminal } } } + + @Override + public IGuiItemObject getGuiObject(ItemStack is, World world, EntityPlayer p, int x, int y, int z) { + final IWirelessTermHandler wh = AEApi.instance().registries().wireless().getWirelessTerminalHandler(is); + if (wh == null) return null; + return switch (y != Integer.MIN_VALUE ? UltraTerminalModes.values()[y] : getMode(is)) { + case CRAFTING -> new WirelessCraftingTerminalGuiObject(wh, is, p, world, x, y, z); + case PATTERN, PATTERN_EX -> new WirelessPatternTerminalGuiObject(wh, is, p, world, x, y, z); + case INTERFACE -> new WirelessInterfaceTerminalGuiObject(wh, is, x); + default -> super.getGuiObject(is, world, p, x, y, z); + }; + } + + @Override + public ICustomButtonDataObject getCustomDataObject(ICustomButtonProvider provider) { + return new UltraTerminalButtons(); + } } diff --git a/src/main/java/com/glodblock/github/common/parts/PartFluidExportBus.java b/src/main/java/com/glodblock/github/common/parts/PartFluidExportBus.java index 4e1b5daa..2339d33c 100644 --- a/src/main/java/com/glodblock/github/common/parts/PartFluidExportBus.java +++ b/src/main/java/com/glodblock/github/common/parts/PartFluidExportBus.java @@ -1,69 +1,29 @@ package com.glodblock.github.common.parts; -import static appeng.util.Platform.convertStack; -import static appeng.util.Platform.stackConvert; - -import net.minecraft.client.renderer.RenderBlocks; -import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.IIcon; -import net.minecraftforge.fluids.IFluidHandler; import com.glodblock.github.client.textures.FCPartsTexture; -import com.glodblock.github.common.item.ItemFluidDrop; -import com.glodblock.github.common.item.ItemFluidPacket; -import com.glodblock.github.common.parts.base.FCSharedFluidBus; -import com.google.common.collect.ImmutableSet; +import com.glodblock.github.util.Util; -import appeng.api.config.Actionable; import appeng.api.config.FuzzyMode; -import appeng.api.config.InsertionMode; -import appeng.api.config.PowerMultiplier; -import appeng.api.config.RedstoneMode; -import appeng.api.config.SchedulingMode; -import appeng.api.config.Settings; import appeng.api.config.Upgrades; -import appeng.api.config.YesNo; -import appeng.api.networking.IGridNode; -import appeng.api.networking.crafting.ICraftingGrid; -import appeng.api.networking.crafting.ICraftingLink; -import appeng.api.networking.crafting.ICraftingRequester; import appeng.api.networking.energy.IEnergyGrid; -import appeng.api.networking.security.BaseActionSource; -import appeng.api.networking.security.MachineSource; -import appeng.api.networking.ticking.TickRateModulation; -import appeng.api.networking.ticking.TickingRequest; -import appeng.api.parts.IPartCollisionHelper; -import appeng.api.parts.IPartRenderHelper; import appeng.api.storage.IMEMonitor; +import appeng.api.storage.StorageName; import appeng.api.storage.data.IAEFluidStack; import appeng.api.storage.data.IAEItemStack; -import appeng.client.texture.CableBusTextures; -import appeng.core.AELog; -import appeng.helpers.MultiCraftingTracker; +import appeng.api.storage.data.IAEStack; import appeng.me.GridAccessException; +import appeng.parts.automation.PartBaseExportBus; +import appeng.tile.inventory.IAEStackInventory; import appeng.util.InventoryAdaptor; -import appeng.util.Platform; -import appeng.util.item.AEFluidStack; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -public class PartFluidExportBus extends FCSharedFluidBus implements ICraftingRequester { - - private final BaseActionSource source; - private final MultiCraftingTracker craftingTracker = new MultiCraftingTracker(this, 9); - private int nextSlot = 0; - private long fluidToSend = 1000; - private boolean didSomething; +public class PartFluidExportBus extends PartBaseExportBus { public PartFluidExportBus(ItemStack is) { super(is); - this.getConfigManager().registerSetting(Settings.REDSTONE_CONTROLLED, RedstoneMode.IGNORE); - this.getConfigManager().registerSetting(Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL); - this.getConfigManager().registerSetting(Settings.CRAFT_ONLY, YesNo.NO); - this.getConfigManager().registerSetting(Settings.SCHEDULING_MODE, SchedulingMode.DEFAULT); - this.source = new MachineSource(this); } @Override @@ -72,238 +32,63 @@ public class PartFluidExportBus extends FCSharedFluidBus implements ICraftingReq } @Override - public TickingRequest getTickingRequest(IGridNode node) { - return new TickingRequest(5, 40, this.isSleeping(), false); + protected int getAdaptorFlags() { + return InventoryAdaptor.DEFAULT & ~InventoryAdaptor.ALLOW_ITEMS; } @Override - public TickRateModulation tickingRequest(IGridNode node, int ticksSinceLastCall) { - return this.canDoBusWork() ? this.doBusWork() : TickRateModulation.IDLE; - } - - @Override - protected boolean canDoBusWork() { - return this.getProxy().isActive(); - } - - private int getStartingSlot(final SchedulingMode schedulingMode, final int x) { - if (schedulingMode == SchedulingMode.RANDOM) { - return Platform.getRandom().nextInt(this.availableSlots()); + public int calculateAmountToSend() { + double amount = 1000D; + switch (this.getInstalledUpgrades(Upgrades.SPEED)) { + case 4: + amount = amount * 1.5; + case 3: + amount = amount * 2; + case 2: + amount = amount * 4; + case 1: + amount = amount * 8; } - - if (schedulingMode == SchedulingMode.ROUNDROBIN) { - return (this.nextSlot + x) % this.availableSlots(); + switch (this.getInstalledUpgrades(Upgrades.SUPERSPEED)) { + case 4: + amount = amount * 8; + case 3: + amount = amount * 12; + case 2: + amount = amount * 16; + case 1: + amount = amount * 32; } - - return x; - } - - private int availableSlots() { - return Math.min(1 + this.getInstalledUpgrades(Upgrades.CAPACITY) * 4, this.getInv().getSizeInventory()); - } - - private IInventory getInv() { - return this.getInventoryByName("config"); + return (int) Math.floor(amount); } @Override - protected TickRateModulation doBusWork() { - if (!this.canDoBusWork()) { - return TickRateModulation.IDLE; - } - this.didSomething = false; - this.fluidToSend = this.calculateAmountToSend(); - final TileEntity te = this.getConnectedTE(); - InventoryAdaptor destination; - if (te instanceof IFluidHandler && (destination = this.getHandler(te)) != null) { - try { - final ICraftingGrid cg = this.getProxy().getCrafting(); - final IFluidHandler fh = (IFluidHandler) te; - final IMEMonitor inv = this.getProxy().getStorage().getFluidInventory(); - int i; - for (i = 0; i < this.availableSlots() && this.fluidToSend > 0; i++) { - final int slotToExport = this.getStartingSlot(this.getSchedulingMode(), i); - IAEFluidStack fluid = AEFluidStack - .create(ItemFluidPacket.getFluidStack(getInv().getStackInSlot(slotToExport))); - if (fluid != null) { - fluid.setStackSize(this.calculateAmountToSend()); - if (this.craftOnly()) { - this.didSomething = this.craftingTracker.handleCrafting( - i, - fluid.getStackSize(), - ItemFluidDrop.newAeStack(fluid), - destination, - this.getTile().getWorldObj(), - this.getProxy().getGrid(), - cg, - this.source); - continue; - } - // Find out how much to push - final IAEFluidStack toPush = fluid.copy(); - final int amtToInsert = fh.fill(this.getSide().getOpposite(), toPush.getFluidStack(), false); - toPush.setStackSize(amtToInsert); - // Extract from the ME system. This might not be the same amount we actually send... - final IAEFluidStack real = inv.extractItems(toPush, Actionable.MODULATE, this.source); - if (real != null) { - int realInserted = fh.fill(this.getSide().getOpposite(), real.getFluidStack(), true); - if (realInserted < real.getStackSize()) { - // Could not use the entirety of the amount we extracted, so put it back. - // This can result in voiding fluids if there's nowhere for the fluids to go. - fluid.setStackSize(real.getStackSize() - realInserted); - inv.injectItems(fluid, Actionable.MODULATE, this.source); - } - this.fluidToSend -= realInserted; - didSomething = true; - } else if (this.isCraftingEnabled()) { - // If we didn't send anything, try crafting it if we can. - this.didSomething = this.craftingTracker.handleCrafting( - i, - fluid.getStackSize(), - ItemFluidDrop.newAeStack(fluid), - destination, - this.getTile().getWorldObj(), - this.getProxy().getGrid(), - cg, - this.source); - } - } - } - this.updateSchedulingMode(this.getSchedulingMode(), i); - return didSomething ? TickRateModulation.FASTER : TickRateModulation.SLOWER; - } catch (GridAccessException ignored) {} - } - - return TickRateModulation.SLEEP; - } - - private void updateSchedulingMode(final SchedulingMode schedulingMode, final int x) { - if (schedulingMode == SchedulingMode.ROUNDROBIN) { - this.nextSlot = (this.nextSlot + x) % this.availableSlots(); - } - } - - @Override - public void getBoxes(final IPartCollisionHelper bch) { - bch.addBox(4, 4, 12, 12, 12, 14); - bch.addBox(5, 5, 14, 11, 11, 15); - bch.addBox(6, 6, 15, 10, 10, 16); - bch.addBox(6, 6, 11, 10, 10, 12); - } - - @Override - @SideOnly(Side.CLIENT) - public void renderInventory(final IPartRenderHelper rh, final RenderBlocks renderer) { - rh.setTexture( - CableBusTextures.PartExportSides.getIcon(), - CableBusTextures.PartExportSides.getIcon(), - CableBusTextures.PartMonitorBack.getIcon(), - this.getFaceIcon(), - CableBusTextures.PartExportSides.getIcon(), - CableBusTextures.PartExportSides.getIcon()); - - rh.setBounds(4, 4, 12, 12, 12, 14); - rh.renderInventoryBox(renderer); - - rh.setBounds(5, 5, 14, 11, 11, 15); - rh.renderInventoryBox(renderer); - - rh.setBounds(6, 6, 15, 10, 10, 16); - rh.renderInventoryBox(renderer); - } - - @Override - @SideOnly(Side.CLIENT) - public void renderStatic(final int x, final int y, final int z, final IPartRenderHelper rh, - final RenderBlocks renderer) { - this.setRenderCache(rh.useSimplifiedRendering(x, y, z, this, this.getRenderCache())); - rh.setTexture( - CableBusTextures.PartExportSides.getIcon(), - CableBusTextures.PartExportSides.getIcon(), - CableBusTextures.PartMonitorBack.getIcon(), - this.getFaceIcon(), - CableBusTextures.PartExportSides.getIcon(), - CableBusTextures.PartExportSides.getIcon()); - - rh.setBounds(4, 4, 12, 12, 12, 14); - rh.renderBlock(x, y, z, renderer); - - rh.setBounds(5, 5, 14, 11, 11, 15); - rh.renderBlock(x, y, z, renderer); - - rh.setBounds(6, 6, 15, 10, 10, 16); - rh.renderBlock(x, y, z, renderer); - - rh.setTexture( - CableBusTextures.PartMonitorSidesStatus.getIcon(), - CableBusTextures.PartMonitorSidesStatus.getIcon(), - CableBusTextures.PartMonitorBack.getIcon(), - this.getFaceIcon(), - CableBusTextures.PartMonitorSidesStatus.getIcon(), - CableBusTextures.PartMonitorSidesStatus.getIcon()); - - rh.setBounds(6, 6, 11, 10, 10, 12); - rh.renderBlock(x, y, z, renderer); - - this.renderLights(x, y, z, rh, renderer); - } - - @Override - public RedstoneMode getRSMode() { - return (RedstoneMode) this.getConfigManager().getSetting(Settings.REDSTONE_CONTROLLED); - } - - public SchedulingMode getSchedulingMode() { - return (SchedulingMode) this.getConfigManager().getSetting(Settings.SCHEDULING_MODE); - } - - private boolean craftOnly() { - return this.getConfigManager().getSetting(Settings.CRAFT_ONLY) == YesNo.YES; - } - - private boolean isCraftingEnabled() { - return this.getInstalledUpgrades(Upgrades.CRAFTING) > 0; - } - - @Override - public ImmutableSet getRequestedJobs() { - return this.craftingTracker.getRequestedJobs(); - } - - protected InventoryAdaptor getHandler(TileEntity target) { - return target != null ? InventoryAdaptor.getAdaptor(target, getSide().getOpposite()) : null; - } - - @Override - public IAEItemStack injectCraftedItems(ICraftingLink link, IAEItemStack items, Actionable mode) { - final InventoryAdaptor d = this.getHandler(getConnectedTE()); - + protected IMEMonitor getMonitor() { try { - if (d != null && this.getProxy().isActive()) { - final IEnergyGrid energy = this.getProxy().getEnergy(); - final double power = Math.ceil(items.getStackSize() / 1000D); - - if (energy.extractAEPower(power, mode, PowerMultiplier.CONFIG) > power - 0.01) { - IAEItemStack remaining; - - if (mode == Actionable.SIMULATE) { - remaining = stackConvert(d.simulateAddStack(convertStack(items), InsertionMode.DEFAULT)); - } else { - remaining = stackConvert(d.addStack(convertStack(items), InsertionMode.DEFAULT)); - } - - return remaining; - } - } + return this.getProxy().getStorage().getFluidInventory(); } catch (final GridAccessException e) { - AELog.debug(e); + return null; } - - return items; } @Override - public void jobStateChange(ICraftingLink link) { - this.craftingTracker.jobStateChange(link); + protected void doFuzzy(IAEFluidStack aes, FuzzyMode fzMode, InventoryAdaptor destination, IEnergyGrid energy, + IMEMonitor gridInv) {} + + @Override + protected void doOreDict(InventoryAdaptor destination, IEnergyGrid energy, IMEMonitor gridInv) {} + + // legacy + @Override + public void readFromNBT(NBTTagCompound extra) { + super.readFromNBT(extra); + + final IAEStackInventory config = this.getAEInventoryByName(StorageName.NONE); + for (int i = 0; i < config.getSizeInventory(); i++) { + final IAEStack stack = config.getAEStackInSlot(i); + if (stack instanceof IAEItemStack ais) { + config.putAEStackInSlot(i, Util.getAEFluidFromItem(ais.getItemStack())); + } + } } } diff --git a/src/main/java/com/glodblock/github/common/parts/PartFluidImportBus.java b/src/main/java/com/glodblock/github/common/parts/PartFluidImportBus.java index 07b8bc43..e59f6e63 100644 --- a/src/main/java/com/glodblock/github/common/parts/PartFluidImportBus.java +++ b/src/main/java/com/glodblock/github/common/parts/PartFluidImportBus.java @@ -1,49 +1,37 @@ package com.glodblock.github.common.parts; -import net.minecraft.client.renderer.RenderBlocks; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.IIcon; +import net.minecraft.world.World; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTankInfo; import net.minecraftforge.fluids.IFluidHandler; import com.glodblock.github.client.textures.FCPartsTexture; -import com.glodblock.github.common.item.ItemFluidPacket; -import com.glodblock.github.common.parts.base.FCSharedFluidBus; +import com.glodblock.github.util.BlockPos; +import com.glodblock.github.util.Util; import appeng.api.config.Actionable; import appeng.api.config.FuzzyMode; -import appeng.api.config.RedstoneMode; -import appeng.api.config.SchedulingMode; -import appeng.api.config.Settings; -import appeng.api.config.YesNo; -import appeng.api.networking.IGridNode; -import appeng.api.networking.security.BaseActionSource; -import appeng.api.networking.security.MachineSource; -import appeng.api.networking.ticking.TickRateModulation; -import appeng.api.networking.ticking.TickingRequest; -import appeng.api.parts.IPartCollisionHelper; -import appeng.api.parts.IPartRenderHelper; +import appeng.api.config.Upgrades; +import appeng.api.networking.energy.IEnergyGrid; +import appeng.api.networking.energy.IEnergySource; import appeng.api.storage.IMEMonitor; +import appeng.api.storage.StorageName; import appeng.api.storage.data.IAEFluidStack; -import appeng.client.texture.CableBusTextures; +import appeng.api.storage.data.IAEItemStack; +import appeng.api.storage.data.IAEStack; import appeng.me.GridAccessException; +import appeng.parts.automation.PartBaseImportBus; +import appeng.tile.inventory.IAEStackInventory; import appeng.util.item.AEFluidStack; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -public class PartFluidImportBus extends FCSharedFluidBus { - - private final BaseActionSource source; +public class PartFluidImportBus extends PartBaseImportBus { public PartFluidImportBus(ItemStack is) { super(is); - this.getConfigManager().registerSetting(Settings.REDSTONE_CONTROLLED, RedstoneMode.IGNORE); - this.getConfigManager().registerSetting(Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL); - this.getConfigManager().registerSetting(Settings.CRAFT_ONLY, YesNo.NO); - this.getConfigManager().registerSetting(Settings.SCHEDULING_MODE, SchedulingMode.DEFAULT); - this.source = new MachineSource(this); } @Override @@ -52,79 +40,108 @@ public class PartFluidImportBus extends FCSharedFluidBus { } @Override - public TickingRequest getTickingRequest(IGridNode node) { - return new TickingRequest(5, 40, this.isSleeping(), false); + protected Object getTarget() { + TileEntity self = this.getHost().getTile(); + return this.getTileEntity(self, (new BlockPos(self)).getOffSet(this.getSide())); } - @Override - public TickRateModulation tickingRequest(IGridNode node, int ticksSinceLastCall) { - return this.canDoBusWork() ? this.doBusWork() : TickRateModulation.IDLE; - } + private TileEntity getTileEntity(final TileEntity self, final BlockPos pos) { + final World w = self.getWorldObj(); - @Override - protected TickRateModulation doBusWork() { - if (!this.canDoBusWork()) { - return TickRateModulation.IDLE; + if (w.getChunkProvider().chunkExists(pos.getX() >> 4, pos.getZ() >> 4)) { + return w.getTileEntity(pos.getX(), pos.getY(), pos.getZ()); } - final TileEntity te = this.getConnectedTE(); + return null; + } - if (te instanceof IFluidHandler) { - try { - final IFluidHandler fh = (IFluidHandler) te; - FluidTankInfo[] tanksInfo = fh.getTankInfo(this.getSide().getOpposite()); - if (tanksInfo == null) { - return TickRateModulation.SLOWER; + @Override + public int calculateAmountToSend() { + double amount = 1000D; + switch (this.getInstalledUpgrades(Upgrades.SPEED)) { + case 4: + amount = amount * 1.5; + case 3: + amount = amount * 2; + case 2: + amount = amount * 4; + case 1: + amount = amount * 8; + } + switch (this.getInstalledUpgrades(Upgrades.SUPERSPEED)) { + case 4: + amount = amount * 8; + case 3: + amount = amount * 12; + case 2: + amount = amount * 16; + case 1: + amount = amount * 32; + } + return (int) Math.floor(amount); + } + + @Override + protected IMEMonitor getMonitor() { + try { + return this.getProxy().getStorage().getFluidInventory(); + } catch (final GridAccessException e) { + return null; + } + } + + @Override + protected boolean importStuff(final Object myTarget, final IAEFluidStack whatToImport, + final IMEMonitor inv, final IEnergySource energy, final FuzzyMode fzMode) { + if (myTarget instanceof IFluidHandler fh) { + FluidTankInfo[] tanksInfo = fh.getTankInfo(this.getSide().getOpposite()); + if (tanksInfo == null) return true; + + int maxDrain = this.calculateAmountToSend(); + boolean doBreak = true; + + for (FluidTankInfo tankInfo : tanksInfo) { + if (tankInfo.fluid == null) continue; + + FluidStack fluidStack = new FluidStack(tankInfo.fluid, Math.min(tankInfo.fluid.amount, maxDrain)); + fluidStack = fh.drain(this.getSide().getOpposite(), fluidStack, false); + if (this.filterEnabled() && !this.isInFilter(fluidStack)) continue; + + final AEFluidStack aeFluidStack = AEFluidStack.create(fluidStack); + if (aeFluidStack != null) { + final IAEFluidStack notInserted = inv.injectItems(aeFluidStack, Actionable.MODULATE, this.mySrc); + + if (notInserted != null && notInserted.getStackSize() > 0) { + aeFluidStack.decStackSize(notInserted.getStackSize()); + } + + fh.drain(this.getSide().getOpposite(), aeFluidStack.getFluidStack(), true); + maxDrain -= aeFluidStack.getFluidStack().amount; + doBreak = false; } - - final IMEMonitor inv = this.getProxy().getStorage().getFluidInventory(); - int maxDrain = this.calculateAmountToSend(); - boolean drained = false; - - for (FluidTankInfo tankInfo : tanksInfo) { - if (tankInfo.fluid == null) { - continue; - } - - FluidStack fluidStack = new FluidStack(tankInfo.fluid, Math.min(tankInfo.fluid.amount, maxDrain)); - fluidStack = fh.drain(this.getSide().getOpposite(), fluidStack, false); - if (this.filterEnabled() && !this.isInFilter(fluidStack)) { - continue; - } - - final AEFluidStack aeFluidStack = AEFluidStack.create(fluidStack); - if (aeFluidStack != null) { - final IAEFluidStack notInserted = inv - .injectItems(aeFluidStack, Actionable.MODULATE, this.source); - - if (notInserted != null && notInserted.getStackSize() > 0) { - aeFluidStack.decStackSize(notInserted.getStackSize()); - } - - fh.drain(this.getSide().getOpposite(), aeFluidStack.getFluidStack(), true); - maxDrain -= aeFluidStack.getFluidStack().amount; - drained = true; - } - } - - return drained ? TickRateModulation.FASTER : TickRateModulation.SLOWER; - } catch (GridAccessException e) { - e.printStackTrace(); } + + return doBreak; } - return TickRateModulation.SLEEP; + return true; } @Override - protected boolean canDoBusWork() { - return this.getProxy().isActive(); + protected boolean doOreDict(final Object myTarget, IMEMonitor inv, IEnergyGrid energy, + FuzzyMode fzMode) { + return false; + } + + @Override + protected int getPowerMultiplier() { + return 1000; } private boolean isInFilter(FluidStack fluid) { - for (int i = 0; i < this.getInventoryByName("config").getSizeInventory(); i++) { - final IAEFluidStack stack = AEFluidStack - .create(ItemFluidPacket.getFluidStack(this.getInventoryByName("config").getStackInSlot(i))); + final IAEStackInventory inv = this.getAEInventoryByName(StorageName.NONE); + for (int i = 0; i < inv.getSizeInventory(); i++) { + final IAEFluidStack stack = (IAEFluidStack) inv.getAEStackInSlot(i); if (stack != null && stack.getFluidStack().equals(fluid)) { return true; } @@ -133,9 +150,9 @@ public class PartFluidImportBus extends FCSharedFluidBus { } private boolean filterEnabled() { - for (int i = 0; i < this.getInventoryByName("config").getSizeInventory(); i++) { - final IAEFluidStack stack = AEFluidStack - .create(ItemFluidPacket.getFluidStack(this.getInventoryByName("config").getStackInSlot(i))); + final IAEStackInventory inv = this.getAEInventoryByName(StorageName.NONE); + for (int i = 0; i < inv.getSizeInventory(); i++) { + final IAEFluidStack stack = (IAEFluidStack) inv.getAEStackInSlot(i); if (stack != null) { return true; } @@ -143,71 +160,17 @@ public class PartFluidImportBus extends FCSharedFluidBus { return false; } + // legacy @Override - public RedstoneMode getRSMode() { - return (RedstoneMode) this.getConfigManager().getSetting(Settings.REDSTONE_CONTROLLED); - } + public void readFromNBT(NBTTagCompound extra) { + super.readFromNBT(extra); - @Override - public void getBoxes(final IPartCollisionHelper bch) { - bch.addBox(6, 6, 11, 10, 10, 13); - bch.addBox(5, 5, 13, 11, 11, 14); - bch.addBox(4, 4, 14, 12, 12, 16); - } - - @Override - @SideOnly(Side.CLIENT) - public void renderInventory(final IPartRenderHelper rh, final RenderBlocks renderer) { - rh.setTexture( - CableBusTextures.PartImportSides.getIcon(), - CableBusTextures.PartImportSides.getIcon(), - CableBusTextures.PartMonitorBack.getIcon(), - this.getFaceIcon(), - CableBusTextures.PartImportSides.getIcon(), - CableBusTextures.PartImportSides.getIcon()); - - rh.setBounds(3, 3, 15, 13, 13, 16); - rh.renderInventoryBox(renderer); - - rh.setBounds(4, 4, 14, 12, 12, 15); - rh.renderInventoryBox(renderer); - - rh.setBounds(5, 5, 13, 11, 11, 14); - rh.renderInventoryBox(renderer); - } - - @Override - @SideOnly(Side.CLIENT) - public void renderStatic(final int x, final int y, final int z, final IPartRenderHelper rh, - final RenderBlocks renderer) { - this.setRenderCache(rh.useSimplifiedRendering(x, y, z, this, this.getRenderCache())); - rh.setTexture( - CableBusTextures.PartImportSides.getIcon(), - CableBusTextures.PartImportSides.getIcon(), - CableBusTextures.PartMonitorBack.getIcon(), - this.getFaceIcon(), - CableBusTextures.PartImportSides.getIcon(), - CableBusTextures.PartImportSides.getIcon()); - - rh.setBounds(4, 4, 14, 12, 12, 16); - rh.renderBlock(x, y, z, renderer); - - rh.setBounds(5, 5, 13, 11, 11, 14); - rh.renderBlock(x, y, z, renderer); - - rh.setBounds(6, 6, 12, 10, 10, 13); - rh.renderBlock(x, y, z, renderer); - rh.setTexture( - CableBusTextures.PartMonitorSidesStatus.getIcon(), - CableBusTextures.PartMonitorSidesStatus.getIcon(), - CableBusTextures.PartMonitorBack.getIcon(), - this.getFaceIcon(), - CableBusTextures.PartMonitorSidesStatus.getIcon(), - CableBusTextures.PartMonitorSidesStatus.getIcon()); - - rh.setBounds(6, 6, 11, 10, 10, 12); - rh.renderBlock(x, y, z, renderer); - - this.renderLights(x, y, z, rh, renderer); + final IAEStackInventory config = this.getAEInventoryByName(StorageName.NONE); + for (int i = 0; i < config.getSizeInventory(); i++) { + final IAEStack stack = config.getAEStackInSlot(i); + if (stack instanceof IAEItemStack ais) { + config.putAEStackInSlot(i, Util.getAEFluidFromItem(ais.getItemStack())); + } + } } } diff --git a/src/main/java/com/glodblock/github/common/parts/PartFluidInterface.java b/src/main/java/com/glodblock/github/common/parts/PartFluidInterface.java index 3905ac0b..5fb29968 100644 --- a/src/main/java/com/glodblock/github/common/parts/PartFluidInterface.java +++ b/src/main/java/com/glodblock/github/common/parts/PartFluidInterface.java @@ -1,26 +1,22 @@ package com.glodblock.github.common.parts; import java.io.IOException; -import java.util.Objects; +import java.util.List; -import net.minecraft.client.renderer.RenderBlocks; -import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.client.gui.GuiButton; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.Vec3; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTankInfo; -import com.glodblock.github.client.textures.FCPartsTexture; +import com.glodblock.github.client.FluidInterfaceButtons; import com.glodblock.github.common.item.ItemFluidPacket; import com.glodblock.github.inventory.AEFluidInventory; import com.glodblock.github.inventory.IAEFluidTank; import com.glodblock.github.inventory.IDualHost; -import com.glodblock.github.inventory.InventoryHandler; -import com.glodblock.github.inventory.gui.GuiType; -import com.glodblock.github.util.BlockPos; +import com.glodblock.github.loader.ItemAndBlockHolder; import com.glodblock.github.util.DualityFluidInterface; import com.glodblock.github.util.Util; @@ -31,86 +27,27 @@ import appeng.api.networking.events.MENetworkEventSubscribe; import appeng.api.networking.events.MENetworkPowerStatusChange; import appeng.api.networking.ticking.TickRateModulation; import appeng.api.networking.ticking.TickingRequest; -import appeng.api.parts.IPartRenderHelper; import appeng.api.storage.data.IAEFluidStack; -import appeng.client.texture.CableBusTextures; +import appeng.helpers.ICustomButtonDataObject; +import appeng.helpers.ICustomButtonProvider; import appeng.parts.misc.PartInterface; import appeng.tile.inventory.AppEngInternalAEInventory; -import appeng.util.Platform; import cpw.mods.fml.common.network.ByteBufUtils; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import io.netty.buffer.ByteBuf; -public class PartFluidInterface extends PartInterface implements IDualHost { +public class PartFluidInterface extends PartInterface implements IDualHost, ICustomButtonProvider { private final AppEngInternalAEInventory config = new AppEngInternalAEInventory(this, 6); private final DualityFluidInterface fluidDuality = new DualityFluidInterface(this.getProxy(), this); + private ICustomButtonDataObject customButtonDataObject; + public PartFluidInterface(ItemStack is) { super(is); - } - @Override - @SideOnly(Side.CLIENT) - public void renderStatic(final int x, final int y, final int z, final IPartRenderHelper rh, - final RenderBlocks renderer) { - this.setRenderCache(rh.useSimplifiedRendering(x, y, z, this, this.getRenderCache())); - rh.setTexture( - CableBusTextures.PartMonitorSides.getIcon(), - CableBusTextures.PartMonitorSides.getIcon(), - CableBusTextures.PartMonitorBack.getIcon(), - FCPartsTexture.BlockInterface_Face.getIcon(), - CableBusTextures.PartMonitorSides.getIcon(), - CableBusTextures.PartMonitorSides.getIcon()); - - rh.setBounds(2, 2, 14, 14, 14, 16); - rh.renderBlock(x, y, z, renderer); - - rh.setTexture( - CableBusTextures.PartMonitorSides.getIcon(), - CableBusTextures.PartMonitorSides.getIcon(), - CableBusTextures.PartMonitorBack.getIcon(), - FCPartsTexture.BlockInterface_Face.getIcon(), - CableBusTextures.PartMonitorSides.getIcon(), - CableBusTextures.PartMonitorSides.getIcon()); - - rh.setBounds(5, 5, 12, 11, 11, 13); - rh.renderBlock(x, y, z, renderer); - - rh.setTexture( - CableBusTextures.PartMonitorSidesStatus.getIcon(), - CableBusTextures.PartMonitorSidesStatus.getIcon(), - CableBusTextures.PartMonitorBack.getIcon(), - FCPartsTexture.BlockInterface_Face.getIcon(), - CableBusTextures.PartMonitorSidesStatus.getIcon(), - CableBusTextures.PartMonitorSidesStatus.getIcon()); - - rh.setBounds(5, 5, 13, 11, 11, 14); - rh.renderBlock(x, y, z, renderer); - - this.renderLights(x, y, z, rh, renderer); - } - - @Override - @SideOnly(Side.CLIENT) - public void renderInventory(final IPartRenderHelper rh, final RenderBlocks renderer) { - rh.setTexture( - CableBusTextures.PartMonitorSides.getIcon(), - CableBusTextures.PartMonitorSides.getIcon(), - CableBusTextures.PartMonitorBack.getIcon(), - FCPartsTexture.BlockInterface_Face.getIcon(), - CableBusTextures.PartMonitorSides.getIcon(), - CableBusTextures.PartMonitorSides.getIcon()); - - rh.setBounds(2, 2, 14, 14, 14, 16); - rh.renderInventoryBox(renderer); - - rh.setBounds(5, 5, 12, 11, 11, 13); - rh.renderInventoryBox(renderer); - - rh.setBounds(5, 5, 13, 11, 11, 14); - rh.renderInventoryBox(renderer); + this.customButtonDataObject = new FluidInterfaceButtons(false); } @MENetworkEventSubscribe @@ -222,22 +159,6 @@ public class PartFluidInterface extends PartInterface implements IDualHost { return fluidDuality.getTankInfo(from); } - @Override - public boolean onPartActivate(final EntityPlayer player, final Vec3 pos) { - if (player.isSneaking()) { - return false; - } - if (Platform.isServer()) { - InventoryHandler.openGui( - player, - this.getHost().getTile().getWorldObj(), - new BlockPos(this.getHost().getTile()), - Objects.requireNonNull(this.getSide()), - GuiType.DUAL_INTERFACE); - } - return true; - } - @Override public void onFluidInventoryChanged(IAEFluidTank inv, int slot) { saveChanges(); @@ -283,4 +204,38 @@ public class PartFluidInterface extends PartInterface implements IDualHost { return fluid; } } + + @Override + public ItemStack getPrimaryGuiIcon() { + return ItemAndBlockHolder.FLUID_INTERFACE.stack(); + } + + @Override + public void writeCustomButtonData() {} + + @Override + public void readCustomButtonData() {} + + @Override + public void initCustomButtons(int guiLeft, int guiTop, int xSize, int ySize, int xOffset, int yOffset, + List buttonList) { + if (customButtonDataObject != null) + customButtonDataObject.initCustomButtons(guiLeft, guiTop, xSize, ySize, xOffset, yOffset, buttonList); + } + + @SideOnly(Side.CLIENT) + @Override + public boolean actionPerformedCustomButtons(final GuiButton btn) { + return customButtonDataObject != null && customButtonDataObject.actionPerformedCustomButtons(btn); + } + + @Override + public ICustomButtonDataObject getDataObject() { + return customButtonDataObject; + } + + @Override + public void setDataObject(ICustomButtonDataObject dataObject) { + customButtonDataObject = dataObject; + } } diff --git a/src/main/java/com/glodblock/github/common/parts/PartFluidLevelEmitter.java b/src/main/java/com/glodblock/github/common/parts/PartFluidLevelEmitter.java index f78761eb..c8dfe4b1 100644 --- a/src/main/java/com/glodblock/github/common/parts/PartFluidLevelEmitter.java +++ b/src/main/java/com/glodblock/github/common/parts/PartFluidLevelEmitter.java @@ -1,603 +1,14 @@ package com.glodblock.github.common.parts; -import java.util.Objects; -import java.util.Random; - -import net.minecraft.client.renderer.RenderBlocks; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.server.MinecraftServer; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.IIcon; -import net.minecraft.util.Vec3; -import net.minecraft.world.World; -import net.minecraftforge.common.util.ForgeDirection; -import net.minecraftforge.fluids.FluidStack; -import com.glodblock.github.api.registries.ILevelViewable; -import com.glodblock.github.api.registries.LevelItemInfo; -import com.glodblock.github.api.registries.LevelState; -import com.glodblock.github.common.item.ItemFluidPacket; -import com.glodblock.github.inventory.InventoryHandler; -import com.glodblock.github.inventory.gui.GuiType; -import com.glodblock.github.util.BlockPos; -import com.glodblock.github.util.Util; - -import appeng.api.config.RedstoneMode; -import appeng.api.config.Settings; -import appeng.api.networking.IGridNode; -import appeng.api.networking.crafting.ICraftingGrid; -import appeng.api.networking.crafting.ICraftingWatcher; -import appeng.api.networking.crafting.ICraftingWatcherHost; -import appeng.api.networking.events.MENetworkChannelsChanged; -import appeng.api.networking.events.MENetworkEventSubscribe; -import appeng.api.networking.events.MENetworkPowerStatusChange; -import appeng.api.networking.security.BaseActionSource; -import appeng.api.networking.storage.IBaseMonitor; -import appeng.api.networking.storage.IStackWatcher; -import appeng.api.networking.storage.IStackWatcherHost; -import appeng.api.networking.ticking.IGridTickable; -import appeng.api.networking.ticking.TickRateModulation; -import appeng.api.networking.ticking.TickingRequest; -import appeng.api.parts.IPartCollisionHelper; -import appeng.api.parts.IPartRenderHelper; -import appeng.api.storage.IMEMonitor; -import appeng.api.storage.IMEMonitorHandlerReceiver; -import appeng.api.storage.StorageChannel; -import appeng.api.storage.data.IAEFluidStack; -import appeng.api.storage.data.IAEItemStack; -import appeng.api.storage.data.IAEStack; -import appeng.api.storage.data.IItemList; -import appeng.api.util.AECableType; -import appeng.api.util.IConfigManager; -import appeng.client.texture.CableBusTextures; -import appeng.core.AEConfig; -import appeng.core.AELog; import appeng.helpers.Reflected; -import appeng.me.GridAccessException; -import appeng.parts.automation.PartUpgradeable; -import appeng.tile.inventory.AppEngInternalAEInventory; -import appeng.tile.inventory.InvOperation; -import appeng.util.Platform; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; +import appeng.parts.automation.PartLevelEmitter; -public class PartFluidLevelEmitter extends PartUpgradeable implements IStackWatcherHost, ICraftingWatcherHost, - IMEMonitorHandlerReceiver, IGridTickable, ILevelViewable { - - private static final int FLAG_ON = 8; - - private final AppEngInternalAEInventory config = new AppEngInternalAEInventory(this, 1); - - private boolean prevState = false; - - private long lastReportedValue = 0; - private long reportingValue = 0; - - private IStackWatcher myWatcher; - private double centerX; - private double centerY; - private double centerZ; - - private int lastWorkingTick = 0; - private boolean delayedUpdatesQueued = false; +public class PartFluidLevelEmitter extends PartLevelEmitter { @Reflected public PartFluidLevelEmitter(final ItemStack is) { super(is); - - this.getConfigManager().registerSetting(Settings.REDSTONE_EMITTER, RedstoneMode.LOW_SIGNAL); - - // Workaround the emitter randomly breaking on world load - if (MinecraftServer.getServer() != null) { - delayedUpdatesQueued = true; - lastWorkingTick = MinecraftServer.getServer().getTickCounter(); - } - } - - public long getReportingValue() { - return this.reportingValue; - } - - public void setReportingValue(final long v) { - this.reportingValue = v; - this.updateState(); - } - - @MENetworkEventSubscribe - public void powerChanged(final MENetworkPowerStatusChange c) { - this.updateState(); - } - - private void updateState() { - final boolean isOn = this.isLevelEmitterOn(); - if (this.prevState != isOn) { - this.getHost().markForUpdate(); - final TileEntity te = this.getHost().getTile(); - this.prevState = isOn; - Platform.notifyBlocksOfNeighbors(te.getWorldObj(), te.xCoord, te.yCoord, te.zCoord); - Platform.notifyBlocksOfNeighbors( - te.getWorldObj(), - te.xCoord + this.getSide().offsetX, - te.yCoord + this.getSide().offsetY, - te.zCoord + this.getSide().offsetZ); - } - } - - private boolean isLevelEmitterOn() { - if (Platform.isClient()) { - return (this.getClientFlags() & FLAG_ON) == FLAG_ON; - } - - if (!this.getProxy().isActive()) { - return false; - } - - final Enum redstoneEmitterSetting = this.getConfigManager().getSetting(Settings.REDSTONE_EMITTER); - final boolean result; - - if (redstoneEmitterSetting == RedstoneMode.LOW_SIGNAL) { - result = this.reportingValue >= this.lastReportedValue + 1; - } else { - result = this.reportingValue < this.lastReportedValue + 1; - } - - return result; - } - - @MENetworkEventSubscribe - public void channelChanged(final MENetworkChannelsChanged c) { - this.updateState(); - } - - @Override - protected int populateFlags(final int cf) { - return cf | (this.prevState ? FLAG_ON : 0); - } - - @Override - public IIcon getBreakingTexture() { - return this.getItemStack().getIconIndex(); - } - - @Override - public void updateWatcher(final ICraftingWatcher newWatcher) { - this.configureWatchers(); - } - - @Override - public void onRequestChange(final ICraftingGrid craftingGrid, final IAEItemStack what) { - this.updateState(); - } - - private IAEFluidStack getIAEFluidStack() { - final FluidStack fs = ItemFluidPacket.getFluidStack(this.config.getAEStackInSlot(0)); - if (fs != null) return Util.FluidUtil.createAEFluidStack(fs); - return null; - } - - // update the system... - private void configureWatchers() { - final IAEFluidStack myStack = this.getIAEFluidStack(); - - if (this.myWatcher != null) { - this.myWatcher.clear(); - } - - try { - this.getProxy().getStorage().getFluidInventory().removeListener(this); - if (this.myWatcher != null && myStack != null) { - this.myWatcher.add(myStack); - } - - if (myStack == null) { - this.getProxy().getStorage().getFluidInventory().addListener(this, this.getProxy().getGrid()); - } - - this.updateReportingValue(this.getProxy().getStorage().getFluidInventory()); - } catch (final GridAccessException ignored) {} - } - - private void updateReportingValue(final IMEMonitor monitor) { - final IAEFluidStack myStack = this.getIAEFluidStack(); - - if (myStack == null) { - this.lastReportedValue = 0; - for (final IAEFluidStack st : monitor.getStorageList()) { - this.lastReportedValue += st.getStackSize(); - } - } else { - final IAEFluidStack r = monitor.getStorageList().findPrecise(myStack); - if (r == null) { - this.lastReportedValue = 0; - } else { - this.lastReportedValue = r.getStackSize(); - } - } - - this.updateState(); - } - - @Override - public void updateWatcher(final IStackWatcher newWatcher) { - this.myWatcher = newWatcher; - this.configureWatchers(); - } - - @Override - public void onStackChange(@SuppressWarnings("rawtypes") final IItemList o, - @SuppressWarnings("rawtypes") final IAEStack fullStack, - @SuppressWarnings("rawtypes") final IAEStack diffStack, final BaseActionSource src, - final StorageChannel chan) { - if (chan == StorageChannel.FLUIDS && fullStack.equals(this.getIAEFluidStack())) { - this.lastReportedValue = fullStack.getStackSize(); - this.updateState(); - } - } - - @Override - public boolean isValid(final Object effectiveGrid) { - try { - return this.getProxy().getGrid() == effectiveGrid; - } catch (final GridAccessException e) { - return false; - } - } - - @Override - public TickingRequest getTickingRequest(IGridNode node) { - return new TickingRequest( - AEConfig.instance.levelEmitterDelay / 2, - AEConfig.instance.levelEmitterDelay, - !delayedUpdatesQueued, - true); - } - - private boolean canDoWork() { - int currentTick = MinecraftServer.getServer().getTickCounter(); - return (currentTick - lastWorkingTick) > AEConfig.instance.levelEmitterDelay; - } - - @Override - public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall) { - if (delayedUpdatesQueued && canDoWork()) { - delayedUpdatesQueued = false; - lastWorkingTick = MinecraftServer.getServer().getTickCounter(); - this.onListUpdate(); - } - return delayedUpdatesQueued ? TickRateModulation.IDLE : TickRateModulation.SLEEP; - } - - @Override - public void postChange(final IBaseMonitor monitor, final Iterable change, - final BaseActionSource actionSource) { - if (canDoWork()) { - if (delayedUpdatesQueued) { - delayedUpdatesQueued = false; - try { - this.getProxy().getTick().sleepDevice(this.getProxy().getNode()); - } catch (GridAccessException e) { - AELog.error(e, "Couldn't put level emitter to sleep after cancelling delayed updates"); - } - } - lastWorkingTick = MinecraftServer.getServer().getTickCounter(); - this.updateReportingValue((IMEMonitor) monitor); - } else if (!delayedUpdatesQueued) { - delayedUpdatesQueued = true; - try { - this.getProxy().getTick().alertDevice(this.getProxy().getNode()); - } catch (GridAccessException e) { - AELog.error(e, "Couldn't wake up level emitter for delayed updates"); - } - } - } - - @Override - public void onListUpdate() { - try { - this.updateReportingValue(this.getProxy().getStorage().getFluidInventory()); - } catch (final GridAccessException ignored) {} - } - - @Override - public AECableType getCableConnectionType(final ForgeDirection dir) { - return AECableType.SMART; - } - - @Override - public void getBoxes(final IPartCollisionHelper bch) { - bch.addBox(7, 7, 11, 9, 9, 16); - } - - @Override - @SideOnly(Side.CLIENT) - public void renderInventory(final IPartRenderHelper rh, final RenderBlocks renderer) { - rh.setTexture(this.getItemStack().getIconIndex()); - final Tessellator tess = Tessellator.instance; - tess.startDrawingQuads(); - this.renderTorchAtAngle(0, -0.5, 0); - tess.draw(); - } - - private void renderTorchAtAngle(double baseX, double baseY, double baseZ) { - final boolean isOn = this.isLevelEmitterOn(); - final IIcon offTexture = this.getItemStack().getIconIndex(); - final IIcon IIcon = (isOn ? CableBusTextures.LevelEmitterTorchOn.getIcon() : offTexture); - this.centerX = baseX + 0.5; - this.centerY = baseY + 0.5; - this.centerZ = baseZ + 0.5; - - baseY += 7.0 / 16.0; - - final float var16 = IIcon.getMinU(); - final float var17 = IIcon.getMaxU(); - final float var18 = IIcon.getMinV(); - final float var19 = IIcon.getMaxV(); - - final double var20b = offTexture.getInterpolatedU(7.0D); - final double var24b = offTexture.getInterpolatedU(9.0D); - - final double var20 = IIcon.getInterpolatedU(7.0D); - final double var24 = IIcon.getInterpolatedU(9.0D); - final double var22 = IIcon.getInterpolatedV(6.0D + (isOn ? 0 : 1.0D)); - final double var26 = IIcon.getInterpolatedV(8.0D + (isOn ? 0 : 1.0D)); - final double var28 = IIcon.getInterpolatedU(7.0D); - final double var30 = IIcon.getInterpolatedV(13.0D); - final double var32 = IIcon.getInterpolatedU(9.0D); - final double var34 = IIcon.getInterpolatedV(15.0D); - - final double var22b = IIcon.getInterpolatedV(9.0D); - final double var26b = IIcon.getInterpolatedV(11.0D); - - baseX += 0.5D; - baseZ += 0.5D; - final double var36 = baseX - 0.5D; - final double var38 = baseX + 0.5D; - final double var40 = baseZ - 0.5D; - final double var42 = baseZ + 0.5D; - - double toff = 0.0d; - - if (!isOn) { - toff = 1.0d / 16.0d; - } - - final Tessellator var12 = Tessellator.instance; - if (isOn) { - var12.setColorOpaque_F(1.0F, 1.0F, 1.0F); - var12.setBrightness(11 << 20 | 11 << 4); - } - - final double TorchLen = 0.625D; - final double var44 = 0.0625D; - final double Zero = 0; - final double par10 = 0; - - final double x = baseX + Zero * (1.0D - TorchLen) - var44; - final double x1 = baseX + Zero * (1.0D - TorchLen) + var44; - - final double y = baseY + TorchLen - toff; - final double var422 = 0.1915D + 1.0 / 16.0; - final double y1 = baseY + var422; - - final double z = baseZ + par10 * (1.0D - TorchLen) - var44; - final double z1 = baseZ + par10 * (1.0D - TorchLen) + var44; - - this.addVertexWithUV(x, y, z, var20, var22); - this.addVertexWithUV(x, y, z1, var20, var26); - this.addVertexWithUV(x1, y, z1, var24, var26); - this.addVertexWithUV(x1, y, z, var24, var22); - - this.addVertexWithUV(x1, y1, z, var24b, var22b); - this.addVertexWithUV(x1, y1, z1, var24b, var26b); - this.addVertexWithUV(x, y1, z1, var20b, var26b); - this.addVertexWithUV(x, y1, z, var20b, var22b); - - this.addVertexWithUV(baseX + var44 + Zero, baseY, baseZ - var44 + par10, var32, var30); - this.addVertexWithUV(baseX + var44 + Zero, baseY, baseZ + var44 + par10, var32, var34); - this.addVertexWithUV(baseX - var44 + Zero, baseY, baseZ + var44 + par10, var28, var34); - this.addVertexWithUV(baseX - var44 + Zero, baseY, baseZ - var44 + par10, var28, var30); - - this.addVertexWithUV(baseX - var44, baseY + 1.0D, var40, var16, var18); - this.addVertexWithUV(baseX - var44 + Zero, baseY + 0.0D, var40 + par10, var16, var19); - this.addVertexWithUV(baseX - var44 + Zero, baseY + 0.0D, var42 + par10, var17, var19); - this.addVertexWithUV(baseX - var44, baseY + 1.0D, var42, var17, var18); - - this.addVertexWithUV(baseX + var44, baseY + 1.0D, var42, var16, var18); - this.addVertexWithUV(baseX + Zero + var44, baseY + 0.0D, var42 + par10, var16, var19); - this.addVertexWithUV(baseX + Zero + var44, baseY + 0.0D, var40 + par10, var17, var19); - this.addVertexWithUV(baseX + var44, baseY + 1.0D, var40, var17, var18); - - this.addVertexWithUV(var36, baseY + 1.0D, baseZ + var44, var16, var18); - this.addVertexWithUV(var36 + Zero, baseY + 0.0D, baseZ + var44 + par10, var16, var19); - this.addVertexWithUV(var38 + Zero, baseY + 0.0D, baseZ + var44 + par10, var17, var19); - this.addVertexWithUV(var38, baseY + 1.0D, baseZ + var44, var17, var18); - - this.addVertexWithUV(var38, baseY + 1.0D, baseZ - var44, var16, var18); - this.addVertexWithUV(var38 + Zero, baseY + 0.0D, baseZ - var44 + par10, var16, var19); - this.addVertexWithUV(var36 + Zero, baseY + 0.0D, baseZ - var44 + par10, var17, var19); - this.addVertexWithUV(var36, baseY + 1.0D, baseZ - var44, var17, var18); - } - - private void addVertexWithUV(double x, double y, double z, final double u, final double v) { - final Tessellator var12 = Tessellator.instance; - - x -= this.centerX; - y -= this.centerY; - z -= this.centerZ; - - if (this.getSide() == ForgeDirection.DOWN) { - y = -y; - z = -z; - } - - if (this.getSide() == ForgeDirection.EAST) { - final double m = x; - x = y; - y = m; - y = -y; - } - - if (this.getSide() == ForgeDirection.WEST) { - final double m = x; - x = -y; - y = m; - } - - if (this.getSide() == ForgeDirection.SOUTH) { - final double m = z; - z = y; - y = m; - y = -y; - } - - if (this.getSide() == ForgeDirection.NORTH) { - final double m = z; - z = -y; - y = m; - } - - x += this.centerX; // + orientation.offsetX * 0.4; - y += this.centerY; // + orientation.offsetY * 0.4; - z += this.centerZ; // + orientation.offsetZ * 0.4; - - var12.addVertexWithUV(x, y, z, u, v); - } - - @Override - @SideOnly(Side.CLIENT) - public void renderStatic(final int x, final int y, final int z, final IPartRenderHelper rh, - final RenderBlocks renderer) { - rh.setTexture(this.getItemStack().getIconIndex()); - - renderer.renderAllFaces = true; - - final Tessellator tess = Tessellator.instance; - tess.setBrightness(rh.getBlock().getMixedBrightnessForBlock(this.getHost().getTile().getWorldObj(), x, y, z)); - tess.setColorOpaque_F(1.0F, 1.0F, 1.0F); - - this.renderTorchAtAngle(x, y, z); - - renderer.renderAllFaces = false; - - rh.setBounds(7, 7, 11, 9, 9, 12); - this.renderLights(x, y, z, rh, renderer); - } - - @Override - public int isProvidingStrongPower() { - return this.prevState ? 15 : 0; - } - - @Override - public int isProvidingWeakPower() { - return this.prevState ? 15 : 0; - } - - @Override - public void randomDisplayTick(final World world, final int x, final int y, final int z, final Random r) { - if (this.isLevelEmitterOn()) { - final ForgeDirection d = this.getSide(); - - final double d0 = d.offsetX * 0.45F + (r.nextFloat() - 0.5F) * 0.2D; - final double d1 = d.offsetY * 0.45F + (r.nextFloat() - 0.5F) * 0.2D; - final double d2 = d.offsetZ * 0.45F + (r.nextFloat() - 0.5F) * 0.2D; - - world.spawnParticle("reddust", 0.5 + x + d0, 0.5 + y + d1, 0.5 + z + d2, 0.0D, 0.0D, 0.0D); - } - } - - @Override - public int cableConnectionRenderTo() { - return 16; - } - - @Override - public boolean onPartActivate(final EntityPlayer player, final Vec3 pos) { - if (!player.isSneaking()) { - if (Platform.isClient()) { - return true; - } - InventoryHandler.openGui( - player, - this.getHost().getTile().getWorldObj(), - new BlockPos(this.getHost().getTile()), - Objects.requireNonNull(getSide()), - GuiType.FLUID_LEVEL_EMITTER); - return true; - } - - return false; - } - - @Override - public void updateSetting(final IConfigManager manager, @SuppressWarnings("rawtypes") final Enum settingName, - @SuppressWarnings("rawtypes") final Enum newValue) { - this.configureWatchers(); - } - - @Override - public void onChangeInventory(final IInventory inv, final int slot, final InvOperation mc, - final ItemStack removedStack, final ItemStack newStack) { - if (inv == this.config) { - this.configureWatchers(); - } - super.onChangeInventory(inv, slot, mc, removedStack, newStack); - } - - @Override - public void upgradesChanged() { - this.configureWatchers(); - } - - @Override - public boolean canConnectRedstone() { - return true; - } - - @Override - public void readFromNBT(final NBTTagCompound data) { - super.readFromNBT(data); - this.lastReportedValue = data.getLong("lastReportedValue"); - this.reportingValue = data.getLong("reportingValue"); - this.prevState = data.getBoolean("prevState"); - this.config.readFromNBT(data, "config"); - } - - @Override - public void writeToNBT(final NBTTagCompound data) { - super.writeToNBT(data); - data.setLong("lastReportedValue", this.lastReportedValue); - data.setLong("reportingValue", this.reportingValue); - data.setBoolean("prevState", this.prevState); - this.config.writeToNBT(data, "config"); - } - - public void setFluidInSlot(int id, IAEFluidStack fluid) { - ItemStack tmp = ItemFluidPacket.newDisplayStack(fluid == null ? null : fluid.getFluidStack()); - this.config.setInventorySlotContents(id, tmp); - } - - @Override - public IInventory getInventoryByName(final String name) { - if (name.equals("config")) { - return this.config; - } - - return super.getInventoryByName(name); - } - - @Override - public LevelItemInfo[] getLevelItemInfoList() { - ItemStack stack = this.config.getStackInSlot(0); - if (stack == null) return new LevelItemInfo[] { null }; - return new LevelItemInfo[] { new LevelItemInfo( - stack, - this.getReportingValue(), - -1, - this.isProvidingStrongPower() > 0 ? LevelState.Craft : LevelState.Idle) }; } } diff --git a/src/main/java/com/glodblock/github/common/parts/PartFluidP2PInterface.java b/src/main/java/com/glodblock/github/common/parts/PartFluidP2PInterface.java index 056228e2..dcc8a5fc 100644 --- a/src/main/java/com/glodblock/github/common/parts/PartFluidP2PInterface.java +++ b/src/main/java/com/glodblock/github/common/parts/PartFluidP2PInterface.java @@ -1,279 +1,53 @@ package com.glodblock.github.common.parts; -import static appeng.helpers.DualityInterface.NUMBER_OF_STORAGE_SLOTS; - -import java.util.ArrayList; -import java.util.EnumSet; import java.util.List; -import java.util.Objects; +import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.ISidedInventory; -import net.minecraft.inventory.InventoryCrafting; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; import net.minecraft.util.IIcon; -import net.minecraft.util.Vec3; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTankInfo; +import com.glodblock.github.client.FluidInterfaceButtons; import com.glodblock.github.common.item.ItemFluidPacket; import com.glodblock.github.inventory.AEFluidInventory; import com.glodblock.github.inventory.IAEFluidTank; import com.glodblock.github.inventory.IDualHost; -import com.glodblock.github.inventory.InventoryHandler; -import com.glodblock.github.inventory.gui.GuiType; import com.glodblock.github.loader.ItemAndBlockHolder; -import com.glodblock.github.util.BlockPos; import com.glodblock.github.util.DualityFluidInterface; import com.glodblock.github.util.Util; -import com.google.common.collect.ImmutableSet; -import appeng.api.config.Actionable; -import appeng.api.config.Upgrades; import appeng.api.implementations.items.IMemoryCard; -import appeng.api.implementations.tiles.ITileStorageMonitorable; import appeng.api.networking.IGridNode; -import appeng.api.networking.crafting.ICraftingLink; -import appeng.api.networking.crafting.ICraftingPatternDetails; -import appeng.api.networking.crafting.ICraftingProviderHelper; -import appeng.api.networking.events.MENetworkChannelsChanged; -import appeng.api.networking.events.MENetworkCraftingPatternChange; -import appeng.api.networking.events.MENetworkEventSubscribe; -import appeng.api.networking.events.MENetworkPowerStatusChange; -import appeng.api.networking.security.BaseActionSource; -import appeng.api.networking.ticking.IGridTickable; import appeng.api.networking.ticking.TickRateModulation; import appeng.api.networking.ticking.TickingRequest; -import appeng.api.storage.IMEMonitor; -import appeng.api.storage.IStorageMonitorable; import appeng.api.storage.data.IAEFluidStack; -import appeng.api.storage.data.IAEItemStack; -import appeng.api.storage.data.IAEStack; import appeng.api.util.IConfigManager; import appeng.helpers.DualityInterface; -import appeng.helpers.IInterfaceHost; -import appeng.helpers.IPriorityHost; -import appeng.me.GridAccessException; -import appeng.me.cache.CraftingGridCache; -import appeng.parts.automation.UpgradeInventory; +import appeng.helpers.ICustomButtonDataObject; +import appeng.helpers.ICustomButtonProvider; +import appeng.parts.p2p.PartP2PInterface; import appeng.parts.p2p.PartP2PTunnel; -import appeng.parts.p2p.PartP2PTunnelStatic; import appeng.tile.inventory.AppEngInternalAEInventory; -import appeng.tile.inventory.AppEngInternalInventory; -import appeng.tile.inventory.IAEAppEngInventory; -import appeng.tile.inventory.InvOperation; import appeng.util.Platform; -import appeng.util.inv.AdaptorIInventory; -import appeng.util.inv.IInventoryDestination; -import appeng.util.inv.WrapperInvSlot; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -public class PartFluidP2PInterface extends PartP2PTunnelStatic - implements IGridTickable, IStorageMonitorable, IInventoryDestination, IDualHost, ISidedInventory, - IAEAppEngInventory, ITileStorageMonitorable, IPriorityHost, IInterfaceHost { +public class PartFluidP2PInterface extends PartP2PInterface implements IDualHost, ICustomButtonProvider { - boolean needUpdateOnNetworkBooted = false; - boolean lastPowerStart = false; - - public PartFluidP2PInterface(ItemStack is) { - super(is); - } - - private final DualityInterface duality = new DualityInterface(this.getProxy(), this) { - - @Override - public void updateCraftingList() { - if (!isOutput()) { - CraftingGridCache.pauseRebuilds(); - - super.updateCraftingList(); - - try { - for (PartFluidP2PInterface p2p : getOutputs()) { - p2p.duality.updateCraftingList(); - } - } catch (GridAccessException e) { - // ? - } - - CraftingGridCache.unpauseRebuilds(); - } else { - PartFluidP2PInterface p2p = getInput(); - if (p2p != null) { - this.craftingList = p2p.duality.craftingList; - try { - this.gridProxy.getGrid() - .postEvent(new MENetworkCraftingPatternChange(this, this.gridProxy.getNode())); - } catch (final GridAccessException e) { - // :P - } - } - } - } - - @Override - public TickRateModulation tickingRequest(IGridNode node, int ticksSinceLastCall) { - final boolean powerState = proxy.isActive(); - if (needUpdateOnNetworkBooted || lastPowerStart != powerState) { - needUpdateOnNetworkBooted = false; - lastPowerStart = powerState; - updateSharingInventory(); - } - return super.tickingRequest(node, ticksSinceLastCall); - } - - @Override - protected boolean hasWorkToDo() { - if (isOutput()) { - return hasItemsToSend() || hasConfig() || !getStorage().isEmpty(); - } else return super.hasWorkToDo(); - } - - @Override - public void readConfig() { - if (isOutput()) { - PartFluidP2PInterface p2p = getInput(); - boolean alertDevice = false; - - if (p2p != null) { - this.setHasConfig(p2p.duality.hasConfig()); - - alertDevice = hasWorkToDo(); - - } else { - this.setHasConfig(false); - } - - if (alertDevice) { - try { - this.gridProxy.getTick().alertDevice(this.gridProxy.getNode()); - } catch (final GridAccessException ignored) {} - } else { - try { - this.gridProxy.getTick().sleepDevice(this.gridProxy.getNode()); - } catch (final GridAccessException ignored) {} - } - - this.notifyNeighbors(); - } else { - super.readConfig(); - } - } - - @Override - public void addDrops(final List drops) { - if (!isOutput()) { - super.addDrops(drops); - try { - for (PartFluidP2PInterface p2p : getOutputs()) p2p.duality.addDrops(drops); - } catch (GridAccessException ignored) {} - } else { - List> waitingList = this.getWaitingToSend(); - if (waitingList != null) { - for (final IAEStack as : waitingList) { - if (as instanceof IAEItemStack ais) { - drops.add(ais.getItemStack()); - } else if (as instanceof IAEFluidStack afs) { - drops.add(ItemFluidPacket.newStack(afs)); - } - } - } - - for (final ItemStack is : this.getUpgrades()) { - if (is != null) { - drops.add(is); - } - } - - for (final ItemStack is : this.getPatterns()) { - if (is != null) { - drops.add(is); - } - } - } - } - - @Override - public int getInstalledUpgrades(Upgrades u) { - if (isOutput() && u == Upgrades.PATTERN_CAPACITY) return -1; - return super.getInstalledUpgrades(u); - } - - @Override - public int getConfigSize() { - if (isOutput()) return -1; - return super.getConfigSize(); - } - }; private final DualityFluidInterface dualityFluid = new DualityFluidInterface(this.getProxy(), this); private final AppEngInternalAEInventory config = new AppEngInternalAEInventory(this, 6); - private void updateSharingInventory() { - duality.readConfig(); - if (isOutput()) { - PartFluidP2PInterface p2p = getInput(); - if (proxy.isActive() && p2p != null) { - if (!duality.sharedInventory && !duality.getStorage().isEmpty()) { - ArrayList drops = new ArrayList<>(); - AppEngInternalInventory storageAppEng = this.duality.getStorage(); - AdaptorIInventory p2pInv = new AdaptorIInventory(p2p.duality.getStorage()); - for (ItemStack itemStack : storageAppEng) { - if (itemStack == null) continue; - ItemStack drop = p2pInv.addItems(itemStack); - if (drop != null && drop.stackSize > 0) { - drops.add(drop); - } - } - TileEntity te = getTileEntity(); - Platform.spawnDrops(te.getWorldObj(), te.xCoord, te.yCoord, te.zCoord, drops); - } - duality.setStorage(p2p.duality.getStorage()); - duality.setSlotInv(p2p.duality.getSlotInv()); - duality.sharedInventory = true; - } else { - if (duality.sharedInventory) { - duality.setStorage(new AppEngInternalInventory(this, NUMBER_OF_STORAGE_SLOTS)); - duality.setSlotInv(new WrapperInvSlot(duality.getStorage())); - duality.sharedInventory = false; - } - } - } else { - if (duality.sharedInventory) { - duality.setStorage(new AppEngInternalInventory(this, NUMBER_OF_STORAGE_SLOTS)); - duality.setSlotInv(new WrapperInvSlot(duality.getStorage())); - duality.sharedInventory = false; - } - try { - for (PartFluidP2PInterface p2p : getOutputs()) { - p2p.duality.readConfig(); - } - } catch (GridAccessException ignored) {} - } - } + private ICustomButtonDataObject customButtonDataObject; - @MENetworkEventSubscribe - public void stateChange(final MENetworkChannelsChanged c) { - this.duality.notifyNeighbors(); - updateSharingInventory(); - needUpdateOnNetworkBooted = true; - } + public PartFluidP2PInterface(ItemStack is) { + super(is); - @MENetworkEventSubscribe - public void stateChange(final MENetworkPowerStatusChange c) { - this.duality.notifyNeighbors(); - updateSharingInventory(); - needUpdateOnNetworkBooted = true; - } - - @Override - public int getInstalledUpgrades(final Upgrades u) { - return this.duality.getInstalledUpgrades(u); + this.customButtonDataObject = new FluidInterfaceButtons(false); } @Override @@ -282,31 +56,6 @@ public class PartFluidP2PInterface extends PartP2PTunnelStatic applyMemoryCard(EntityPlayer player, IMemoryCard memoryCard, ItemStack is) { PartP2PTunnel newTunnel = super.applyMemoryCard(player, memoryCard, is); @@ -318,112 +67,6 @@ public class PartFluidP2PInterface extends PartP2PTunnelStatic drops, final boolean wrenched) { - this.duality.addDrops(drops); - } - - @Override - public int cableConnectionRenderTo() { - return 4; - } - - @Override - public IConfigManager getConfigManager() { - return this.duality.getConfigManager(); - } - - @Override - public IInventory getInventoryByName(final String name) { - return this.duality.getInventoryByName(name); - } - - @Override - public void onNeighborChanged() { - this.duality.updateRedstoneState(); - } - - @Override - public boolean onPartActivate(final EntityPlayer p, final Vec3 pos) { - if (super.onPartActivate(p, pos)) { - return true; - } - - if (p.isSneaking()) { - return false; - } - - if (Platform.isServer()) { - InventoryHandler.openGui( - p, - this.getHost().getTile().getWorldObj(), - new BlockPos(this.getHost().getTile()), - Objects.requireNonNull(this.getSide()), - GuiType.DUAL_INTERFACE); - } - - return true; - } - - private void dropPatterns(final PartFluidP2PInterface p2p) { - final AppEngInternalInventory patterns = p2p.duality.getPatterns(); - final List drops = new ArrayList<>(); - for (int i = 0; i < patterns.getSizeInventory(); i++) { - if (patterns.getStackInSlot(i) == null) continue; - drops.add(patterns.getStackInSlot(i)); - } - if (!drops.isEmpty()) { - final TileEntity te = p2p.getTileEntity(); - Platform.spawnDrops(te.getWorldObj(), te.xCoord, te.yCoord, te.zCoord, drops); - } - } - - @Override - protected void copyContents(final PartP2PTunnel from) { - if (from instanceof PartFluidP2PInterface fromInterface) { - DualityInterface newDuality = this.duality; - // Copy interface storage, upgrades, and settings over - UpgradeInventory upgrades = (UpgradeInventory) fromInterface.duality.getInventoryByName("upgrades"); - UpgradeInventory newUpgrade = (UpgradeInventory) newDuality.getInventoryByName("upgrades"); - for (int i = 0; i < upgrades.getSizeInventory(); ++i) { - newUpgrade.setInventorySlotContents(i, upgrades.getStackInSlot(i)); - } - - if (!fromInterface.duality.sharedInventory) { - IInventory storage = fromInterface.duality.getStorage(); - IInventory newStorage = newDuality.getStorage(); - for (int i = 0; i < storage.getSizeInventory(); ++i) { - newStorage.setInventorySlotContents(i, storage.getStackInSlot(i)); - } - - IInventory config = fromInterface.duality.getInventoryByName("config"); - IInventory newConfig = newDuality.getInventoryByName("config"); - for (int i = 0; i < config.getSizeInventory(); ++i) { - newConfig.setInventorySlotContents(i, config.getStackInSlot(i)); - } - } - - AppEngInternalInventory patterns = fromInterface.duality.getPatterns(); - boolean drop = true; - if (!from.isOutput() && !this.isOutput()) { // input to input - for (int i = 0; i < patterns.getSizeInventory(); i++) { - newDuality.getPatterns().setInventorySlotContents(i, patterns.getStackInSlot(i)); - } - drop = false; - } - - if (drop) { - this.dropPatterns(fromInterface); - } - } - } - @Override protected void copySettings(final PartP2PTunnel from) { if (from instanceof PartFluidP2PInterface fromInterface) { @@ -435,26 +78,6 @@ public class PartFluidP2PInterface extends PartP2PTunnelStatic getItemInventory() { - return this.duality.getItemInventory(); - } - - @Override - public IMEMonitor getFluidInventory() { - return this.duality.getFluidInventory(); - } - @Override public TickingRequest getTickingRequest(IGridNode node) { TickingRequest item = duality.getTickingRequest(node); @@ -477,216 +100,6 @@ public class PartFluidP2PInterface extends PartP2PTunnelStatic getTargets() { - return EnumSet.of(this.getSide()); - } - - @Override - public TileEntity getTileEntity() { - return super.getHost().getTile(); - } - - @Override - public IStorageMonitorable getMonitorable(final ForgeDirection side, final BaseActionSource src) { - return this.duality.getMonitorable(side, src, this); - } - - @Override - public boolean pushPattern(final ICraftingPatternDetails patternDetails, final InventoryCrafting table) { - return this.duality.pushPattern(patternDetails, table); - } - - @Override - public boolean isBusy() { - return this.duality.isBusy(); - } - - @Override - public void provideCrafting(final ICraftingProviderHelper craftingTracker) { - this.duality.provideCrafting(craftingTracker); - } - - @Override - public ImmutableSet getRequestedJobs() { - return this.duality.getRequestedJobs(); - } - - @Override - public IAEItemStack injectCraftedItems(final ICraftingLink link, final IAEItemStack items, final Actionable mode) { - return this.duality.injectCraftedItems(link, items, mode); - } - - @Override - public void jobStateChange(final ICraftingLink link) { - this.duality.jobStateChange(link); - } - - @Override - public int getPriority() { - return this.duality.getPriority(); - } - - @Override - public void setPriority(final int newValue) { - this.duality.setPriority(newValue); - } - - @Override - public void onTunnelNetworkChange() { - this.duality.updateCraftingList(); - updateSharingInventory(); - } - - @Override - public void onTunnelConfigChange() { - updateSharingInventory(); - } - - @Override - public IInventory getPatterns() { - if (isOutput()) { - PartFluidP2PInterface input = getInput(); - if (input != null) { - return input.getPatterns(); - } - return IInterfaceHost.super.getPatterns(); - } - return IInterfaceHost.super.getPatterns(); - } - - @Override - public int rows() { - if (isOutput()) { - PartFluidP2PInterface input = getInput(); - if (input != null) { - return input.rows(); - } - return IInterfaceHost.super.rows(); - } - return IInterfaceHost.super.rows(); - } - - @Override - public int rowSize() { - if (isOutput()) { - PartFluidP2PInterface input = getInput(); - if (input != null) { - return input.rowSize(); - } - return IInterfaceHost.super.rowSize(); - } - return IInterfaceHost.super.rowSize(); - } - - @Override - public String getName() { - if (isOutput()) { - PartFluidP2PInterface input = getInput(); - if (input != null) { - return input.getName(); - } - return IInterfaceHost.super.getName(); - } - return IInterfaceHost.super.getName(); - } - - @Override - public ItemStack getSelfRep() { - return this.getItemStack(); - } - @Override public int fill(ForgeDirection from, FluidStack resource, boolean doFill) { return dualityFluid.fill(from, resource, doFill); @@ -758,8 +171,36 @@ public class PartFluidP2PInterface extends PartP2PTunnelStatic buttonList) { + if (customButtonDataObject != null) + customButtonDataObject.initCustomButtons(guiLeft, guiTop, xSize, ySize, xOffset, yOffset, buttonList); + } + + @SideOnly(Side.CLIENT) + @Override + public boolean actionPerformedCustomButtons(final GuiButton btn) { + return customButtonDataObject != null && customButtonDataObject.actionPerformedCustomButtons(btn); + } + + @Override + public ICustomButtonDataObject getDataObject() { + return customButtonDataObject; + } + + @Override + public void setDataObject(ICustomButtonDataObject dataObject) { + customButtonDataObject = dataObject; + } } diff --git a/src/main/java/com/glodblock/github/common/parts/PartFluidPatternTerminal.java b/src/main/java/com/glodblock/github/common/parts/PartFluidPatternTerminal.java index 5a8a8f64..8e3fffce 100644 --- a/src/main/java/com/glodblock/github/common/parts/PartFluidPatternTerminal.java +++ b/src/main/java/com/glodblock/github/common/parts/PartFluidPatternTerminal.java @@ -1,161 +1,13 @@ package com.glodblock.github.common.parts; -import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import com.glodblock.github.client.textures.FCPartsTexture; -import com.glodblock.github.common.item.ItemFluidDrop; -import com.glodblock.github.common.item.ItemFluidPacket; -import com.glodblock.github.common.parts.base.FCFluidEncodeTerminal; -import com.glodblock.github.inventory.gui.GuiType; +import appeng.parts.reporting.PartPatternTerminal; -import appeng.api.implementations.ICraftingPatternItem; -import appeng.api.networking.crafting.ICraftingPatternDetails; -import appeng.api.storage.data.IAEItemStack; -import appeng.tile.inventory.BiggerAppEngInventory; -import appeng.tile.inventory.InvOperation; - -public class PartFluidPatternTerminal extends FCFluidEncodeTerminal { - - private static final FCPartsTexture FRONT_BRIGHT_ICON = FCPartsTexture.PartFluidPatternTerminal_Bright; - private static final FCPartsTexture FRONT_DARK_ICON = FCPartsTexture.PartFluidPatternTerminal_Colored; - private static final FCPartsTexture FRONT_COLORED_ICON = FCPartsTexture.PartFluidPatternTerminal_Dark; +public class PartFluidPatternTerminal extends PartPatternTerminal { public PartFluidPatternTerminal(ItemStack is) { super(is); - this.crafting = new BiggerAppEngInventory(this, 9); - this.output = new BiggerAppEngInventory(this, 3); - this.prioritize = false; - this.inverted = false; - this.activePage = 0; } - @Override - public GuiType getGui() { - return GuiType.FLUID_PATTERN_TERMINAL; - } - - @Override - public void onChangeInventory(final IInventory inv, final int slot, final InvOperation mc, - final ItemStack removedStack, final ItemStack newStack) { - if (inv == this.pattern && slot == 1) { - final ItemStack is = inv.getStackInSlot(1); - if (is != null && is.getItem() instanceof final ICraftingPatternItem craftingPatternItem) { - final ICraftingPatternDetails details = craftingPatternItem - .getPatternForItem(is, this.getHost().getTile().getWorldObj()); - if (details != null) { - final IAEItemStack[] inItems = details.getInputs(); - final IAEItemStack[] outItems = details.getOutputs(); - - this.setCraftingRecipe(details.isCraftable()); - this.setSubstitution(details.canSubstitute()); - if (newStack != null) { - NBTTagCompound data = newStack.getTagCompound(); - this.setCombineMode(data.getInteger("combine") == 1); - this.setBeSubstitute(details.canBeSubstitute()); - } - for (int i = 0; i < this.crafting.getSizeInventory(); i++) { - this.crafting.setInventorySlotContents(i, null); - } - - for (int i = 0; i < this.output.getSizeInventory(); i++) { - this.output.setInventorySlotContents(i, null); - } - - for (int i = 0; i < this.crafting.getSizeInventory() && i < inItems.length; i++) { - if (inItems[i] != null) { - final IAEItemStack item = inItems[i]; - if (item != null && item.getItem() instanceof ItemFluidDrop) { - ItemStack packet = ItemFluidPacket - .newStack(ItemFluidDrop.getFluidStack(item.getItemStack())); - this.crafting.setInventorySlotContents(i, packet); - } else this.crafting.setInventorySlotContents(i, item == null ? null : item.getItemStack()); - } - } - - for (int i = 0; i < this.output.getSizeInventory() && i < outItems.length; i++) { - if (outItems[i] != null) { - final IAEItemStack item = outItems[i]; - if (item != null && item.getItem() instanceof ItemFluidDrop) { - ItemStack packet = ItemFluidPacket - .newStack(ItemFluidDrop.getFluidStack(item.getItemStack())); - this.output.setInventorySlotContents(i, packet); - } else this.output.setInventorySlotContents(i, item == null ? null : item.getItemStack()); - } - } - } - } - } - if (inv == this.crafting) { - this.fixCraftingRecipes(); - } - this.getHost().markForSave(); - } - - private void fixCraftingRecipes() { - if (this.craftingMode) { - for (int x = 0; x < this.crafting.getSizeInventory(); x++) { - final ItemStack is = this.crafting.getStackInSlot(x); - if (is != null) { - is.stackSize = 1; - } - } - } - } - - public void setCraftingRecipe(final boolean craftingMode) { - super.setCraftingRecipe(craftingMode); - this.fixCraftingRecipes(); - } - - @Override - public void setPrioritization(boolean canPrioritize) { - this.prioritize = false; - } - - @Override - public boolean isPrioritize() { - return false; - } - - @Override - public boolean isInverted() { - return false; - } - - @Override - public void setInverted(boolean inverted) { - this.inverted = false; - } - - @Override - public int getActivePage() { - return 0; - } - - @Override - public void setActivePage(int activePage) { - this.activePage = 0; - } - - @Override - public FCPartsTexture getFrontBright() { - return FRONT_BRIGHT_ICON; - } - - @Override - public FCPartsTexture getFrontColored() { - return FRONT_COLORED_ICON; - } - - @Override - public FCPartsTexture getFrontDark() { - return FRONT_DARK_ICON; - } - - @Override - public boolean isLightSource() { - return false; - } } diff --git a/src/main/java/com/glodblock/github/common/parts/PartFluidPatternTerminalEx.java b/src/main/java/com/glodblock/github/common/parts/PartFluidPatternTerminalEx.java index 6edf61db..7cbf950b 100644 --- a/src/main/java/com/glodblock/github/common/parts/PartFluidPatternTerminalEx.java +++ b/src/main/java/com/glodblock/github/common/parts/PartFluidPatternTerminalEx.java @@ -1,149 +1,12 @@ package com.glodblock.github.common.parts; -import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import com.glodblock.github.client.textures.FCPartsTexture; -import com.glodblock.github.common.item.ItemFluidDrop; -import com.glodblock.github.common.item.ItemFluidPacket; -import com.glodblock.github.common.parts.base.FCFluidEncodeTerminal; -import com.glodblock.github.inventory.gui.GuiType; +import appeng.parts.reporting.PartPatternTerminalEx; -import appeng.api.implementations.ICraftingPatternItem; -import appeng.api.networking.crafting.ICraftingPatternDetails; -import appeng.api.storage.data.IAEItemStack; -import appeng.tile.inventory.BiggerAppEngInventory; -import appeng.tile.inventory.InvOperation; - -public class PartFluidPatternTerminalEx extends FCFluidEncodeTerminal { - - private static final FCPartsTexture FRONT_BRIGHT_ICON = FCPartsTexture.PartFluidPatternTerminal_Bright; - private static final FCPartsTexture FRONT_DARK_ICON = FCPartsTexture.PartFluidPatternTerminal_Colored; - private static final FCPartsTexture FRONT_COLORED_ICON = FCPartsTexture.PartFluidPatternTerminal_Dark; +public class PartFluidPatternTerminalEx extends PartPatternTerminalEx { public PartFluidPatternTerminalEx(ItemStack is) { super(is); - this.crafting = new BiggerAppEngInventory(this, 32); - this.output = new BiggerAppEngInventory(this, 32); - this.craftingMode = false; - } - - @Override - public GuiType getGui() { - return GuiType.FLUID_PATTERN_TERMINAL_EX; - } - - @Override - public void onChangeInventory(final IInventory inv, final int slot, final InvOperation mc, - final ItemStack removedStack, final ItemStack newStack) { - if (inv == this.pattern && slot == 1) { - final ItemStack is = inv.getStackInSlot(1); - - if (is != null && is.getItem() instanceof final ICraftingPatternItem craftingPatternItem) { - final ICraftingPatternDetails details = craftingPatternItem - .getPatternForItem(is, this.getHost().getTile().getWorldObj()); - - if (details != null) { - final IAEItemStack[] inItems = details.getInputs(); - final IAEItemStack[] outItems = details.getOutputs(); - int inputsCount = 0; - int outputCount = 0; - for (IAEItemStack inItem : inItems) { - if (inItem != null) { - inputsCount++; - } - } - for (IAEItemStack outItem : outItems) { - if (outItem != null) { - outputCount++; - } - } - - this.setSubstitution(details.canSubstitute()); - if (newStack != null) { - NBTTagCompound data = newStack.getTagCompound(); - this.setCombineMode(data.getInteger("combine") == 1); - this.setBeSubstitute(details.canBeSubstitute()); - } - this.setInverted(inputsCount <= 8 && outputCount > 8); - this.setActivePage(0); - - for (int i = 0; i < this.crafting.getSizeInventory(); i++) { - this.crafting.setInventorySlotContents(i, null); - } - - for (int i = 0; i < this.output.getSizeInventory(); i++) { - this.output.setInventorySlotContents(i, null); - } - - for (int i = 0; i < this.crafting.getSizeInventory() && i < inItems.length; i++) { - final IAEItemStack item = inItems[i]; - if (item != null) { - if (item.getItem() instanceof ItemFluidDrop) { - ItemStack packet = ItemFluidPacket - .newStack(ItemFluidDrop.getFluidStack(item.getItemStack())); - this.crafting.setInventorySlotContents(i, packet); - } else this.crafting.setInventorySlotContents(i, item.getItemStack()); - } - } - - if (inverted) { - for (int i = 0; i < this.output.getSizeInventory() && i < outItems.length; i++) { - final IAEItemStack item = outItems[i]; - if (item != null) { - if (item.getItem() instanceof ItemFluidDrop) { - ItemStack packet = ItemFluidPacket - .newStack(ItemFluidDrop.getFluidStack(item.getItemStack())); - this.output.setInventorySlotContents(i, packet); - } else this.output.setInventorySlotContents(i, item.getItemStack()); - } - } - } else { - for (int i = 0; i < outItems.length && i < 8; i++) { - final IAEItemStack item = outItems[i]; - if (item != null) { - if (item.getItem() instanceof ItemFluidDrop) { - ItemStack packet = ItemFluidPacket - .newStack(ItemFluidDrop.getFluidStack(item.getItemStack())); - this.output.setInventorySlotContents(i >= 4 ? 12 + i : i, packet); - } else this.output.setInventorySlotContents(i >= 4 ? 12 + i : i, item.getItemStack()); - } - } - } - } - } - } - this.getHost().markForSave(); - } - - @Override - public void setCraftingRecipe(final boolean craftingMode) { - this.craftingMode = false; - } - - @Override - public boolean isCraftingRecipe() { - return false; - } - - @Override - public FCPartsTexture getFrontBright() { - return FRONT_BRIGHT_ICON; - } - - @Override - public FCPartsTexture getFrontColored() { - return FRONT_COLORED_ICON; - } - - @Override - public FCPartsTexture getFrontDark() { - return FRONT_DARK_ICON; - } - - @Override - public boolean isLightSource() { - return false; } } diff --git a/src/main/java/com/glodblock/github/common/parts/PartFluidStorageBus.java b/src/main/java/com/glodblock/github/common/parts/PartFluidStorageBus.java index 09f6c43d..702367ac 100644 --- a/src/main/java/com/glodblock/github/common/parts/PartFluidStorageBus.java +++ b/src/main/java/com/glodblock/github/common/parts/PartFluidStorageBus.java @@ -1,529 +1,18 @@ package com.glodblock.github.common.parts; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Objects; -import java.util.function.Predicate; - -import javax.annotation.Nullable; - -import net.minecraft.client.renderer.RenderBlocks; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.Vec3; -import com.glodblock.github.client.textures.FCPartsTexture; -import com.glodblock.github.common.item.ItemFluidPacket; -import com.glodblock.github.inventory.InventoryHandler; -import com.glodblock.github.inventory.MEMonitorIFluidHandler; -import com.glodblock.github.inventory.gui.GuiType; -import com.glodblock.github.util.BlockPos; - -import appeng.api.AEApi; -import appeng.api.config.AccessRestriction; -import appeng.api.config.FuzzyMode; -import appeng.api.config.IncludeExclude; -import appeng.api.config.Settings; -import appeng.api.config.StorageFilter; -import appeng.api.config.Upgrades; -import appeng.api.config.YesNo; -import appeng.api.networking.IGridNode; -import appeng.api.networking.events.MENetworkCellArrayUpdate; -import appeng.api.networking.events.MENetworkChannelsChanged; -import appeng.api.networking.events.MENetworkEventSubscribe; -import appeng.api.networking.events.MENetworkPowerStatusChange; -import appeng.api.networking.security.BaseActionSource; -import appeng.api.networking.security.MachineSource; -import appeng.api.networking.storage.IBaseMonitor; -import appeng.api.networking.storage.IStorageGrid; -import appeng.api.networking.ticking.IGridTickable; -import appeng.api.networking.ticking.ITickManager; -import appeng.api.networking.ticking.TickRateModulation; -import appeng.api.networking.ticking.TickingRequest; -import appeng.api.parts.IPartCollisionHelper; -import appeng.api.parts.IPartRenderHelper; -import appeng.api.parts.PartItemStack; -import appeng.api.storage.ICellContainer; -import appeng.api.storage.IExternalStorageHandler; -import appeng.api.storage.IMEInventory; -import appeng.api.storage.IMEInventoryHandler; -import appeng.api.storage.IMEMonitor; -import appeng.api.storage.IMEMonitorHandlerReceiver; import appeng.api.storage.StorageChannel; -import appeng.api.storage.data.IAEFluidStack; -import appeng.api.storage.data.IAEItemStack; -import appeng.api.storage.data.IItemList; -import appeng.api.util.IConfigManager; -import appeng.client.texture.CableBusTextures; -import appeng.core.settings.TickRates; -import appeng.helpers.IPriorityHost; -import appeng.me.GridAccessException; -import appeng.me.cache.GridStorageCache; -import appeng.me.storage.MEInventoryHandler; -import appeng.me.storage.StorageBusInventoryHandler; -import appeng.parts.automation.PartUpgradeable; -import appeng.tile.inventory.AppEngInternalAEInventory; -import appeng.tile.inventory.InvOperation; -import appeng.util.IterationCounter; -import appeng.util.Platform; -import appeng.util.item.AEFluidStack; -import appeng.util.prioitylist.PrecisePriorityList; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; +import appeng.parts.misc.PartStorageBus; -public class PartFluidStorageBus extends PartUpgradeable - implements IGridTickable, ICellContainer, IMEMonitorHandlerReceiver, IPriorityHost { - - private final BaseActionSource source; - private final AppEngInternalAEInventory config = new AppEngInternalAEInventory(this, 63); - private int priority = 0; - private boolean cached = false; - private MEMonitorIFluidHandler monitor = null; - private MEInventoryHandler handler = null; - private int handlerHash = 0; - private boolean wasActive = false; - private byte resetCacheLogic = 0; - /** - * used to read changes once when the list of extractable items was changed - */ - private boolean readOncePass = false; +public class PartFluidStorageBus extends PartStorageBus { public PartFluidStorageBus(ItemStack is) { super(is); - this.getConfigManager().registerSetting(Settings.ACCESS, AccessRestriction.READ_WRITE); - this.getConfigManager().registerSetting(Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL); - this.getConfigManager().registerSetting(Settings.STORAGE_FILTER, StorageFilter.EXTRACTABLE_ONLY); - this.getConfigManager().registerSetting(Settings.STICKY_MODE, YesNo.NO); - this.source = new MachineSource(this); - if (is.getTagCompound() != null) { - NBTTagCompound tag = is.getTagCompound(); - if (tag.hasKey("priority")) { - priority = tag.getInteger("priority"); - // if we don't do this, the tag will stick forever to the storage bus, as it's never cleaned up, - // even when the item is broken with a pickaxe - this.is.setTagCompound(null); - } - } } @Override - public ItemStack getItemStack(final PartItemStack type) { - if (type == PartItemStack.Wrench) { - final NBTTagCompound tag = new NBTTagCompound(); - tag.setInteger("priority", priority); - final ItemStack copy = this.is.copy(); - copy.setTagCompound(tag); - return copy; - } - return super.getItemStack(type); - } - - @Override - @MENetworkEventSubscribe - public void powerRender(final MENetworkPowerStatusChange c) { - this.updateStatus(); - } - - @Override - @MENetworkEventSubscribe - public void chanRender(final MENetworkChannelsChanged changedChannels) { - this.updateStatus(); - } - - protected void updateStatus() { - final boolean currentActive = this.getProxy().isActive(); - if (this.wasActive != currentActive) { - this.wasActive = currentActive; - try { - this.getProxy().getGrid().postEvent(new MENetworkCellArrayUpdate()); - this.getHost().markForUpdate(); - } catch (final GridAccessException e) { - // NO-OP - } - } - } - - @Override - protected int getUpgradeSlots() { - return 5; - } - - @Override - public void updateSetting(final IConfigManager manager, @SuppressWarnings("rawtypes") final Enum settingName, - @SuppressWarnings("rawtypes") final Enum newValue) { - this.resetCache(true); - this.getHost().markForSave(); - } - - @Override - public void upgradesChanged() { - super.upgradesChanged(); - this.resetCache(true); - } - - @Override - public void readFromNBT(final NBTTagCompound data) { - super.readFromNBT(data); - this.config.readFromNBT(data, "config"); - this.priority = data.getInteger("priority"); - } - - @Override - public void writeToNBT(final NBTTagCompound data) { - super.writeToNBT(data); - this.config.writeToNBT(data, "config"); - data.setInteger("priority", this.priority); - } - - @Override - public IInventory getInventoryByName(final String name) { - if (name.equals("config")) { - return this.config; - } - return super.getInventoryByName(name); - } - - @Override - public void onChangeInventory(final IInventory inv, final int slot, final InvOperation mc, - final ItemStack removedStack, final ItemStack newStack) { - super.onChangeInventory(inv, slot, mc, removedStack, newStack); - - if (inv == this.config) { - this.resetCache(true); - } - } - - protected void resetCache(final boolean fullReset) { - if (this.getHost() == null || this.getHost().getTile() == null - || this.getHost().getTile().getWorldObj() == null - || this.getHost().getTile().getWorldObj().isRemote) { - return; - } - - if (fullReset) { - this.resetCacheLogic = 2; - } else if (this.resetCacheLogic < 2) { - this.resetCacheLogic = 1; - } - - try { - this.getProxy().getTick().alertDevice(this.getProxy().getNode()); - } catch (final GridAccessException ignore) {} - } - - protected void resetCache() { - final boolean fullReset = this.resetCacheLogic == 2; - this.resetCacheLogic = 0; - - final MEInventoryHandler in = this.getInternalHandler(); - IItemList before = AEApi.instance().storage().createFluidList(); - if (in != null) { - before = in.getAvailableItems(before, IterationCounter.fetchNewId()); - } - - this.cached = false; - if (fullReset) { - this.handlerHash = 0; - } - - final MEInventoryHandler out = this.getInternalHandler(); - if (this.monitor != null) { - this.monitor.onTick(); - } - - IItemList after = AEApi.instance().storage().createFluidList(); - - if (in != out) { - if (out != null) { - after = out.getAvailableItems(after, IterationCounter.fetchNewId()); - } - Platform.postListChanges(before, after, this, this.source); - } - } - - @Override - public boolean isValid(final Object verificationToken) { - return this.handler == verificationToken; - } - - @Override - public void postChange(final IBaseMonitor monitor, final Iterable change, - final BaseActionSource source) { - try { - if (this.getProxy().isActive()) { - if (!this.readOncePass) { - AccessRestriction currentAccess = (AccessRestriction) this.getConfigManager() - .getSetting(Settings.ACCESS); - if (!currentAccess.hasPermission(AccessRestriction.READ)) { - return; - } - } - Iterable filteredChanges = this.filterChanges(change, this.readOncePass); - this.readOncePass = false; - if (filteredChanges == null) return; - this.getProxy().getStorage() - .postAlterationOfStoredItems(StorageChannel.FLUIDS, filteredChanges, this.source); - } - } catch (final GridAccessException ignore) {} - } - - /** - * Filters the changes to only include fluids that pass the handlers extract filter. Will return null if none of the - * changes match the filter. - */ - @Nullable - private Iterable filterChanges(final Iterable change, final boolean readOncePass) { - if (readOncePass) { - return change; - } - - if (this.handler != null && this.handler.isExtractFilterActive() - && !this.handler.getExtractPartitionList().isEmpty()) { - List filteredChanges = new ArrayList<>(); - Predicate extractFilterCondition = this.handler.getExtractFilterCondition(); - for (final IAEFluidStack changedFluid : change) { - if (extractFilterCondition.test(changedFluid)) { - filteredChanges.add(changedFluid); - } - } - return filteredChanges.isEmpty() ? null : Collections.unmodifiableList(filteredChanges); - } - return change; - } - - @Override - public void onListUpdate() { - // NO-OP - } - - @Override - public void getBoxes(final IPartCollisionHelper bch) { - bch.addBox(3, 3, 15, 13, 13, 16); - bch.addBox(2, 2, 14, 14, 14, 15); - bch.addBox(5, 5, 12, 11, 11, 14); - } - - @Override - public void onNeighborChanged() { - this.resetCache(false); - } - - @Override - public boolean onPartActivate(final EntityPlayer player, final Vec3 pos) { - if (player.isSneaking()) { - return false; - } - if (Platform.isServer()) { - InventoryHandler.openGui( - player, - this.getHost().getTile().getWorldObj(), - new BlockPos(this.getHost().getTile()), - Objects.requireNonNull(this.getSide()), - GuiType.FLUID_STORAGE_BUS); - } - return true; - } - - @Override - public TickingRequest getTickingRequest(IGridNode node) { - return new TickingRequest(TickRates.StorageBus.getMin(), TickRates.StorageBus.getMax(), monitor == null, true); - } - - @Override - public TickRateModulation tickingRequest(IGridNode node, int ticksSinceLastCall) { - if (this.resetCacheLogic != 0) { - this.resetCache(); - } - if (this.monitor != null) { - return this.monitor.onTick(); - } - return TickRateModulation.SLEEP; - } - - @SuppressWarnings({ "rawtypes", "unchecked" }) - public MEInventoryHandler getInternalHandler() { - if (this.cached) { - return this.handler; - } - - final boolean wasSleeping = this.monitor == null; - - this.cached = true; - final TileEntity self = this.getHost().getTile(); - final TileEntity target = new BlockPos(self).getOffSet(this.getSide()).getTileEntity(); - final int newHandlerHash = Platform.generateTileHash(target); - if (newHandlerHash != 0 && newHandlerHash == this.handlerHash) { - return this.handler; - } - this.handlerHash = newHandlerHash; - this.handler = null; - this.monitor = null; - this.readOncePass = true; - if (target != null) { - final IExternalStorageHandler esh = AEApi.instance().registries().externalStorage() - .getHandler(target, this.getSide().getOpposite(), StorageChannel.FLUIDS, this.source); - if (esh != null) { - final IMEInventory inv = esh - .getInventory(target, this.getSide().getOpposite(), StorageChannel.FLUIDS, this.source); - if (inv instanceof final MEMonitorIFluidHandler h) { - h.setMode((StorageFilter) this.getConfigManager().getSetting(Settings.STORAGE_FILTER)); - h.setActionSource(new MachineSource(this)); - this.monitor = h; - } - if (inv != null) { - this.handler = new StorageBusInventoryHandler(inv, StorageChannel.FLUIDS); - AccessRestriction currentAccess = (AccessRestriction) this.getConfigManager().getSetting(Settings.ACCESS); - this.handler.setBaseAccess(currentAccess); - this.handler.setWhitelist( - this.getInstalledUpgrades(Upgrades.INVERTER) > 0 ? IncludeExclude.BLACKLIST - : IncludeExclude.WHITELIST); - this.handler.setSticky(this.getInstalledUpgrades(Upgrades.STICKY) > 0); - this.handler.setPriority(this.priority); - // only READ since READ_WRITE would break compat of existing storage buses - // could use a new setting that is applied via button or a card too - this.handler.setIsExtractFilterActive(currentAccess == AccessRestriction.READ); - - if (inv instanceof IMEMonitor) { - ((IBaseMonitor) inv).addListener(this, this.handler); - } - final IItemList priorityList = AEApi.instance().storage().createFluidList(); - - final int slotsToUse = 18 + this.getInstalledUpgrades(Upgrades.CAPACITY) * 9; - for (int x = 0; x < this.config.getSizeInventory() && x < slotsToUse; x++) { - final IAEItemStack is = this.config.getAEStackInSlot(x); - if (is != null) priorityList.add(AEFluidStack.create(ItemFluidPacket.getFluidStack(is))); - } - PrecisePriorityList partitionList = new PrecisePriorityList(priorityList); - this.handler.setPartitionList(partitionList); - this.handler.setExtractPartitionList(partitionList); - } - } - } - - // update sleep state... - if (wasSleeping != (this.monitor == null)) { - try { - final ITickManager tm = this.getProxy().getTick(); - if (this.monitor == null) { - tm.sleepDevice(this.getProxy().getNode()); - } else { - tm.wakeDevice(this.getProxy().getNode()); - } - } catch (final GridAccessException ignore) {} - } - - try { - // force grid to update handlers... - ((GridStorageCache) this.getProxy().getGrid().getCache(IStorageGrid.class)).cellUpdate(null); - } catch (final GridAccessException ignore) {} - - return this.handler; - } - - @Override - @SuppressWarnings("rawtypes") - public List getCellArray(final StorageChannel channel) { - if (channel == StorageChannel.FLUIDS) { - final IMEInventoryHandler out = this.getInternalHandler(); - if (out != null) { - return Collections.singletonList(out); - } - } - return Collections.emptyList(); - } - - @Override - public int getPriority() { - return this.priority; - } - - @Override - public void setPriority(int newValue) { - this.priority = newValue; - this.getHost().markForSave(); - this.resetCache(true); - } - - @Override - public void saveChanges(@SuppressWarnings("rawtypes") final IMEInventory cellInventory) { - // NO-OP - } - - public AppEngInternalAEInventory getConfig() { - return this.config; - } - - public void setFluidInSlot(int id, IAEFluidStack fluid) { - ItemStack tmp = ItemFluidPacket.newDisplayStack(fluid == null ? null : fluid.getFluidStack()); - this.config.setInventorySlotContents(id, tmp); - } - - @Override - @SideOnly(Side.CLIENT) - public void renderInventory(final IPartRenderHelper rh, final RenderBlocks renderer) { - rh.setTexture( - CableBusTextures.PartStorageSides.getIcon(), - CableBusTextures.PartStorageSides.getIcon(), - CableBusTextures.PartStorageBack.getIcon(), - FCPartsTexture.PartFluidStorageBus.getIcon(), - CableBusTextures.PartStorageSides.getIcon(), - CableBusTextures.PartStorageSides.getIcon()); - - rh.setBounds(3, 3, 15, 13, 13, 16); - rh.renderInventoryBox(renderer); - - rh.setBounds(2, 2, 14, 14, 14, 15); - rh.renderInventoryBox(renderer); - - rh.setBounds(5, 5, 12, 11, 11, 14); - rh.renderInventoryBox(renderer); - } - - @Override - @SideOnly(Side.CLIENT) - public void renderStatic(final int x, final int y, final int z, final IPartRenderHelper rh, - final RenderBlocks renderer) { - this.setRenderCache(rh.useSimplifiedRendering(x, y, z, this, this.getRenderCache())); - rh.setTexture( - CableBusTextures.PartStorageSides.getIcon(), - CableBusTextures.PartStorageSides.getIcon(), - CableBusTextures.PartStorageBack.getIcon(), - FCPartsTexture.PartFluidStorageBus.getIcon(), - CableBusTextures.PartStorageSides.getIcon(), - CableBusTextures.PartStorageSides.getIcon()); - - rh.setBounds(3, 3, 15, 13, 13, 16); - rh.renderBlock(x, y, z, renderer); - - rh.setBounds(2, 2, 14, 14, 14, 15); - rh.renderBlock(x, y, z, renderer); - - rh.setTexture( - CableBusTextures.PartStorageSides.getIcon(), - CableBusTextures.PartStorageSides.getIcon(), - CableBusTextures.PartStorageBack.getIcon(), - FCPartsTexture.PartFluidStorageBus.getIcon(), - CableBusTextures.PartStorageSides.getIcon(), - CableBusTextures.PartStorageSides.getIcon()); - - rh.setBounds(5, 5, 12, 11, 11, 13); - rh.renderBlock(x, y, z, renderer); - - rh.setTexture( - CableBusTextures.PartMonitorSidesStatus.getIcon(), - CableBusTextures.PartMonitorSidesStatus.getIcon(), - CableBusTextures.PartMonitorBack.getIcon(), - FCPartsTexture.PartFluidStorageBus.getIcon(), - CableBusTextures.PartMonitorSidesStatus.getIcon(), - CableBusTextures.PartMonitorSidesStatus.getIcon()); - - rh.setBounds(5, 5, 13, 11, 11, 14); - rh.renderBlock(x, y, z, renderer); - - this.renderLights(x, y, z, rh, renderer); + public StorageChannel getStorageChannel() { + return StorageChannel.FLUIDS; } } diff --git a/src/main/java/com/glodblock/github/common/parts/PartFluidTerminal.java b/src/main/java/com/glodblock/github/common/parts/PartFluidTerminal.java index 9b42bea4..a26038c2 100644 --- a/src/main/java/com/glodblock/github/common/parts/PartFluidTerminal.java +++ b/src/main/java/com/glodblock/github/common/parts/PartFluidTerminal.java @@ -4,7 +4,8 @@ import net.minecraft.item.ItemStack; import com.glodblock.github.client.textures.FCPartsTexture; import com.glodblock.github.common.parts.base.FCPart; -import com.glodblock.github.inventory.gui.GuiType; + +import appeng.core.sync.GuiBridge; public class PartFluidTerminal extends FCPart { @@ -42,7 +43,7 @@ public class PartFluidTerminal extends FCPart { } @Override - public GuiType getGui() { - return GuiType.FLUID_TERMINAL; + public GuiBridge getGui() { + return GuiBridge.GUI_ME; } } diff --git a/src/main/java/com/glodblock/github/common/parts/PartLevelTerminal.java b/src/main/java/com/glodblock/github/common/parts/PartLevelTerminal.java index 7df1d991..bad82be6 100644 --- a/src/main/java/com/glodblock/github/common/parts/PartLevelTerminal.java +++ b/src/main/java/com/glodblock/github/common/parts/PartLevelTerminal.java @@ -1,14 +1,21 @@ package com.glodblock.github.common.parts; +import java.util.Objects; + +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import com.glodblock.github.client.textures.FCPartsTexture; import com.glodblock.github.common.parts.base.FCPart; +import com.glodblock.github.inventory.InventoryHandler; import com.glodblock.github.inventory.gui.GuiType; import com.glodblock.github.inventory.item.IClickableInTerminal; +import com.glodblock.github.util.BlockPos; import com.glodblock.github.util.Util; +import appeng.core.sync.GuiBridge; + public class PartLevelTerminal extends FCPart implements IClickableInTerminal { private static final FCPartsTexture FRONT_BRIGHT_ICON = FCPartsTexture.PartLevelTerminal_Bright; @@ -66,8 +73,8 @@ public class PartLevelTerminal extends FCPart implements IClickableInTerminal { } @Override - public GuiType getGui() { - return GuiType.LEVEL_TERMINAL; + public GuiBridge getGui() { + return GuiBridge.GUI_ME; } @Override @@ -80,4 +87,14 @@ public class PartLevelTerminal extends FCPart implements IClickableInTerminal { public Util.DimensionalCoordSide getClickedInterface() { return this.tile; } + + @Override + protected void openGui(EntityPlayer player) { + InventoryHandler.openGui( + player, + this.getHost().getTile().getWorldObj(), + new BlockPos(this.getHost().getTile()), + Objects.requireNonNull(this.getSide()), + GuiType.LEVEL_TERMINAL); + } } diff --git a/src/main/java/com/glodblock/github/common/parts/base/FCFluidEncodeTerminal.java b/src/main/java/com/glodblock/github/common/parts/base/FCFluidEncodeTerminal.java deleted file mode 100644 index 5ae403d0..00000000 --- a/src/main/java/com/glodblock/github/common/parts/base/FCFluidEncodeTerminal.java +++ /dev/null @@ -1,238 +0,0 @@ -package com.glodblock.github.common.parts.base; - -import java.util.ArrayList; -import java.util.List; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; - -import com.glodblock.github.common.item.ItemFluidPacket; -import com.glodblock.github.inventory.item.IItemPatternTerminal; - -import appeng.api.networking.IGrid; -import appeng.api.storage.ITerminalPins; -import appeng.api.storage.data.IAEItemStack; -import appeng.items.contents.PinsHandler; -import appeng.items.contents.PinsHolder; -import appeng.tile.inventory.AppEngInternalInventory; - -public abstract class FCFluidEncodeTerminal extends FCPart implements IItemPatternTerminal, ITerminalPins { - - protected AppEngInternalInventory crafting; - protected AppEngInternalInventory output; - protected final AppEngInternalInventory pattern = new AppEngInternalInventory(this, 2); - private final PinsHolder pinsInv = new PinsHolder(this); - - protected boolean craftingMode = true; - protected boolean substitute = false; - protected boolean combine = false; - protected boolean prioritize = false; - protected boolean inverted = false; - protected boolean beSubstitute = false; - protected boolean autoFillPattern = false; - protected int activePage = 0; - - public FCFluidEncodeTerminal(ItemStack is) { - super(is, true); - } - - @Override - public void getDrops(final List drops, final boolean wrenched) { - super.getDrops(drops, wrenched); - for (final ItemStack is : this.pattern) { - if (is != null) { - drops.add(is); - } - } - } - - @Override - public void readFromNBT(final NBTTagCompound data) { - super.readFromNBT(data); - this.setCraftingRecipe(data.getBoolean("craftingMode")); - this.setSubstitution(data.getBoolean("substitute")); - this.setCombineMode(data.getBoolean("combine")); - this.setBeSubstitute(data.getBoolean("beSubstitute")); - this.setPrioritization(data.getBoolean("priorization")); - this.setInverted(data.getBoolean("inverted")); - this.setActivePage(data.getInteger("activePage")); - this.setAutoFillPattern(data.getBoolean("autoFillPattern")); - this.pattern.readFromNBT(data, "pattern"); - this.output.readFromNBT(data, "outputList"); - this.crafting.readFromNBT(data, "craftingGrid"); - pinsInv.readFromNBT(data, "pins"); - } - - @Override - public void writeToNBT(final NBTTagCompound data) { - super.writeToNBT(data); - data.setBoolean("craftingMode", this.craftingMode); - data.setBoolean("combine", this.combine); - data.setBoolean("beSubstitute", this.beSubstitute); - data.setBoolean("priorization", this.prioritize); - data.setBoolean("substitute", this.substitute); - data.setBoolean("inverted", this.inverted); - data.setInteger("activePage", this.activePage); - data.setBoolean("autoFillPattern", this.autoFillPattern); - this.pattern.writeToNBT(data, "pattern"); - this.output.writeToNBT(data, "outputList"); - this.crafting.writeToNBT(data, "craftingGrid"); - pinsInv.writeToNBT(data, "pins"); - } - - @Override - public boolean shouldCombine() { - return this.combine; - } - - @Override - public void setCombineMode(boolean shouldCombine) { - this.combine = shouldCombine; - } - - @Override - public boolean isSubstitution() { - return this.substitute; - } - - @Override - public boolean isPrioritize() { - return this.prioritize; - } - - @Override - public void setBeSubstitute(boolean canBeSubstitute) { - this.beSubstitute = canBeSubstitute; - } - - @Override - public boolean canBeSubstitute() { - return this.beSubstitute; - } - - @Override - public void setSubstitution(boolean canSubstitute) { - this.substitute = canSubstitute; - } - - @Override - public void setPrioritization(boolean canPrioritize) { - this.prioritize = canPrioritize; - } - - @Override - public boolean isInverted() { - return inverted; - } - - @Override - public void setInverted(boolean inverted) { - this.inverted = inverted; - } - - @Override - public int getActivePage() { - return this.activePage; - } - - @Override - public void setActivePage(int activePage) { - this.activePage = activePage; - } - - @Override - public void setCraftingRecipe(final boolean craftingMode) { - this.craftingMode = craftingMode; - } - - @Override - public boolean isCraftingRecipe() { - return this.craftingMode; - } - - @Override - public void onChangeCrafting(IAEItemStack[] newCrafting, IAEItemStack[] newOutput) { - IInventory crafting = this.getInventoryByName("crafting"); - IInventory output = this.getInventoryByName("output"); - if (crafting instanceof AppEngInternalInventory && output instanceof AppEngInternalInventory) { - for (int x = 0; x < crafting.getSizeInventory() && x < newCrafting.length; x++) { - final IAEItemStack item = newCrafting[x]; - crafting.setInventorySlotContents(x, item == null ? null : item.getItemStack()); - } - for (int x = 0; x < output.getSizeInventory() && x < newOutput.length; x++) { - final IAEItemStack item = newOutput[x]; - output.setInventorySlotContents(x, item == null ? null : item.getItemStack()); - } - } - } - - @Override - public IInventory getInventoryByName(final String name) { - if (name.equals("crafting")) { - return this.crafting; - } - - if (name.equals("output")) { - return this.output; - } - - if (name.equals("pattern")) { - return this.pattern; - } - - return super.getInventoryByName(name); - } - - @Override - public void sortCraftingItems() { - List items = new ArrayList<>(); - List fluids = new ArrayList<>(); - for (ItemStack is : this.crafting) { - if (is == null) continue; - if (is.getItem() instanceof ItemFluidPacket) { - fluids.add(is); - } else { - items.add(is); - } - } - if (this.prioritize) { - fluids.addAll(items); - items.clear(); - } else { - items.addAll(fluids); - fluids.clear(); - } - - for (int i = 0; i < this.crafting.getSizeInventory(); i++) { - if (this.crafting.getStackInSlot(i) == null) break; - if (items.isEmpty()) { - this.crafting.setInventorySlotContents(i, fluids.get(i)); - } else { - this.crafting.setInventorySlotContents(i, items.get(i)); - } - } - saveChanges(); - } - - @Override - public boolean isAutoFillPattern() { - return this.autoFillPattern; - } - - @Override - public void setAutoFillPattern(boolean canFill) { - this.autoFillPattern = canFill; - } - - @Override - public PinsHandler getPinsHandler(EntityPlayer player) { - return pinsInv.getHandler(player); - } - - @Override - public IGrid getGrid() { - return getGridNode().getGrid(); - } -} diff --git a/src/main/java/com/glodblock/github/common/parts/base/FCPart.java b/src/main/java/com/glodblock/github/common/parts/base/FCPart.java index 5573869c..90809bcd 100644 --- a/src/main/java/com/glodblock/github/common/parts/base/FCPart.java +++ b/src/main/java/com/glodblock/github/common/parts/base/FCPart.java @@ -2,7 +2,6 @@ package com.glodblock.github.common.parts.base; import java.io.IOException; import java.util.List; -import java.util.Objects; import net.minecraft.client.renderer.RenderBlocks; import net.minecraft.client.renderer.Tessellator; @@ -18,8 +17,6 @@ import net.minecraft.util.Vec3; import net.minecraftforge.common.util.ForgeDirection; import com.glodblock.github.client.textures.FCPartsTexture; -import com.glodblock.github.inventory.InventoryHandler; -import com.glodblock.github.inventory.gui.GuiType; import com.glodblock.github.util.BlockPos; import com.glodblock.github.util.Util; @@ -44,6 +41,7 @@ import appeng.api.storage.data.IAEFluidStack; import appeng.api.storage.data.IAEItemStack; import appeng.api.util.IConfigManager; import appeng.client.texture.CableBusTextures; +import appeng.core.sync.GuiBridge; import appeng.me.GridAccessException; import appeng.parts.AEBasePart; import appeng.tile.inventory.AppEngInternalInventory; @@ -149,7 +147,7 @@ public abstract class FCPart extends AEBasePart this.viewCell.writeToNBT(data, "viewCell"); } - public abstract GuiType getGui(); + public abstract GuiBridge getGui(); @Override public void writeToStream(final ByteBuf data) throws IOException { @@ -223,7 +221,7 @@ public abstract class FCPart extends AEBasePart if (Platform.isServer()) { if (Util.hasPermission(player, SecurityPermissions.INJECT, (IGridHost) this) || Util.hasPermission(player, SecurityPermissions.EXTRACT, (IGridHost) this)) { - InventoryHandler.openGui(player, te.getWorldObj(), tePos, Objects.requireNonNull(getSide()), getGui()); + openGui(player); } else { player.addChatComponentMessage(new ChatComponentText("You don't have permission to view.")); } @@ -231,6 +229,10 @@ public abstract class FCPart extends AEBasePart return true; } + protected void openGui(EntityPlayer player) { + Platform.openGUI(player, this.getHost().getTile(), this.getSide(), this.getGui()); + } + @Override public final void onPlacement(final EntityPlayer player, final ItemStack held, final ForgeDirection side) { super.onPlacement(player, held, side); diff --git a/src/main/java/com/glodblock/github/common/parts/base/FCSharedFluidBus.java b/src/main/java/com/glodblock/github/common/parts/base/FCSharedFluidBus.java deleted file mode 100644 index aac34257..00000000 --- a/src/main/java/com/glodblock/github/common/parts/base/FCSharedFluidBus.java +++ /dev/null @@ -1,169 +0,0 @@ -package com.glodblock.github.common.parts.base; - -import java.util.Objects; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.IIcon; -import net.minecraft.util.Vec3; -import net.minecraft.world.World; - -import com.glodblock.github.common.item.ItemFluidPacket; -import com.glodblock.github.inventory.InventoryHandler; -import com.glodblock.github.inventory.gui.GuiType; -import com.glodblock.github.util.BlockPos; - -import appeng.api.config.RedstoneMode; -import appeng.api.config.Upgrades; -import appeng.api.networking.ticking.IGridTickable; -import appeng.api.networking.ticking.TickRateModulation; -import appeng.api.parts.IPartCollisionHelper; -import appeng.api.storage.StorageChannel; -import appeng.api.storage.data.IAEFluidStack; -import appeng.me.GridAccessException; -import appeng.parts.automation.PartUpgradeable; -import appeng.tile.inventory.AppEngInternalAEInventory; -import appeng.util.Platform; - -public abstract class FCSharedFluidBus extends PartUpgradeable implements IGridTickable { - - private final AppEngInternalAEInventory config = new AppEngInternalAEInventory(this, 9); - private boolean lastRedstone; - - public FCSharedFluidBus(ItemStack is) { - super(is); - } - - public abstract IIcon getFaceIcon(); - - @Override - public void upgradesChanged() { - this.updateState(); - } - - @Override - public void onNeighborChanged() { - this.updateState(); - if (this.lastRedstone != this.getHost().hasRedstone(this.getSide())) { - this.lastRedstone = !this.lastRedstone; - if (this.lastRedstone && this.getRSMode() == RedstoneMode.SIGNAL_PULSE) { - this.doBusWork(); - } - } - } - - private void updateState() { - try { - if (!this.isSleeping()) { - this.getProxy().getTick().wakeDevice(this.getProxy().getNode()); - } else { - this.getProxy().getTick().sleepDevice(this.getProxy().getNode()); - } - } catch (final GridAccessException ignored) {} - } - - @Override - public boolean onPartActivate(final EntityPlayer player, final Vec3 pos) { - if (player.isSneaking()) { - return false; - } - if (Platform.isServer()) { - InventoryHandler.openGui( - player, - this.getHost().getTile().getWorldObj(), - new BlockPos(this.getHost().getTile()), - Objects.requireNonNull(this.getSide()), - GuiType.FLUID_BUS_IO); - } - - return true; - } - - @Override - public void getBoxes(IPartCollisionHelper bch) { - bch.addBox(6, 6, 11, 10, 10, 13); - bch.addBox(5, 5, 13, 11, 11, 14); - bch.addBox(4, 4, 14, 12, 12, 16); - } - - protected TileEntity getConnectedTE() { - TileEntity self = this.getHost().getTile(); - return this.getTileEntity(self, (new BlockPos(self)).getOffSet(this.getSide())); - } - - private TileEntity getTileEntity(final TileEntity self, final BlockPos pos) { - final World w = self.getWorldObj(); - - if (w.getChunkProvider().chunkExists(pos.getX() >> 4, pos.getZ() >> 4)) { - return w.getTileEntity(pos.getX(), pos.getY(), pos.getZ()); - } - - return null; - } - - public int calculateAmountToSend() { - double amount = 1000D; - switch (this.getInstalledUpgrades(Upgrades.SPEED)) { - case 4: - amount = amount * 1.5; - case 3: - amount = amount * 2; - case 2: - amount = amount * 4; - case 1: - amount = amount * 8; - } - switch (this.getInstalledUpgrades(Upgrades.SUPERSPEED)) { - case 4: - amount = amount * 8; - case 3: - amount = amount * 12; - case 2: - amount = amount * 16; - case 1: - amount = amount * 32; - } - return (int) Math.floor(amount); - } - - @Override - public void readFromNBT(NBTTagCompound extra) { - super.readFromNBT(extra); - this.config.readFromNBT(extra, "config"); - } - - @Override - public void writeToNBT(NBTTagCompound extra) { - super.writeToNBT(extra); - this.config.writeToNBT(extra, "config"); - } - - @Override - public IInventory getInventoryByName(String name) { - if (name.equals("config")) { - return this.config; - } - return super.getInventoryByName(name); - } - - public void setFluidInSlot(int id, IAEFluidStack fluid) { - ItemStack tmp = ItemFluidPacket.newDisplayStack(fluid == null ? null : fluid.getFluidStack()); - this.config.setInventorySlotContents(id, tmp); - } - - protected StorageChannel getChannel() { - return StorageChannel.FLUIDS; - } - - protected abstract TickRateModulation doBusWork(); - - protected abstract boolean canDoBusWork(); - - @Override - public int cableConnectionRenderTo() { - return 5; - } -} diff --git a/src/main/java/com/glodblock/github/common/storage/CreativeFluidCellInventory.java b/src/main/java/com/glodblock/github/common/storage/CreativeFluidCellInventory.java deleted file mode 100644 index d9987ef5..00000000 --- a/src/main/java/com/glodblock/github/common/storage/CreativeFluidCellInventory.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.glodblock.github.common.storage; - -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraftforge.fluids.FluidStack; - -import com.glodblock.github.util.Util; - -import appeng.api.AEApi; -import appeng.api.config.Actionable; -import appeng.api.exceptions.AppEngException; -import appeng.api.networking.security.BaseActionSource; -import appeng.api.storage.ISaveProvider; -import appeng.api.storage.data.IAEFluidStack; - -public class CreativeFluidCellInventory extends FluidCellInventory { - - public CreativeFluidCellInventory(ItemStack o, ISaveProvider container) throws AppEngException { - super(o, container); - } - - @Override - public IAEFluidStack injectItems(IAEFluidStack input, Actionable mode, BaseActionSource src) { - if (input == null || input.getStackSize() == 0) { - return null; - } - if (this.cellType.isBlackListed(this.cellItem, input)) { - return input; - } - if (this.getCellFluids().findPrecise(input) != null) { - return null; - } else { - return input; - } - } - - @Override - public IAEFluidStack extractItems(IAEFluidStack request, Actionable mode, BaseActionSource src) { - if (request == null) { - return null; - } - if (this.getCellFluids().findPrecise(request) != null) { - return request.copy(); - } else { - return null; - } - - } - - @Override - protected void loadCellFluids() { - if (this.cellFluids == null) { - this.cellFluids = AEApi.instance().storage().createFluidList(); - } - this.cellFluids.resetStatus(); // clears totals and stuff. - IInventory inv = this.cellType.getConfigInventory(this.cellItem); - for (int i = 0; i < inv.getSizeInventory(); i++) { - ItemStack is = inv.getStackInSlot(i); - FluidStack fs = Util.getFluidFromItem(is); - if (fs == null) continue; - IAEFluidStack iaeFluidStack = Util.FluidUtil.createAEFluidStack(fs); - if (this.cellFluids.findPrecise(iaeFluidStack) == null) { - iaeFluidStack.setStackSize((long) (Math.pow(2, 52) - 1)); - this.cellFluids.add(iaeFluidStack); - } - } - } -} diff --git a/src/main/java/com/glodblock/github/common/storage/FluidCellHandler.java b/src/main/java/com/glodblock/github/common/storage/FluidCellHandler.java deleted file mode 100644 index eb0784e2..00000000 --- a/src/main/java/com/glodblock/github/common/storage/FluidCellHandler.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.glodblock.github.common.storage; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.IIcon; - -import com.glodblock.github.inventory.InventoryHandler; -import com.glodblock.github.inventory.gui.GuiType; -import com.glodblock.github.util.BlockPos; - -import appeng.api.implementations.tiles.IChestOrDrive; -import appeng.api.storage.ICellHandler; -import appeng.api.storage.IMEInventory; -import appeng.api.storage.IMEInventoryHandler; -import appeng.api.storage.ISaveProvider; -import appeng.api.storage.StorageChannel; -import appeng.client.texture.ExtraBlockTextures; - -public class FluidCellHandler implements ICellHandler { - - @Override - public boolean isCell(final ItemStack is) { - return FluidCellInventory.isCell(is); - } - - @Override - @SuppressWarnings("rawtypes") - public IMEInventoryHandler getCellInventory(final ItemStack is, final ISaveProvider container, - final StorageChannel channel) { - if (channel == StorageChannel.FLUIDS) { - return FluidCellInventory.getCell(is, container); - } - return null; - } - - @Override - public IIcon getTopTexture_Light() { - return ExtraBlockTextures.BlockMEChestItems_Light.getIcon(); - } - - @Override - public IIcon getTopTexture_Medium() { - return ExtraBlockTextures.BlockMEChestItems_Medium.getIcon(); - } - - @Override - public IIcon getTopTexture_Dark() { - return ExtraBlockTextures.BlockMEChestItems_Dark.getIcon(); - } - - @Override - public void openChestGui(final EntityPlayer player, final IChestOrDrive chest, final ICellHandler cellHandler, - @SuppressWarnings("rawtypes") final IMEInventoryHandler inv, final ItemStack is, - final StorageChannel chan) { - if (chan == StorageChannel.FLUIDS) { - if (chest instanceof TileEntity te) { - InventoryHandler - .openGui(player, te.getWorldObj(), new BlockPos(te), chest.getUp(), GuiType.FLUID_TERMINAL); - } - } - } - - @Override - public int getStatusForCell(final ItemStack is, @SuppressWarnings("rawtypes") final IMEInventory handler) { - if (handler instanceof final FluidCellInventoryHandler ci) { - return ci.getStatusForCell(); - } - return 0; - } - - @Override - public double cellIdleDrain(final ItemStack is, @SuppressWarnings("rawtypes") final IMEInventory handler) { - final IFluidCellInventory inv = ((IFluidCellInventoryHandler) handler).getCellInv(); - return inv.getIdleDrain(is); - } -} diff --git a/src/main/java/com/glodblock/github/common/storage/FluidCellInventory.java b/src/main/java/com/glodblock/github/common/storage/FluidCellInventory.java deleted file mode 100644 index 39fdab99..00000000 --- a/src/main/java/com/glodblock/github/common/storage/FluidCellInventory.java +++ /dev/null @@ -1,505 +0,0 @@ -package com.glodblock.github.common.storage; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import javax.annotation.Nonnull; - -import net.minecraft.inventory.IInventory; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTBase; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraftforge.fluids.FluidStack; - -import org.jetbrains.annotations.NotNull; - -import com.glodblock.github.common.item.ItemBaseInfinityStorageCell; -import com.glodblock.github.common.item.ItemFluidVoidStorageCell; -import com.glodblock.github.crossmod.extracells.storage.ProxyFluidCellInventory; -import com.glodblock.github.crossmod.extracells.storage.ProxyFluidStorageCell; - -import appeng.api.AEApi; -import appeng.api.config.Actionable; -import appeng.api.config.Upgrades; -import appeng.api.exceptions.AppEngException; -import appeng.api.implementations.items.IUpgradeModule; -import appeng.api.networking.security.BaseActionSource; -import appeng.api.storage.IMEInventoryHandler; -import appeng.api.storage.ISaveProvider; -import appeng.api.storage.StorageChannel; -import appeng.api.storage.data.IAEFluidStack; -import appeng.api.storage.data.IItemList; -import appeng.util.Platform; -import appeng.util.item.AEFluidStack; - -public class FluidCellInventory implements IFluidCellInventory { - - protected static final String FLUID_TYPE_TAG = "ft"; - protected static final String FLUID_COUNT_TAG = "fc"; - protected static final String FLUID_SLOT = "#"; - protected static final String FLUID_SLOT_COUNT = "@"; - protected IStorageFluidCell cellType; - protected static String[] fluidSlots; - protected static String[] fluidSlotCount; - protected final ItemStack cellItem; - private final ISaveProvider container; - private final int MAX_TYPE = 63; - protected long storedFluidCount; - protected short storedFluids; - protected IItemList cellFluids; - protected final NBTTagCompound tagCompound; - public static final int singleByteAmount = 256 * 8; - private boolean cardVoidOverflow = false; - private boolean cardDistribution = false; - private byte restrictionTypes = 0; - private long restrictionLong = 0; - - public FluidCellInventory(final ItemStack o, final ISaveProvider container) throws AppEngException { - if (o == null) { - throw new AppEngException("ItemStack was used as a cell, but was not a cell!"); - } - this.cellType = null; - this.cellItem = o; - final Item type = this.cellItem.getItem(); - if (type instanceof IStorageFluidCell) { - this.cellType = (IStorageFluidCell) this.cellItem.getItem(); - } - if (this.cellType == null) { - throw new AppEngException("ItemStack was used as a cell, but was not a cell!"); - } - if (!this.cellType.isStorageCell(this.cellItem)) { - throw new AppEngException("ItemStack was used as a cell, but was not a cell!"); - } - - if (fluidSlots == null) { - fluidSlots = new String[MAX_TYPE]; - fluidSlotCount = new String[MAX_TYPE]; - - for (int x = 0; x < MAX_TYPE; x++) { - fluidSlots[x] = FLUID_SLOT + x; - fluidSlotCount[x] = FLUID_SLOT_COUNT + x; - } - } - - final IInventory upgrades = this.getUpgradesInventory(); - Upgrades u; - for (int x = 0; x < upgrades.getSizeInventory(); x++) { - final ItemStack is = upgrades.getStackInSlot(x); - if (is == null) continue; - if (is.getItem() instanceof IUpgradeModule upgradeItem && (u = upgradeItem.getType(is)) != null) { - switch (u) { - case VOID_OVERFLOW -> cardVoidOverflow = true; - case DISTRIBUTION -> cardDistribution = true; - default -> {} - } - } - } - - this.container = container; - this.tagCompound = Platform.openNbtData(o); - this.storedFluids = this.tagCompound.getShort(FLUID_TYPE_TAG); - this.storedFluidCount = this.tagCompound.getLong(FLUID_COUNT_TAG); - this.restrictionTypes = this.tagCompound.getByte("cellRestrictionTypes"); - this.restrictionLong = this.tagCompound.getLong("cellRestrictionAmount"); - this.cellFluids = null; - } - - public static IMEInventoryHandler getCell(final ItemStack o, final ISaveProvider container2) { - try { - if (o.getItem() instanceof ItemBaseInfinityStorageCell) { - return new FluidCellInventoryHandler(new CreativeFluidCellInventory(o, container2)); - } else if (o.getItem() instanceof ProxyFluidStorageCell) { - return new FluidCellInventoryHandler(new ProxyFluidCellInventory(o, container2)); - } else if (o.getItem() instanceof ItemFluidVoidStorageCell) { - return new FluidCellInventoryHandler(new FluidVoidStorageCellInventory(o, container2)); - } else { - return new FluidCellInventoryHandler(new FluidCellInventory(o, container2)); - } - } catch (final AppEngException e) { - return null; - } - } - - public static boolean isCell(final ItemStack itemStack) { - if (itemStack == null) { - return false; - } - final Item type = itemStack.getItem(); - if (type instanceof IStorageFluidCell) { - return ((IStorageFluidCell) type).isStorageCell(itemStack); - } - return false; - } - - @Override - public ItemStack getItemStack() { - return this.cellItem; - } - - @Override - public double getIdleDrain(ItemStack is) { - return this.cellType.getIdleDrain(is); - } - - @Override - public IInventory getConfigInventory() { - return this.cellType.getConfigInventory(this.cellItem); - } - - @Override - public int getBytesPerType() { - return this.cellType.getBytesPerType(this.cellItem); - } - - @Override - public boolean canHoldNewFluid() { - final long bytesFree = this.getFreeBytes(); - return (bytesFree > this.getBytesPerType() - || (bytesFree == this.getBytesPerType() && this.getUnusedFluidCount() > 0)) - && this.getRemainingFluidTypes() > 0; - } - - @Override - public long getTotalBytes() { - return this.cellType.getBytes(this.cellItem); - } - - @Override - public long getFreeBytes() { - return this.getTotalBytes() - this.getUsedBytes(); - } - - @Override - public long getUsedBytes() { - final long bytesForFluidCount = (this.getStoredFluidCount() + this.getUnusedFluidCount()) / singleByteAmount; - return this.getStoredFluidTypes() * this.getBytesPerType() + bytesForFluidCount; - } - - @Override - public long getTotalFluidTypes() { - if (restrictionTypes > 0) return restrictionTypes; - return this.cellType.getTotalTypes(this.cellItem); - } - - public long getMaxFluidTypes() { - return this.cellType.getTotalTypes(this.cellItem); - } - - @Override - public long getStoredFluidCount() { - return this.storedFluidCount; - } - - @Override - public long getStoredFluidTypes() { - return this.storedFluids; - } - - @Override - public long getRemainingFluidTypes() { - final long basedOnStorage = this.getFreeBytes() / Math.max(1, this.getBytesPerType()); - final long baseOnTotal = this.getTotalFluidTypes() - this.getStoredFluidTypes(); - return Math.min(basedOnStorage, baseOnTotal); - } - - @Override - public long getRemainingFluidCount() { - if (restrictionLong > 0) { - return Math.min( - restrictionLong - this.getStoredFluidCount(), - this.getFreeBytes() * singleByteAmount + this.getUnusedFluidCount()); - } - final long remaining = this.getFreeBytes() * singleByteAmount + this.getUnusedFluidCount(); - return remaining > 0 ? remaining : 0; - } - - @Override - public long getRemainingFluidCountDist(IAEFluidStack l) { - long remaining; - long types = 0; - long maxFluidTypes = this.getTotalFluidTypes(); - IInventory configInventory = this.getConfigInventory(); - for (int i = 0; i < configInventory.getSizeInventory(); i++) { - // Check all partition slots to determine min distribution behaviour until max fluid types is reached - if (types >= maxFluidTypes) break; - if (configInventory.getStackInSlot(i) != null) { - types++; - } - } - if (types == 0) types = maxFluidTypes; - if (l != null) { - if (restrictionLong > 0) { - remaining = Math.min((restrictionLong / types) - l.getStackSize(), getRemainingFluidCount()); - } else { - remaining = (((getTotalBytes() / types) - getBytesPerType()) * singleByteAmount) - l.getStackSize(); - } - } else { - if (restrictionLong > 0) { - remaining = Math.min( - restrictionLong / types, - ((this.getTotalBytes() / types) - this.getBytesPerType()) * singleByteAmount); - } else { - remaining = ((this.getTotalBytes() / types) - this.getBytesPerType()) * singleByteAmount; - } - } - return remaining > 0 ? remaining : 0; - } - - @Override - public int getUnusedFluidCount() { - final int div = (int) (this.getStoredFluidCount() % singleByteAmount); - if (div == 0) { - return 0; - } - return singleByteAmount - div; - } - - @Override - public int getStatusForCell() { - if (this.getUsedBytes() == 0) { - return 1; - } - if (this.canHoldNewFluid()) { - return 2; - } - if (this.getRemainingFluidCount() > 0) { - return 3; - } - return 4; - } - - protected void loadCellFluids() { - if (this.cellFluids == null) { - this.cellFluids = AEApi.instance().storage().createFluidList(); - } - this.cellFluids.resetStatus(); // clears totals and stuff. - final int types = (int) this.getStoredFluidTypes(); - for (int x = 0; x < types; x++) { - final FluidStack t = FluidStack.loadFluidStackFromNBT(this.tagCompound.getCompoundTag(fluidSlots[x])); - final AEFluidStack aet = AEFluidStack.create(t); - if (aet != null) { - aet.setStackSize(this.tagCompound.getLong(fluidSlotCount[x])); - if (aet.getStackSize() > 0) { - this.cellFluids.add(aet); - } - } - } - } - - protected IItemList getCellFluids() { - if (this.cellFluids == null) { - this.loadCellFluids(); - } - return this.cellFluids; - } - - private void updateFluidCount(final long delta) { - this.storedFluidCount += delta; - this.tagCompound.setLong(FLUID_COUNT_TAG, this.storedFluidCount); - } - - private void saveChanges() { - long fluidCount = 0; - int x = 0; - - for (final IAEFluidStack v : this.cellFluids) { - fluidCount += v.getStackSize(); - final NBTBase c = this.tagCompound.getTag(fluidSlots[x]); - if (c instanceof NBTTagCompound) { - v.writeToNBT((NBTTagCompound) c); - } else { - final NBTTagCompound g = new NBTTagCompound(); - v.writeToNBT(g); - this.tagCompound.setTag(fluidSlots[x], g); - } - this.tagCompound.setLong(fluidSlotCount[x], v.getStackSize()); - x++; - } - - final short oldStoredFluids = this.storedFluids; - this.storedFluids = (short) this.cellFluids.size(); - - if (this.cellFluids.isEmpty()) { - this.tagCompound.removeTag(FLUID_TYPE_TAG); - } else { - this.tagCompound.setShort(FLUID_TYPE_TAG, this.storedFluids); - } - - this.storedFluidCount = fluidCount; - - if (fluidCount == 0) { - this.tagCompound.removeTag(FLUID_COUNT_TAG); - } else { - this.tagCompound.setLong(FLUID_COUNT_TAG, fluidCount); - } - - // clean any old crusty stuff... - for (; x < oldStoredFluids && x < MAX_TYPE; x++) { - this.tagCompound.removeTag(fluidSlots[x]); - this.tagCompound.removeTag(fluidSlotCount[x]); - } - - if (this.container != null) { - this.container.saveChanges(this); - } - } - - @Override - public IAEFluidStack injectItems(IAEFluidStack input, Actionable mode, BaseActionSource src) { - if (input == null) { - return null; - } - if (input.getStackSize() == 0) { - return null; - } - if (this.cellType.isBlackListed(this.cellItem, input)) { - return input; - } - final IAEFluidStack l = this.getCellFluids().findPrecise(input); - - if (l != null) { - long remainingFluidSlots; - if (cardDistribution) { - remainingFluidSlots = this.getRemainingFluidCountDist(l); - } else { - remainingFluidSlots = this.getRemainingFluidCount(); - } - - if (remainingFluidSlots <= 0) { - if (cardVoidOverflow) { - return null; - } - return input; - } - - if (input.getStackSize() > remainingFluidSlots) { - final IAEFluidStack r = input.copy(); - r.setStackSize(r.getStackSize() - remainingFluidSlots); - if (mode == Actionable.MODULATE) { - l.setStackSize(l.getStackSize() + remainingFluidSlots); - this.updateFluidCount(remainingFluidSlots); - this.saveChanges(); - } - return r; - } else { - if (mode == Actionable.MODULATE) { - l.setStackSize(l.getStackSize() + input.getStackSize()); - this.updateFluidCount(input.getStackSize()); - this.saveChanges(); - } - return null; - } - } - - if (this.canHoldNewFluid()) // room for new type, and for at least one item! - { - long remainingFluidCount; - if (cardDistribution) { - remainingFluidCount = this.getRemainingFluidCountDist(null); - } else { - remainingFluidCount = Math.min( - getRemainingFluidCount(), - getFreeBytes() * singleByteAmount + getUnusedFluidCount() - - (long) getBytesPerType() * singleByteAmount); - } - - if (remainingFluidCount > 0) { - if (input.getStackSize() > remainingFluidCount) { - final IAEFluidStack toReturn = input.copy(); - toReturn.decStackSize(remainingFluidCount); - if (mode == Actionable.MODULATE) { - IAEFluidStack toWrite = input.copy(); - toWrite.setStackSize(remainingFluidCount); - this.cellFluids.add(toWrite); - this.updateFluidCount(toWrite.getStackSize()); - this.saveChanges(); - } - return toReturn; - } - if (mode == Actionable.MODULATE) { - this.updateFluidCount(input.getStackSize()); - this.cellFluids.add(input); - this.saveChanges(); - } - return null; - } - } - - return input; - } - - @Override - public IAEFluidStack extractItems(IAEFluidStack request, Actionable mode, BaseActionSource src) { - if (request == null) { - return null; - } - - final long size = request.getStackSize(); - - IAEFluidStack results = null; - - final IAEFluidStack l = this.getCellFluids().findPrecise(request); - - if (l != null) { - results = l.copy(); - - if (l.getStackSize() <= size) { - results.setStackSize(l.getStackSize()); - - if (mode == Actionable.MODULATE) { - this.updateFluidCount(-l.getStackSize()); - l.setStackSize(0); - this.saveChanges(); - } - } else { - results.setStackSize(size); - - if (mode == Actionable.MODULATE) { - l.setStackSize(l.getStackSize() - size); - this.updateFluidCount(-size); - this.saveChanges(); - } - } - } - - return results; - } - - @Override - public IItemList getAvailableItems(IItemList out, int iteration) { - for (final IAEFluidStack i : this.getCellFluids()) { - out.add(i); - } - return out; - } - - @Override - public IAEFluidStack getAvailableItem(@Nonnull IAEFluidStack request, int iteration) { - return this.getCellFluids().findPrecise(request); - } - - @Override - public @NotNull List getContents() { - List ret = new ArrayList<>(); - for (IAEFluidStack fluid : this.getCellFluids()) { - ret.add(fluid); - } - return ret; - } - - @Override - public IInventory getUpgradesInventory() { - return this.cellType.getUpgradesInventory(this.cellItem); - } - - @Override - public StorageChannel getChannel() { - return StorageChannel.FLUIDS; - } - - public List getRestriction() { - return Arrays.asList(restrictionLong, restrictionTypes); - } -} diff --git a/src/main/java/com/glodblock/github/common/storage/FluidCellInventoryHandler.java b/src/main/java/com/glodblock/github/common/storage/FluidCellInventoryHandler.java deleted file mode 100644 index 83101386..00000000 --- a/src/main/java/com/glodblock/github/common/storage/FluidCellInventoryHandler.java +++ /dev/null @@ -1,171 +0,0 @@ -package com.glodblock.github.common.storage; - -import java.util.List; - -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraftforge.fluids.FluidStack; - -import com.glodblock.github.common.item.ItemFluidPacket; -import com.glodblock.github.util.Util; - -import appeng.api.AEApi; -import appeng.api.config.IncludeExclude; -import appeng.api.config.Upgrades; -import appeng.api.implementations.items.IUpgradeModule; -import appeng.api.storage.ICellCacheRegistry; -import appeng.api.storage.IMEInventory; -import appeng.api.storage.StorageChannel; -import appeng.api.storage.data.IAEFluidStack; -import appeng.api.storage.data.IItemList; -import appeng.me.storage.MEInventoryHandler; -import appeng.me.storage.MEPassThrough; -import appeng.util.item.AEFluidStack; -import appeng.util.prioitylist.PrecisePriorityList; - -public class FluidCellInventoryHandler extends MEInventoryHandler - implements IFluidCellInventoryHandler, ICellCacheRegistry { - - protected FluidCellInventoryHandler(final IMEInventory c) { - super(c, StorageChannel.FLUIDS); - - final IFluidCellInventory ci = this.getCellInv(); - - if (ci != null) { - final IInventory config = ci.getConfigInventory(); - - final IItemList priorityList = AEApi.instance().storage().createFluidList(); - for (int x = 0; x < config.getSizeInventory(); x++) { - final ItemStack is = config.getStackInSlot(x); - final FluidStack fluid = Util.getFluidFromItem(is); - if (fluid != null) { - AEFluidStack stack = AEFluidStack.create(fluid); - stack.setStackSize(1); - priorityList.add(stack); - - // convert partition on cells in network - if (!(is.getItem() instanceof ItemFluidPacket)) { - config.setInventorySlotContents(x, ItemFluidPacket.newDisplayStack(fluid)); - config.markDirty(); - } - } - } - if (!priorityList.isEmpty()) { - this.setPartitionList(new PrecisePriorityList<>(priorityList)); - } - - final IInventory upgrades = ci.getUpgradesInventory(); - boolean hasSticky = false; - - for (int x = 0; x < upgrades.getSizeInventory(); x++) { - final ItemStack is = upgrades.getStackInSlot(x); - if (is != null && is.getItem() instanceof IUpgradeModule) { - final Upgrades u = ((IUpgradeModule) is.getItem()).getType(is); - if (u == Upgrades.STICKY) { - hasSticky = true; - break; - } - } - } - - if (hasSticky) { - setSticky(true); - } - } - } - - @Override - public IFluidCellInventory getCellInv() { - Object o = this.getInternal(); - if (o instanceof MEPassThroughpt) { - o = pt.getInternal(); - } - return (IFluidCellInventory) (o instanceof IFluidCellInventory ? o : null); - } - - @Override - @SuppressWarnings("unchecked") - public Iterable getPartitionInv() { - return getPartitionList().getItems(); - } - - @Override - public boolean isPreformatted() { - return !getPartitionList().isEmpty(); - } - - @Override - @Deprecated - public IncludeExclude getIncludeExcludeMode() { - return getWhitelist(); - } - - @Override - public IncludeExclude getWhitelist() { - return IncludeExclude.WHITELIST; - } - - public int getStatusForCell() { - int val = this.getCellInv().getStatusForCell(); - - if ((val == 1 || val == 2) && this.isPreformatted()) { - val = 3; - } - - return val; - } - - @Override - public boolean canGetInv() { - IFluidCellInventory cellInv = this.getCellInv(); - return !(cellInv instanceof CreativeFluidCellInventory); - } - - @Override - public long getTotalBytes() { - return this.getCellInv().getTotalBytes(); - } - - @Override - public long getFreeBytes() { - return this.getCellInv().getFreeBytes(); - } - - @Override - public long getUsedBytes() { - return this.getCellInv().getUsedBytes(); - } - - @Override - public long getTotalTypes() { - return this.getCellInv().getTotalFluidTypes(); - } - - @Override - public long getFreeTypes() { - return this.getCellInv().getRemainingFluidTypes(); - } - - @Override - public long getUsedTypes() { - return this.getCellInv().getStoredFluidTypes(); - } - - @Override - public int getCellStatus() { - return this.getStatusForCell(); - } - - @Override - public TYPE getCellType() { - return TYPE.FLUID; - } - - public List getRestricted() { - IFluidCellInventory cellInventory = this.getCellInv(); - if (cellInventory instanceof FluidCellInventory ci) { - return ci.getRestriction(); - } - return null; - } -} diff --git a/src/main/java/com/glodblock/github/common/storage/FluidVoidStorageCellInventory.java b/src/main/java/com/glodblock/github/common/storage/FluidVoidStorageCellInventory.java deleted file mode 100644 index bc5635d9..00000000 --- a/src/main/java/com/glodblock/github/common/storage/FluidVoidStorageCellInventory.java +++ /dev/null @@ -1,118 +0,0 @@ -package com.glodblock.github.common.storage; - -import java.util.Collections; -import java.util.List; - -import javax.annotation.Nonnull; - -import net.minecraft.item.ItemStack; - -import org.jetbrains.annotations.NotNull; - -import appeng.api.config.Actionable; -import appeng.api.exceptions.AppEngException; -import appeng.api.networking.security.BaseActionSource; -import appeng.api.storage.ISaveProvider; -import appeng.api.storage.data.IAEFluidStack; -import appeng.api.storage.data.IItemList; - -public class FluidVoidStorageCellInventory extends FluidCellInventory { - - public FluidVoidStorageCellInventory(ItemStack o, ISaveProvider container) throws AppEngException { - super(o, container); - } - - @Override - public boolean canHoldNewFluid() { - return true; - } - - @Override - public long getTotalBytes() { - return 0; - } - - @Override - public long getFreeBytes() { - return 0; - } - - @Override - public long getUsedBytes() { - return 0; - } - - @Override - public long getTotalFluidTypes() { - return 63; - } - - @Override - public long getStoredFluidCount() { - return 0; - } - - @Override - public long getStoredFluidTypes() { - return 0; - } - - @Override - public long getRemainingFluidTypes() { - return 63; - } - - @Override - public long getRemainingFluidCount() { - return Long.MAX_VALUE; - } - - @Override - public int getUnusedFluidCount() { - return Integer.MAX_VALUE; - } - - @Override - public int getStatusForCell() { - return 1; - } - - @Override - protected void loadCellFluids() {} - - @Override - protected IItemList getCellFluids() { - return null; - } - - @Override - public IAEFluidStack injectItems(IAEFluidStack input, Actionable mode, BaseActionSource src) { - if (input == null || input.getStackSize() == 0) { - return null; - } - if (this.cellType.isBlackListed(this.cellItem, input)) { - return input; - } - return null; - } - - @Override - public IAEFluidStack extractItems(IAEFluidStack request, Actionable mode, BaseActionSource src) { - return null; - } - - @Override - public IItemList getAvailableItems(IItemList out, int iteration) { - return out; - } - - @Override - public IAEFluidStack getAvailableItem(@Nonnull IAEFluidStack request, int iteration) { - return null; - } - - @Override - public @NotNull List getContents() { - return Collections.emptyList(); - } -} diff --git a/src/main/java/com/glodblock/github/common/storage/IFluidCellInventory.java b/src/main/java/com/glodblock/github/common/storage/IFluidCellInventory.java deleted file mode 100644 index c1c4384e..00000000 --- a/src/main/java/com/glodblock/github/common/storage/IFluidCellInventory.java +++ /dev/null @@ -1,102 +0,0 @@ -package com.glodblock.github.common.storage; - -import java.util.List; - -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; - -import org.jetbrains.annotations.NotNull; - -import appeng.api.storage.IMEInventory; -import appeng.api.storage.data.IAEFluidStack; - -public interface IFluidCellInventory extends IMEInventory { - - /** - * @return the item stack of this storage cell. - */ - ItemStack getItemStack(); - - /** - * @return idle cost for this Storage Cell - */ - double getIdleDrain(ItemStack is); - - /** - * @return access configured list - */ - IInventory getConfigInventory(); - - /** - * @return How many bytes are used for each type? - */ - int getBytesPerType(); - - /** - * @return true if a new fluid type can be added. - */ - boolean canHoldNewFluid(); - - /** - * @return total byte storage. - */ - long getTotalBytes(); - - /** - * @return how many bytes are free. - */ - long getFreeBytes(); - - /** - * @return how many bytes are in use. - */ - long getUsedBytes(); - - /** - * @return how many fluids are stored. - */ - long getStoredFluidCount(); - - /** - * @return how many more fluids can be stored. - */ - long getRemainingFluidCount(); - - /** - * @return how many more fluids can be stored with Distribution card. - */ - long getRemainingFluidCountDist(IAEFluidStack l); - - /** - * @return how many fluid types remain. - */ - long getRemainingFluidTypes(); - - /** - * @return how many fluids can be added without consuming another byte. - */ - int getUnusedFluidCount(); - - /** - * @return the status number for this drive. - */ - int getStatusForCell(); - - /** - * @return how many items types are currently stored. - */ - long getStoredFluidTypes(); - - /** - * @return max number of types. - */ - long getTotalFluidTypes(); - - @NotNull - List getContents(); - - /** - * @return access installed upgrades. - */ - IInventory getUpgradesInventory(); -} diff --git a/src/main/java/com/glodblock/github/common/storage/IFluidCellInventoryHandler.java b/src/main/java/com/glodblock/github/common/storage/IFluidCellInventoryHandler.java deleted file mode 100644 index 13f7dfd1..00000000 --- a/src/main/java/com/glodblock/github/common/storage/IFluidCellInventoryHandler.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.glodblock.github.common.storage; - -import appeng.api.config.IncludeExclude; -import appeng.api.storage.data.IAEFluidStack; - -public interface IFluidCellInventoryHandler { - - IFluidCellInventory getCellInv(); - - Iterable getPartitionInv(); - - boolean isPreformatted(); - - /** use {@link IFluidCellInventoryHandler#getWhitelist} instead */ - @Deprecated - IncludeExclude getIncludeExcludeMode(); - - IncludeExclude getWhitelist(); -} diff --git a/src/main/java/com/glodblock/github/common/storage/IStorageFluidCell.java b/src/main/java/com/glodblock/github/common/storage/IStorageFluidCell.java deleted file mode 100644 index 3e6bdc3d..00000000 --- a/src/main/java/com/glodblock/github/common/storage/IStorageFluidCell.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.glodblock.github.common.storage; - -import net.minecraft.item.ItemStack; - -import appeng.api.storage.ICellWorkbenchItem; -import appeng.api.storage.data.IAEFluidStack; - -public interface IStorageFluidCell extends ICellWorkbenchItem { - - long getBytes(ItemStack cellItem); - - int getBytesPerType(ItemStack cellItem); - - boolean isBlackListed(ItemStack cellItem, IAEFluidStack requestedAddition); - - boolean storableInStorageCell(); - - boolean isStorageCell(ItemStack i); - - double getIdleDrain(ItemStack is); - - int getTotalTypes(ItemStack cellItem); -} diff --git a/src/main/java/com/glodblock/github/common/tile/TileFluidAutoFiller.java b/src/main/java/com/glodblock/github/common/tile/TileFluidAutoFiller.java index 48422567..d6f9d4b6 100644 --- a/src/main/java/com/glodblock/github/common/tile/TileFluidAutoFiller.java +++ b/src/main/java/com/glodblock/github/common/tile/TileFluidAutoFiller.java @@ -45,6 +45,7 @@ import appeng.api.networking.ticking.TickingRequest; import appeng.api.storage.IMEMonitorHandlerReceiver; import appeng.api.storage.data.IAEFluidStack; import appeng.api.storage.data.IAEItemStack; +import appeng.api.storage.data.IAEStack; import appeng.api.storage.data.IItemList; import appeng.api.util.AECableType; import appeng.api.util.DimensionalCoord; @@ -59,7 +60,7 @@ import appeng.util.item.AEItemStack; import cpw.mods.fml.common.registry.GameRegistry; public class TileFluidAutoFiller extends AENetworkInvTile - implements ICraftingProvider, IMEMonitorHandlerReceiver, IGridTickable { + implements ICraftingProvider, IMEMonitorHandlerReceiver>, IGridTickable { private final AppEngInternalInventory inventory = new AppEngInternalInventory(this, 1); private final BaseActionSource source = new MachineSource(this); @@ -214,14 +215,13 @@ public class TileFluidAutoFiller extends AENetworkInvTile } @Override - public void postChange(IBaseMonitor monitor, Iterable change, - BaseActionSource source) { + public void postChange(IBaseMonitor> monitor, Iterable> change, BaseActionSource source) { if (this.getProxy().isActive() && this.getStorageGrid() != null) { boolean hasChanged = false; - for (IAEFluidStack tmp : change) { - if (this.fluids.findPrecise(tmp) == null) { + for (IAEStack tmp : change) { + if (this.fluids.findPrecise((IAEFluidStack) tmp) == null) { hasChanged = true; - this.fluids.add(tmp); + this.fluids.add((IAEFluidStack) tmp); } } if (hasChanged) postEvent(); diff --git a/src/main/java/com/glodblock/github/common/tile/TileFluidDiscretizer.java b/src/main/java/com/glodblock/github/common/tile/TileFluidDiscretizer.java index f7cd3fa4..0197e6d9 100644 --- a/src/main/java/com/glodblock/github/common/tile/TileFluidDiscretizer.java +++ b/src/main/java/com/glodblock/github/common/tile/TileFluidDiscretizer.java @@ -1,258 +1,10 @@ package com.glodblock.github.common.tile; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import javax.annotation.Nonnull; - -import com.glodblock.github.api.FluidCraftAPI; -import com.glodblock.github.common.item.ItemFluidDrop; - -import appeng.api.AEApi; -import appeng.api.config.Actionable; -import appeng.api.networking.GridFlags; -import appeng.api.networking.energy.IEnergyGrid; -import appeng.api.networking.events.MENetworkCellArrayUpdate; -import appeng.api.networking.events.MENetworkChannelsChanged; -import appeng.api.networking.events.MENetworkEventSubscribe; -import appeng.api.networking.events.MENetworkPowerStatusChange; -import appeng.api.networking.events.MENetworkStorageEvent; -import appeng.api.networking.security.BaseActionSource; -import appeng.api.networking.security.MachineSource; -import appeng.api.networking.storage.IBaseMonitor; -import appeng.api.networking.storage.IStorageGrid; -import appeng.api.storage.ICellContainer; -import appeng.api.storage.IMEInventory; -import appeng.api.storage.IMEInventoryHandler; -import appeng.api.storage.IMEMonitor; -import appeng.api.storage.IMEMonitorHandlerReceiver; -import appeng.api.storage.StorageChannel; -import appeng.api.storage.data.IAEFluidStack; -import appeng.api.storage.data.IAEItemStack; -import appeng.api.storage.data.IItemList; -import appeng.helpers.IPriorityHost; -import appeng.me.GridAccessException; -import appeng.me.storage.MEInventoryHandler; import appeng.tile.grid.AENetworkTile; -public class TileFluidDiscretizer extends AENetworkTile implements IPriorityHost, ICellContainer { - - private final BaseActionSource ownActionSource = new MachineSource(this); - private final FluidDiscretizingInventory fluidDropInv = new FluidDiscretizingInventory(); - private boolean prevActiveState = false; +public class TileFluidDiscretizer extends AENetworkTile { public TileFluidDiscretizer() { super(); - getProxy().setIdlePowerUsage(3D); - getProxy().setFlags(GridFlags.REQUIRE_CHANNEL); - } - - @Override - public boolean canBeRotated() { - return false; - } - - @Override - @SuppressWarnings("rawtypes") - public List getCellArray(StorageChannel channel) { - if (channel == StorageChannel.ITEMS && getProxy().isActive()) { - return Collections.singletonList(fluidDropInv.invHandler); - } - return Collections.emptyList(); - } - - @Override - public int getPriority() { - return Integer.MAX_VALUE; - } - - @Override - public void setPriority(int newValue) { - // do nothing - } - - @Override - public void gridChanged() { - IMEMonitor fluidGrid = getFluidGrid(); - if (fluidGrid != null) { - fluidGrid.addListener(fluidDropInv, fluidGrid); - } - } - - @Override - public void saveChanges(@SuppressWarnings("rawtypes") IMEInventory cellInventory) { - markDirty(); - } - - private IMEMonitor getFluidGrid() { - try { - return getProxy().getGrid().getCache(IStorageGrid.class).getFluidInventory(); - } catch (GridAccessException e) { - return null; - } - } - - private IEnergyGrid getEnergyGrid() { - try { - return getProxy().getGrid().getCache(IEnergyGrid.class); - } catch (GridAccessException e) { - return null; - } - } - - private void updateState() { - boolean isActive = getProxy().isActive(); - if (isActive != prevActiveState) { - prevActiveState = isActive; - try { - getProxy().getGrid().postEvent(new MENetworkCellArrayUpdate()); - } catch (GridAccessException e) { - // NO-OP - } - } - } - - @MENetworkEventSubscribe - public void onPowerUpdate(MENetworkPowerStatusChange event) { - updateState(); - } - - @MENetworkEventSubscribe - public void onChannelUpdate(MENetworkChannelsChanged event) { - updateState(); - } - - @MENetworkEventSubscribe - public void onStorageUpdate(MENetworkStorageEvent event) { - updateState(); - } - - private class FluidDiscretizingInventory - implements IMEInventory, IMEMonitorHandlerReceiver { - - private final MEInventoryHandler invHandler = new MEInventoryHandler<>(this, getChannel()); - private IItemList itemCache = null; - - FluidDiscretizingInventory() { - invHandler.setPriority(Integer.MAX_VALUE); - } - - @Override - public IAEItemStack injectItems(IAEItemStack request, Actionable type, BaseActionSource src) { - IAEFluidStack fluidStack = ItemFluidDrop.getAeFluidStack(request); - if (fluidStack == null) { - return request; - } - IMEMonitor fluidGrid = getFluidGrid(); - if (fluidGrid == null) { - return request; - } - IEnergyGrid energyGrid = getEnergyGrid(); - if (energyGrid == null) { - return request; - } - if (type == Actionable.SIMULATE) { - return ItemFluidDrop.newAeStack(fluidGrid.injectItems(fluidStack.copy(), Actionable.SIMULATE, src)); - } else { - return ItemFluidDrop.newAeStack(fluidGrid.injectItems(fluidStack.copy(), Actionable.MODULATE, src)); - } - } - - @Override - public IAEItemStack extractItems(IAEItemStack request, Actionable mode, BaseActionSource src) { - IAEFluidStack fluidStack = ItemFluidDrop.getAeFluidStack(request); - if (fluidStack == null) { - return null; - } - IMEMonitor fluidGrid = getFluidGrid(); - if (fluidGrid == null) { - return null; - } - IEnergyGrid energyGrid = getEnergyGrid(); - if (energyGrid == null) { - return null; - } - if (mode == Actionable.SIMULATE) { - return ItemFluidDrop.newAeStack(fluidGrid.extractItems(fluidStack.copy(), Actionable.SIMULATE, src)); - } else { - return ItemFluidDrop.newAeStack(fluidGrid.extractItems(fluidStack.copy(), Actionable.MODULATE, src)); - } - } - - @Override - public IItemList getAvailableItems(IItemList out, int iteration) { - if (itemCache == null) { - itemCache = AEApi.instance().storage().createItemList(); - IMEMonitor fluidGrid = getFluidGrid(); - if (fluidGrid != null) { - for (IAEFluidStack fluid : fluidGrid.getStorageList()) { - IAEItemStack stack = ItemFluidDrop.newAeStack(fluid); - if (stack != null - && !FluidCraftAPI.instance().isBlacklistedInDisplay(fluid.getFluid().getClass())) { - itemCache.add(stack); - } - } - } - } - for (IAEItemStack stack : itemCache) { - out.addStorage(stack); - } - return out; - } - - @Override - public IAEItemStack getAvailableItem(@Nonnull IAEItemStack request, int iteration) { - IMEMonitor fluidGrid = getFluidGrid(); - if (fluidGrid == null) { - return null; - } - IAEFluidStack fluidRequest = ItemFluidDrop.getAeFluidStack(request); - if (fluidRequest == null) { - return null; - } - IAEFluidStack availableFluid = fluidGrid.getAvailableItem(fluidRequest, iteration); - if (availableFluid == null || availableFluid.getFluid() == null - || FluidCraftAPI.instance().isBlacklistedInDisplay(availableFluid.getFluid().getClass())) { - return null; - } - return ItemFluidDrop.newAeStack(availableFluid); - } - - @Override - public StorageChannel getChannel() { - return StorageChannel.ITEMS; - } - - @Override - public boolean isValid(Object verificationToken) { - IMEMonitor fluidGrid = getFluidGrid(); - return fluidGrid != null && fluidGrid == verificationToken; - } - - @Override - public void postChange(IBaseMonitor monitor, Iterable change, - BaseActionSource actionSource) { - itemCache = null; - try { - List mappedChanges = new ArrayList<>(); - for (IAEFluidStack fluidStack : change) { - IAEItemStack itemStack = ItemFluidDrop.newAeStack(fluidStack); - if (itemStack != null - && !FluidCraftAPI.instance().isBlacklistedInDisplay(fluidStack.getFluid().getClass())) { - mappedChanges.add(itemStack); - } - } - getProxy().getGrid().getCache(IStorageGrid.class) - .postAlterationOfStoredItems(getChannel(), mappedChanges, ownActionSource); - } catch (GridAccessException e) { - // NO-OP - } - } - - @Override - public void onListUpdate() { - // NO-OP - } } } diff --git a/src/main/java/com/glodblock/github/common/tile/TileFluidInterface.java b/src/main/java/com/glodblock/github/common/tile/TileFluidInterface.java index f4f50547..a2c8e701 100644 --- a/src/main/java/com/glodblock/github/common/tile/TileFluidInterface.java +++ b/src/main/java/com/glodblock/github/common/tile/TileFluidInterface.java @@ -5,6 +5,7 @@ import java.util.List; import javax.annotation.Nullable; +import net.minecraft.client.gui.GuiButton; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; @@ -13,6 +14,7 @@ import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTankInfo; +import com.glodblock.github.client.FluidInterfaceButtons; import com.glodblock.github.common.item.ItemFluidPacket; import com.glodblock.github.inventory.AEFluidInventory; import com.glodblock.github.inventory.IAEFluidTank; @@ -32,17 +34,23 @@ import appeng.api.networking.ticking.TickRateModulation; import appeng.api.networking.ticking.TickingRequest; import appeng.api.storage.data.IAEFluidStack; import appeng.api.util.IConfigManager; +import appeng.helpers.ICustomButtonDataObject; +import appeng.helpers.ICustomButtonProvider; import appeng.tile.TileEvent; import appeng.tile.events.TileEventType; import appeng.tile.inventory.AppEngInternalAEInventory; import appeng.tile.misc.TileInterface; import cpw.mods.fml.common.network.ByteBufUtils; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; import io.netty.buffer.ByteBuf; -public class TileFluidInterface extends TileInterface implements IDualHost { +public class TileFluidInterface extends TileInterface implements IDualHost, ICustomButtonProvider { private final IConfigManager dualityConfigManager = getInterfaceDuality().getConfigManager(); + private ICustomButtonDataObject customButtonDataObject; + private final DualityFluidInterface fluidDuality = new DualityFluidInterface(this.getProxy(), this) { @Override @@ -59,6 +67,7 @@ public class TileFluidInterface extends TileInterface implements IDualHost { public TileFluidInterface() { super.getInterfaceDuality().getConfigManager().registerSetting(Settings.SIDELESS_MODE, SidelessMode.SIDELESS); + this.customButtonDataObject = new FluidInterfaceButtons(true); } @MENetworkEventSubscribe @@ -226,4 +235,39 @@ public class TileFluidInterface extends TileInterface implements IDualHost { this.fluidDuality.addDrops(drops); super.getDrops(w, x, y, z, drops); } + + @Override + public ItemStack getPrimaryGuiIcon() { + return ItemAndBlockHolder.INTERFACE.stack(); + } + + @Override + public void writeCustomButtonData() {} + + @Override + public void readCustomButtonData() {} + + @SideOnly(Side.CLIENT) + @Override + public void initCustomButtons(int guiLeft, int guiTop, int xSize, int ySize, int xOffset, int yOffset, + List buttonList) { + if (customButtonDataObject != null) + customButtonDataObject.initCustomButtons(guiLeft, guiTop, xSize, ySize, xOffset, yOffset, buttonList); + } + + @SideOnly(Side.CLIENT) + @Override + public boolean actionPerformedCustomButtons(final GuiButton btn) { + return customButtonDataObject != null && customButtonDataObject.actionPerformedCustomButtons(btn); + } + + @Override + public ICustomButtonDataObject getDataObject() { + return customButtonDataObject; + } + + @Override + public void setDataObject(ICustomButtonDataObject dataObject) { + customButtonDataObject = dataObject; + } } diff --git a/src/main/java/com/glodblock/github/common/tile/TileLevelMaintainer.java b/src/main/java/com/glodblock/github/common/tile/TileLevelMaintainer.java index 3d275b9b..60c21155 100644 --- a/src/main/java/com/glodblock/github/common/tile/TileLevelMaintainer.java +++ b/src/main/java/com/glodblock/github/common/tile/TileLevelMaintainer.java @@ -1,10 +1,8 @@ package com.glodblock.github.common.tile; import java.util.Arrays; -import java.util.Iterator; import java.util.Objects; import java.util.concurrent.Future; -import java.util.stream.Stream; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; @@ -17,20 +15,18 @@ import net.minecraftforge.common.util.ForgeDirection; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import com.glodblock.github.api.registries.ILevelViewable; -import com.glodblock.github.api.registries.LevelItemInfo; -import com.glodblock.github.api.registries.LevelState; import com.glodblock.github.common.Config; import com.glodblock.github.common.item.ItemFluidDrop; import com.glodblock.github.crossmod.thaumcraft.ThaumicEnergisticsCrafting; -import com.glodblock.github.inventory.AeItemStackHandler; -import com.glodblock.github.inventory.AeStackInventory; import com.glodblock.github.util.ModAndClassUtil; import com.google.common.collect.ImmutableSet; import appeng.api.AEApi; import appeng.api.config.Actionable; import appeng.api.config.PowerMultiplier; +import appeng.api.features.ILevelViewable; +import appeng.api.features.LevelItemInfo; +import appeng.api.features.LevelState; import appeng.api.implementations.IPowerChannelState; import appeng.api.networking.GridFlags; import appeng.api.networking.IGrid; @@ -49,8 +45,10 @@ import appeng.api.networking.security.MachineSource; import appeng.api.networking.ticking.IGridTickable; import appeng.api.networking.ticking.TickRateModulation; import appeng.api.networking.ticking.TickingRequest; +import appeng.api.storage.StorageName; import appeng.api.storage.data.IAEFluidStack; import appeng.api.storage.data.IAEItemStack; +import appeng.api.storage.data.IAEStack; import appeng.api.storage.data.IItemList; import appeng.core.AELog; import appeng.me.GridAccessException; @@ -58,7 +56,9 @@ import appeng.tile.TileEvent; import appeng.tile.events.TileEventType; import appeng.tile.grid.AENetworkTile; import appeng.tile.inventory.IAEAppEngInventory; +import appeng.tile.inventory.IAEStackInventory; import appeng.tile.inventory.InvOperation; +import appeng.util.Platform; import appeng.util.SettingsFrom; import appeng.util.item.AEItemStack; import io.netty.buffer.ByteBuf; @@ -76,10 +76,9 @@ public class TileLevelMaintainer extends AENetworkTile public static final String NBT_LINK = "link"; public final RequestInfo[] requests = new RequestInfo[REQ_COUNT]; - private final LevelMaintainerInventory inventory = new LevelMaintainerInventory(requests, this); + private final LevelMaintainerInventory inventory = new LevelMaintainerInventory(requests); private int firstRequest = 0; private final BaseActionSource source; - private final IInventory inv = new AeItemStackHandler(inventory); private boolean isPowered = false; public TileLevelMaintainer() { @@ -88,7 +87,7 @@ public class TileLevelMaintainer extends AENetworkTile source = new MachineSource(this); } - public AeStackInventory getRequestSlots() { + public IAEStackInventory getAEStackInventory() { return inventory; } @@ -181,7 +180,7 @@ public class TileLevelMaintainer extends AENetworkTile // If there is none, find the next request we can begin calculating. ICraftingJob jobToSubmit = null; int jobToSubmitIdx = -1; - IAEItemStack itemToBegin = null; + IAEStack itemToBegin = null; int itemToBeginIdx = -1; for (int j = 0; j < REQ_COUNT; ++j) { @@ -197,29 +196,27 @@ public class TileLevelMaintainer extends AENetworkTile continue; } - IAEItemStack craftItem = requests[i].itemStack.copy(); + IAEStack aeItem = null; + + IAEStack craftItem = requests[i].stack.copy(); craftItem.setStackSize(batchSize); - if (ModAndClassUtil.ThE) { - if (ThaumicEnergisticsCrafting.isAspectStack(craftItem.getItemStack())) { - craftItem = ThaumicEnergisticsCrafting.convertAspectStack(craftItem); + if (craftItem instanceof IAEItemStack ais) { + if (ModAndClassUtil.ThE && ThaumicEnergisticsCrafting.isAspectStack(ais.getItemStack())) { + aeItem = ThaumicEnergisticsCrafting.convertAspectStack(ais); + } else { + aeItem = invItems.findPrecise(ais); } + } else if (craftItem instanceof IAEFluidStack afs) { + aeItem = invFluid.findPrecise(afs); } - IAEItemStack aeItem = invItems.findPrecise(craftItem); - - long stackSize; - - if (craftItem.getItem() instanceof ItemFluidDrop) { - IAEFluidStack ifs = invFluid.findPrecise(ItemFluidDrop.getAeFluidStack(craftItem)); - stackSize = ifs == null ? 0 : ifs.getStackSize(); - } else { - stackSize = aeItem == null ? 0 : aeItem.getStackSize(); - } + long stackSize = aeItem == null ? 0 : aeItem.getStackSize(); if (ModAndClassUtil.ThE) { - if (aeItem != null && ThaumicEnergisticsCrafting.isAspectStack(aeItem.getItemStack())) { - stackSize = ThaumicEnergisticsCrafting.getEssentiaAmount(aeItem, grid); + if (aeItem instanceof IAEItemStack ais + && ThaumicEnergisticsCrafting.isAspectStack(ais.getItemStack())) { + stackSize = ThaumicEnergisticsCrafting.getEssentiaAmount(ais, grid); } } @@ -243,11 +240,11 @@ public class TileLevelMaintainer extends AENetworkTile continue; } - if (craftingGrid.canEmitFor(craftItem)) { + if (craftingGrid.canEmitFor(aeItem)) { continue; } - if (craftingGrid.isRequesting(craftItem)) { + if (craftingGrid.isRequesting(aeItem)) { continue; } @@ -338,22 +335,12 @@ public class TileLevelMaintainer extends AENetworkTile return isPowered; } - public IInventory getInventory() { - return inv; - } - - public IInventory getInventoryByName(String name) { - if (Objects.equals(name, "config")) return new AeItemStackHandler(this.inventory); - - return null; - } - @Override public LevelItemInfo[] getLevelItemInfoList() { return Arrays.stream(this.requests).map(request -> { if (request == null) return null; return new LevelItemInfo( - request.itemStack.getItemStack(), + request.getAEStack(), request.getQuantity(), request.getBatchSize(), request.getState()); @@ -387,11 +374,10 @@ public class TileLevelMaintainer extends AENetworkTile this.saveChanges(); } - public void updateStack(int idx, @Nullable ItemStack stack) { + public void updateStack(int idx, @Nullable IAEStack stack) { if (stack == null) { requests[idx] = null; } else { - stack = this.removeRecursion(stack); requests[idx] = new RequestInfo(stack, this); } this.saveChanges(); @@ -481,7 +467,7 @@ public class TileLevelMaintainer extends AENetworkTile ItemStack craftStack = ItemStack.loadItemStackFromNBT(itemTag.getCompoundTag("Stack")); craftStack = removeRecursion(craftStack); if (craftStack == null) continue; - requests[i] = new RequestInfo(craftStack, this); + requests[i] = new RequestInfo(Platform.convertStack(AEItemStack.create(craftStack)), this); if (itemTag.hasKey("Enable")) { requests[i].enable = itemTag.getBoolean("Enable"); } @@ -522,7 +508,7 @@ public class TileLevelMaintainer extends AENetworkTile for (int i = 0; i < REQ_COUNT; i++) { if (stacks[i] == null) continue; - this.requests[i] = new RequestInfo(stacks[i], this); + this.requests[i] = new RequestInfo(Platform.convertStack(AEItemStack.create(stacks[i])), this); this.requests[i].batchSize = batches[i]; this.requests[i].quantity = quantyties[i]; } @@ -631,7 +617,7 @@ public class TileLevelMaintainer extends AENetworkTile public static class RequestInfo { private final TileLevelMaintainer tile; - private @NotNull IAEItemStack itemStack; + private @NotNull IAEStack stack; private long quantity; private long batchSize; private boolean enable; @@ -641,9 +627,9 @@ public class TileLevelMaintainer extends AENetworkTile @Nullable private ICraftingLink link; - public RequestInfo(@NotNull ItemStack stack, TileLevelMaintainer tile) { + public RequestInfo(@NotNull IAEStack stack, TileLevelMaintainer tile) { this.tile = tile; - itemStack = AEItemStack.create(stack); + this.stack = stack.copy(); quantity = 0; batchSize = 0; enable = false; @@ -654,8 +640,8 @@ public class TileLevelMaintainer extends AENetworkTile public RequestInfo(NBTTagCompound tag, TileLevelMaintainer tile) throws IllegalArgumentException { this.tile = tile; - itemStack = AEItemStack.loadItemStackFromNBT(tag.getCompoundTag(NBT_STACK)); - if (itemStack == null) { + stack = Platform.readStackNBT(tag.getCompoundTag(NBT_STACK), true); + if (stack == null) { throw new IllegalArgumentException("ItemStack cannot be null!"); } quantity = tag.getLong(NBT_QUANTITY); @@ -673,7 +659,7 @@ public class TileLevelMaintainer extends AENetworkTile } public void loadFromNBT(NBTTagCompound tag) { - itemStack = AEItemStack.loadItemStackFromNBT(tag.getCompoundTag(NBT_STACK)); + stack = Platform.readStackNBT(tag.getCompoundTag(NBT_STACK), true); quantity = tag.getLong(NBT_QUANTITY); batchSize = tag.getLong(NBT_BATCH); enable = tag.getBoolean(NBT_ENABLE); @@ -690,7 +676,7 @@ public class TileLevelMaintainer extends AENetworkTile public NBTTagCompound writeToNBT(boolean includeLink) { NBTTagCompound tag = new NBTTagCompound(); NBTTagCompound stackTag = new NBTTagCompound(); - itemStack.writeToNBT(stackTag); + Platform.writeStackNBT(stack, stackTag, true); tag.setTag(NBT_STACK, stackTag); tag.setLong(NBT_QUANTITY, quantity); tag.setLong(NBT_BATCH, batchSize); @@ -704,8 +690,9 @@ public class TileLevelMaintainer extends AENetworkTile return tag; } - public IAEItemStack getAEItemStack() { - return this.itemStack; + @NotNull + public IAEStack getAEStack() { + return this.stack; } public long getQuantity() { @@ -725,43 +712,34 @@ public class TileLevelMaintainer extends AENetworkTile } } - private static class LevelMaintainerInventory implements AeStackInventory { + private class LevelMaintainerInventory extends IAEStackInventory { - private final RequestInfo[] requests; - private final TileLevelMaintainer tile; - - private LevelMaintainerInventory(RequestInfo[] requests, TileLevelMaintainer tile) { - this.requests = requests; - this.tile = tile; + public LevelMaintainerInventory(RequestInfo[] requests) { + super(null, requests.length, StorageName.NONE); } @Override - public @NotNull Iterator iterator() { - return Arrays.stream(requests).map(info -> info != null ? info.itemStack : null).iterator(); - } - - @Override - public int getSlotCount() { + public int getSizeInventory() { return requests.length; } @Override - public @Nullable IAEItemStack getStack(int slot) { - return requests[slot] != null ? requests[slot].itemStack : null; - } - - @Override - public void setStack(int slot, @Nullable IAEItemStack stack) { - if (stack == null) { - this.tile.updateStack(slot, null); - } else { - this.tile.updateStack(slot, stack.getItemStack()); + public IAEStack getAEStackInSlot(int n) { + if (requests[n] != null) { + return requests[n].stack; } + return null; } @Override - public Stream stream() { - return Arrays.stream(requests).map(info -> info != null ? info.itemStack : null); + public void putAEStackInSlot(int slot, IAEStack aes) { + updateStack(slot, aes); + super.putAEStackInSlot(slot, aes); + } + + @Override + public void markDirty() { + } } } diff --git a/src/main/java/com/glodblock/github/common/tile/TileSuperStockReplenisher.java b/src/main/java/com/glodblock/github/common/tile/TileSuperStockReplenisher.java index a8921f8a..234b0ff1 100644 --- a/src/main/java/com/glodblock/github/common/tile/TileSuperStockReplenisher.java +++ b/src/main/java/com/glodblock/github/common/tile/TileSuperStockReplenisher.java @@ -34,10 +34,13 @@ import appeng.api.networking.security.MachineSource; import appeng.api.networking.ticking.IGridTickable; import appeng.api.networking.ticking.TickRateModulation; import appeng.api.networking.ticking.TickingRequest; +import appeng.api.storage.IMEMonitor; +import appeng.api.storage.ITerminalHost; import appeng.api.storage.data.IAEFluidStack; import appeng.api.storage.data.IAEItemStack; import appeng.api.util.AECableType; import appeng.api.util.DimensionalCoord; +import appeng.api.util.IConfigManager; import appeng.core.AELog; import appeng.items.storage.ItemBasicStorageCell; import appeng.me.GridAccessException; @@ -52,7 +55,7 @@ import appeng.util.item.AEItemStack; import io.netty.buffer.ByteBuf; public class TileSuperStockReplenisher extends AENetworkInvTile - implements IAEFluidInventory, IFluidHandler, IPowerChannelState, IGridTickable { + implements IAEFluidInventory, IFluidHandler, IPowerChannelState, IGridTickable, ITerminalHost { private final AppEngInternalInventory cell = new AppEngInternalInventory(this, 1); private final AppEngInternalInventory invItems = new AppEngInternalInventory(this, 63); @@ -461,4 +464,19 @@ public class TileSuperStockReplenisher extends AENetworkInvTile public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall) { return doWork(); } + + @Override + public IMEMonitor getItemInventory() { + return null; + } + + @Override + public IMEMonitor getFluidInventory() { + return null; + } + + @Override + public IConfigManager getConfigManager() { + return null; + } } diff --git a/src/main/java/com/glodblock/github/coremod/hooker/CoreModHooks.java b/src/main/java/com/glodblock/github/coremod/hooker/CoreModHooks.java index 4130ce06..7a98dd7b 100644 --- a/src/main/java/com/glodblock/github/coremod/hooker/CoreModHooks.java +++ b/src/main/java/com/glodblock/github/coremod/hooker/CoreModHooks.java @@ -4,7 +4,6 @@ import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; -import com.glodblock.github.client.gui.GuiFluidCraftConfirm; import com.glodblock.github.common.item.ItemFluidDrop; import com.glodblock.github.common.item.ItemFluidPacket; @@ -26,11 +25,4 @@ public class CoreModHooks { } return null; } - - public static boolean shouldShowTooltip(GuiContainer gui) { - if (gui instanceof GuiFluidCraftConfirm guiCraftConfirm) { - return guiCraftConfirm.getHoveredStack() == null; - } - return true; - } } diff --git a/src/main/java/com/glodblock/github/coremod/registries/LevelTerminalRegistry.java b/src/main/java/com/glodblock/github/coremod/registries/LevelTerminalRegistry.java index 326cda9d..480c1c60 100644 --- a/src/main/java/com/glodblock/github/coremod/registries/LevelTerminalRegistry.java +++ b/src/main/java/com/glodblock/github/coremod/registries/LevelTerminalRegistry.java @@ -6,13 +6,11 @@ import java.util.Set; import java.util.WeakHashMap; import com.glodblock.github.api.registries.ILevelTerminalRegistry; -import com.glodblock.github.api.registries.ILevelViewable; import com.glodblock.github.api.registries.ILevelViewableAdapter; import com.glodblock.github.common.parts.PartFluidLevelEmitter; import com.glodblock.github.common.tile.TileLevelMaintainer; -import com.glodblock.github.coremod.registries.adapters.PartFluidLevelEmitterAdapter; -import com.glodblock.github.coremod.registries.adapters.PartLevelEmitterAdapter; +import appeng.api.features.ILevelViewable; import appeng.api.networking.IGridHost; import appeng.parts.automation.PartLevelEmitter; @@ -29,8 +27,8 @@ public class LevelTerminalRegistry implements ILevelTerminalRegistry { { this.register(TileLevelMaintainer.class); - this.register(PartFluidLevelEmitter.class, new PartFluidLevelEmitterAdapter()); - this.register(PartLevelEmitter.class, new PartLevelEmitterAdapter()); + this.register(PartLevelEmitter.class); + this.register(PartFluidLevelEmitter.class); } public Set> getSupportedClasses() { diff --git a/src/main/java/com/glodblock/github/coremod/registries/adapters/PartFluidLevelEmitterAdapter.java b/src/main/java/com/glodblock/github/coremod/registries/adapters/PartFluidLevelEmitterAdapter.java deleted file mode 100644 index b9109783..00000000 --- a/src/main/java/com/glodblock/github/coremod/registries/adapters/PartFluidLevelEmitterAdapter.java +++ /dev/null @@ -1,90 +0,0 @@ -package com.glodblock.github.coremod.registries.adapters; - -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; -import net.minecraftforge.common.util.ForgeDirection; - -import com.glodblock.github.api.registries.ILevelViewable; -import com.glodblock.github.api.registries.ILevelViewableAdapter; -import com.glodblock.github.api.registries.LevelItemInfo; -import com.glodblock.github.api.registries.LevelState; -import com.glodblock.github.common.parts.PartFluidLevelEmitter; - -import appeng.api.networking.IGridHost; -import appeng.api.networking.IGridNode; -import appeng.api.util.AECableType; -import appeng.api.util.DimensionalCoord; - -public class PartFluidLevelEmitterAdapter implements ILevelViewable, ILevelViewableAdapter { - - private PartFluidLevelEmitter delegate; - - public PartFluidLevelEmitterAdapter() {} - - public ILevelViewable adapt(IGridHost gridHost) { - if (gridHost instanceof PartFluidLevelEmitter levelEmitter) this.delegate = levelEmitter; - return this; - }; - - @Override - public DimensionalCoord getLocation() { - return delegate.getLocation(); - } - - @Override - public TileEntity getTile() { - return delegate.getTile(); - } - - @Override - public ForgeDirection getSide() { - return delegate.getSide(); - } - - @Override - public IInventory getInventoryByName(String name) { - return delegate.getInventoryByName(name); - } - - @Override - public IGridNode getGridNode(ForgeDirection dir) { - return delegate.getGridNode(dir); - } - - @Override - public AECableType getCableConnectionType(ForgeDirection dir) { - return delegate.getCableConnectionType(dir); - } - - @Override - public void securityBreak() { - delegate.securityBreak(); - } - - @Override - public String getCustomName() { - return delegate.getCustomName(); - } - - @Override - public boolean hasCustomName() { - return delegate.hasCustomName(); - } - - @Override - public void setCustomName(String name) { - delegate.hasCustomName(); - } - - @Override - public LevelItemInfo[] getLevelItemInfoList() { - ItemStack stack = delegate.getInventoryByName("config").getStackInSlot(0); - if (stack == null) return new LevelItemInfo[] { null }; - return new LevelItemInfo[] { new LevelItemInfo( - stack, - delegate.getReportingValue(), - -1, - delegate.isProvidingStrongPower() > 0 ? LevelState.Craft : LevelState.Idle) }; - } -} diff --git a/src/main/java/com/glodblock/github/coremod/registries/adapters/PartLevelEmitterAdapter.java b/src/main/java/com/glodblock/github/coremod/registries/adapters/PartLevelEmitterAdapter.java deleted file mode 100644 index c799a452..00000000 --- a/src/main/java/com/glodblock/github/coremod/registries/adapters/PartLevelEmitterAdapter.java +++ /dev/null @@ -1,90 +0,0 @@ -package com.glodblock.github.coremod.registries.adapters; - -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; -import net.minecraftforge.common.util.ForgeDirection; - -import com.glodblock.github.api.registries.ILevelViewable; -import com.glodblock.github.api.registries.ILevelViewableAdapter; -import com.glodblock.github.api.registries.LevelItemInfo; -import com.glodblock.github.api.registries.LevelState; - -import appeng.api.networking.IGridHost; -import appeng.api.networking.IGridNode; -import appeng.api.util.AECableType; -import appeng.api.util.DimensionalCoord; -import appeng.parts.automation.PartLevelEmitter; - -public class PartLevelEmitterAdapter implements ILevelViewable, ILevelViewableAdapter { - - private PartLevelEmitter delegate; - - public PartLevelEmitterAdapter() {} - - public ILevelViewable adapt(IGridHost gridHost) { - if (gridHost instanceof PartLevelEmitter levelEmitter) this.delegate = levelEmitter; - return this; - } - - @Override - public DimensionalCoord getLocation() { - return delegate.getLocation(); - } - - @Override - public TileEntity getTile() { - return delegate.getTile(); - } - - @Override - public IInventory getInventoryByName(String name) { - return delegate.getInventoryByName(name); - } - - @Override - public IGridNode getGridNode(ForgeDirection dir) { - return delegate.getGridNode(dir); - } - - @Override - public AECableType getCableConnectionType(ForgeDirection dir) { - return delegate.getCableConnectionType(dir); - } - - @Override - public ForgeDirection getSide() { - return delegate.getSide(); - } - - @Override - public void securityBreak() { - delegate.securityBreak(); - } - - @Override - public String getCustomName() { - return delegate.getCustomName(); - } - - @Override - public boolean hasCustomName() { - return delegate.hasCustomName(); - } - - @Override - public void setCustomName(String name) { - delegate.hasCustomName(); - } - - @Override - public LevelItemInfo[] getLevelItemInfoList() { - ItemStack stack = delegate.getInventoryByName("config").getStackInSlot(0); - if (stack == null) return new LevelItemInfo[] { null }; - return new LevelItemInfo[] { new LevelItemInfo( - stack, - delegate.getReportingValue(), - -1, - delegate.isProvidingStrongPower() > 0 ? LevelState.Craft : LevelState.Idle) }; - } -} diff --git a/src/main/java/com/glodblock/github/crossmod/extracells/EC2Replacer.java b/src/main/java/com/glodblock/github/crossmod/extracells/EC2Replacer.java deleted file mode 100644 index a93898c9..00000000 --- a/src/main/java/com/glodblock/github/crossmod/extracells/EC2Replacer.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.glodblock.github.crossmod.extracells; - -import java.util.List; - -import net.minecraft.item.Item; - -import cpw.mods.fml.common.event.FMLMissingMappingsEvent; -import cpw.mods.fml.common.registry.GameRegistry; - -public class EC2Replacer { - - /** - * Should be called if and only if replaceEC2 config is true and EC2 not present. Registers proxy items for the - * entire EC2 mod. After running this once, you should set replaceEC2 back to false. - */ - public static void initReplacer() { - System.out.println("Extra Cells not detected, and configuration set. Replacing extra cells."); - ItemReplacements.postinit(); - } - - public static void replaceExtraCells(FMLMissingMappingsEvent event) { - List mappings = event.getAll(); - for (FMLMissingMappingsEvent.MissingMapping m : mappings) { - if (m.type == GameRegistry.Type.ITEM && ItemReplacements.registry.containsKey(m.name)) { - Item toRemap = ItemReplacements.registry.get(m.name); - m.remap(toRemap); - } - } - } -} diff --git a/src/main/java/com/glodblock/github/crossmod/extracells/ItemReplacements.java b/src/main/java/com/glodblock/github/crossmod/extracells/ItemReplacements.java deleted file mode 100644 index 26eda941..00000000 --- a/src/main/java/com/glodblock/github/crossmod/extracells/ItemReplacements.java +++ /dev/null @@ -1,321 +0,0 @@ -package com.glodblock.github.crossmod.extracells; - -import java.util.HashMap; -import java.util.Map; -import java.util.function.Function; - -import net.minecraft.item.Item; -import net.minecraft.nbt.NBTTagCompound; - -import com.glodblock.github.common.item.ItemBaseWirelessTerminal; -import com.glodblock.github.common.item.ItemMultiFluidStorageCell; -import com.glodblock.github.crossmod.extracells.parts.ProxyFluidBusIO; -import com.glodblock.github.crossmod.extracells.parts.ProxyFluidInterface; -import com.glodblock.github.crossmod.extracells.parts.ProxyFluidStorage; -import com.glodblock.github.crossmod.extracells.parts.ProxyLevelEmitter; -import com.glodblock.github.crossmod.extracells.parts.ProxyOreDictExportBus; -import com.glodblock.github.crossmod.extracells.parts.ProxyStorageMonitor; -import com.glodblock.github.crossmod.extracells.storage.ProxyExtremeStorageCell; -import com.glodblock.github.crossmod.extracells.storage.ProxyFluidStorageCell; -import com.glodblock.github.crossmod.extracells.storage.ProxyItemCellHandler; -import com.glodblock.github.crossmod.extracells.storage.ProxyItemStorageCell; -import com.glodblock.github.crossmod.extracells.storage.ProxyVoidCellHandler; -import com.glodblock.github.crossmod.extracells.storage.ProxyVoidStorageCell; -import com.glodblock.github.loader.ItemAndBlockHolder; - -import appeng.api.AEApi; -import appeng.api.definitions.IItemDefinition; -import cpw.mods.fml.common.Loader; -import cpw.mods.fml.common.Optional; -import cpw.mods.fml.common.registry.GameRegistry; -import li.cil.oc.api.Items; -import li.cil.oc.api.detail.ItemInfo; - -/** - * A shell class to organize proxy replacements and hide the ugliness - */ -public class ItemReplacements { - - protected static Map registry; - - static void postinit() { - registry = new HashMap<>(23); - ProxyFluidBusIO.init(); - ItemReplacements.proxyItems(); - ItemReplacements.proxyPartItems(); - if (Loader.isModLoaded("OpenComputers")) { - deprecateOC(); - } - } - - /** - * Register proxy items (non-parts) - */ - static void proxyItems() { - deprecateFluidStorage("storage.fluid", 0, ItemAndBlockHolder.CELL1KM, 1, 8, 0.5); - deprecateFluidStorage("storage.fluid", 1, ItemAndBlockHolder.CELL4KM, 4, 32, 1.0); - deprecateFluidStorage("storage.fluid", 2, ItemAndBlockHolder.CELL16KM, 16, 128, 1.5); - deprecateFluidStorage("storage.fluid", 3, ItemAndBlockHolder.CELL64KM, 64, 512, 2.0); - deprecateFluidStorage("storage.fluid", 4, ItemAndBlockHolder.CELL256KM, 256, 2048, 2.5); - deprecateFluidStorage("storage.fluid", 5, ItemAndBlockHolder.CELL1024KM, 1024, 8192, 3.0); - deprecateFluidStorage("storage.fluid", 6, ItemAndBlockHolder.CELL4096KM, 4096, 32768, 3.5); - deprecateFluidStorage("storage.fluid", 7, ItemAndBlockHolder.CELL16384KM, 16384, 131072, 4.0); - // Thanks, AEApi. - AEApi.instance().registries().cell().addCellHandler(new ProxyItemCellHandler()); - AEApi.instance().registries().cell().addCellHandler(new ProxyVoidCellHandler()); - deprecateItemStorage(0, AEApi.instance().definitions().items().cell256k(), 256, 2048, 2.5); - deprecateItemStorage(1, AEApi.instance().definitions().items().cell1024k(), 1024, 8192, 3.0); - deprecateItemStorage(2, AEApi.instance().definitions().items().cell4096k(), 4096, 32768, 3.5); - deprecateItemStorage(3, AEApi.instance().definitions().items().cell16384k(), 16384, 131072, 4.0); - deprecateItemStorage(4, AEApi.instance().definitions().items().cellContainer(), 65536, 8, 2.0, 1); - deprecateExtremeStorage( - "storage.physical.advanced.quantum", - 0, - AEApi.instance().definitions().items().cellQuantum(), - Integer.MAX_VALUE / 16, - 4096, - 1000.0); - deprecateExtremeStorage( - "storage.physical.advanced.singularity", - 0, - AEApi.instance().definitions().items().cellSingularity(), - Long.MAX_VALUE / 16, - 4096, - 15000.0); - // Deprecate void cell manually - ProxyVoidStorageCell voidCell = new ProxyVoidStorageCell(); - GameRegistry.registerItem(voidCell, "ec2placeholder.storage.physical.void"); - registry.put("extracells:storage.physical.void", voidCell); - deprecateItem("pattern.fluid", ItemAndBlockHolder.PATTERN); - deprecateWireless("terminal.fluid.wireless", ItemAndBlockHolder.WIRELESS_FLUID_TERM); - - /* Storage casings */ - deprecateItem("storage.casing", 0, AEApi.instance().definitions().materials().emptyAdvancedStorageCell()); - deprecateItem("storage.casing", 1, ItemAndBlockHolder.CELL_HOUSING, 2); - - /* Storage components (1k component, etc.) */ - deprecateItem("storage.component", 0, AEApi.instance().definitions().materials().cell256kPart()); - deprecateItem("storage.component", 1, AEApi.instance().definitions().materials().cell1024kPart()); - deprecateItem("storage.component", 2, AEApi.instance().definitions().materials().cell4096kPart()); - deprecateItem("storage.component", 3, AEApi.instance().definitions().materials().cell16384kPart()); - deprecateItem("storage.component", 4, ItemAndBlockHolder.CELL_PART, 0); - deprecateItem("storage.component", 5, ItemAndBlockHolder.CELL_PART, 1); - deprecateItem("storage.component", 6, ItemAndBlockHolder.CELL_PART, 2); - deprecateItem("storage.component", 7, ItemAndBlockHolder.CELL_PART, 3); - deprecateItem("storage.component", 8, ItemAndBlockHolder.CELL_PART, 4); - deprecateItem("storage.component", 9, ItemAndBlockHolder.CELL_PART, 5); - deprecateItem("storage.component", 10, ItemAndBlockHolder.CELL_PART, 6); - deprecateWireless("terminal.universal.wireless", ItemAndBlockHolder.WIRELESS_ULTRA_TERM); - - } - - /** - * Deprecate OC upgrades. Wrapper so we don't need a hard dependency - */ - @Optional.Method(modid = "OpenComputers") - static void deprecateOC() { - ItemInfo info = Items.get("me_upgrade1"); - if (info != null) { - // Note EC tier 1, 2, 3 corresponds to the correct meta equivalent in OC, so we can be lazy - deprecateItem("oc.upgrade", 0, info.item(), 0); - deprecateItem("oc.upgrade", 1, info.item(), 1); - deprecateItem("oc.upgrade", 2, info.item(), 2); - } else { - System.out.println("OpenComputers detected, but could not replace items: me_upgrade1"); - } - } - - /** - * Register proxy part items. - */ - static void proxyPartItems() { - deprecateItemPart(0, ItemAndBlockHolder.FLUID_EXPORT_BUS, ProxyFluidBusIO::new); - deprecateItemPart(1, ItemAndBlockHolder.FLUID_IMPORT_BUS, ProxyFluidBusIO::new); - deprecateItemPart(2, ItemAndBlockHolder.FLUID_STORAGE_BUS, ProxyFluidStorage::new); - deprecateItemPart(3, ItemAndBlockHolder.FLUID_TERM, ProxyPart::new); - deprecateItemPart(4, ItemAndBlockHolder.FLUID_LEVEL_EMITTER, ProxyLevelEmitter::new); - deprecateItemPart(9, ItemAndBlockHolder.FLUID_INTERFACE, ProxyFluidInterface::new); - deprecateItemPart(10, ItemAndBlockHolder.FLUID_STORAGE_MONITOR, ProxyStorageMonitor::new); - deprecateItemPart(11, ItemAndBlockHolder.FLUID_CONVERSION_MONITOR, ProxyStorageMonitor::new); - deprecateItemPart(12, AEApi.instance().definitions().parts().exportBus(), ProxyOreDictExportBus::new); - } - - private static ProxyItem getOrBuildItem(String srcName) { - final String fullName = "extracells:" + srcName; - ProxyItem proxy = (ProxyItem) registry.get(fullName); - if (proxy == null) { - proxy = new ProxyItem(srcName); - registry.put(fullName, proxy); - proxy.register(); - } - return proxy; - } - - private static ProxyFluidStorageCell getOrBuildFluidStorage(String srcName) { - final String fullName = "extracells:" + srcName; - ProxyFluidStorageCell proxy = (ProxyFluidStorageCell) registry.get(fullName); - if (proxy == null) { - proxy = new ProxyFluidStorageCell(srcName); - registry.put(fullName, proxy); - proxy.register(); - } - return proxy; - } - - private static ProxyItemStorageCell getOrBuildItemStorage() { - final String fullName = "extracells:storage.physical"; - ProxyItemStorageCell proxy = (ProxyItemStorageCell) registry.get(fullName); - if (proxy == null) { - proxy = new ProxyItemStorageCell("storage.physical"); - registry.put(fullName, proxy); - proxy.register(); - } - return proxy; - } - - private static ProxyExtremeStorageCell getOrBuildItemStorage(String srcName) { - final String fullName = "extracells:" + srcName; - ProxyExtremeStorageCell proxy = (ProxyExtremeStorageCell) registry.get(fullName); - if (proxy == null) { - proxy = new ProxyExtremeStorageCell(srcName); - registry.put(fullName, proxy); - proxy.register(); - } - return proxy; - } - - /** - * Deprecate a simple item. - * - * @param srcName name of the to-be-replaced item without the mod id prefix - * @param srcMeta meta of the to-be-replaced item - * @param replacement item that will replace src - * @param targetMeta meta of the item that will replace src - */ - private static void deprecateItem(String srcName, int srcMeta, Item replacement, int targetMeta) { - getOrBuildItem(srcName).addMetaReplacement(srcMeta, replacement, targetMeta); - } - - private static void deprecateItem(String srcName, Item replacement) { - deprecateItem(srcName, 0, replacement, 0); - } - - private static void deprecateItem(String srcName, int srcMeta, IItemDefinition replacement) { - if (replacement.isEnabled()) { - deprecateItem( - srcName, - srcMeta, - replacement.maybeItem().get(), - replacement.maybeStack(1).get().getItemDamage()); - } - } - - private static void deprecateWireless(String srcName, ItemBaseWirelessTerminal replacement) { - getOrBuildItem(srcName).addMetaReplacement(0, new ProxyItem.ProxyItemEntry(replacement, 0) { - - @Override - NBTTagCompound replaceNBT(NBTTagCompound compound) { - double power = compound.getDouble("power"); - compound.removeTag("power"); - compound.setDouble("internalCurrentPower", power); - String key = compound.getString("key"); - compound.removeTag("key"); - compound.setString("encryptionKey", key); - return compound; - } - }); - } - - private static void deprecateItemPart(int srcMeta, Item replacement, - Function partBuilder) { - final String fullName = "extracells:part.base"; - ProxyPartItem proxyItem = (ProxyPartItem) registry.get(fullName); - if (proxyItem == null) { - proxyItem = new ProxyPartItem("part.base"); - registry.put(fullName, proxyItem); - proxyItem.register(); - } - proxyItem.addItemPart(srcMeta, replacement, partBuilder); - } - - private static void deprecateItemPart(int srcMeta, IItemDefinition definition, - Function partBuilder) { - if (definition.isEnabled()) { - final String fullName = "extracells:part.base"; - ProxyPartItem proxyItem = (ProxyPartItem) registry.get(fullName); - if (proxyItem == null) { - proxyItem = new ProxyPartItem("part.base"); - registry.put(fullName, proxyItem); - proxyItem.register(); - } - proxyItem.addItemPart(srcMeta, definition, partBuilder); - } - } - - /** - * Deprecate a fluid storage item. Note that we can't access the properties directly, so we need to do this - */ - private static void deprecateFluidStorage(String srcName, int srcMeta, ItemMultiFluidStorageCell replacement, - long kilobytes, int bytesPerType, double idleDrain) { - ProxyFluidStorageCell proxyItem = getOrBuildFluidStorage(srcName); - ProxyItem.ProxyStorageEntry entry = new ProxyItem.ProxyStorageEntry( - replacement, - 0, - kilobytes, - bytesPerType, - idleDrain); - proxyItem.addMetaReplacement(srcMeta, entry); - } - - /** - * Deprecate a storage item. This goes through AEAPI, as AE2FC doesn't have any item cells. If the item is disabled - * in AEAPI, the replacement will not be registered! - */ - private static void deprecateItemStorage(int srcMeta, IItemDefinition replacement, long kilobytes, int bytesPerType, - double idleDrain) { - if (replacement.isEnabled()) { - ProxyItemStorageCell item = getOrBuildItemStorage(); - int meta = replacement.maybeStack(1).get().getItemDamage(); - ProxyItem.ProxyItemEntry storage = new ProxyItem.ProxyStorageEntry( - replacement.maybeItem().get(), - meta, - kilobytes, - bytesPerType, - idleDrain); - item.addMetaReplacement(srcMeta, storage); - } - } - - /** - * Deprecate a storage item. This goes through AEAPI, as AE2FC doesn't have any item cells. If the item is disabled - * in AEAPI, the replacement will not be registered! - */ - private static void deprecateItemStorage(int srcMeta, IItemDefinition replacement, long kilobytes, int bytesPerType, - double idleDrain, int types) { - if (replacement.isEnabled()) { - ProxyItemStorageCell item = getOrBuildItemStorage(); - ProxyItem.ProxyItemEntry storage = new ProxyItem.ProxyStorageEntry( - replacement.maybeItem().get(), - kilobytes, - bytesPerType, - idleDrain, - types); - item.addMetaReplacement(srcMeta, storage); - } - } - - private static void deprecateExtremeStorage(String srcName, int srcMeta, IItemDefinition replacement, long bytes, - int bytesPerType, double idleDrain) { - if (replacement.isEnabled()) { - ProxyExtremeStorageCell item = getOrBuildItemStorage(srcName); - int meta = replacement.maybeStack(1).get().getItemDamage(); - ProxyItem.ProxyItemEntry storage = new ProxyItem.ProxyStorageEntry( - replacement.maybeItem().get(), - meta, - bytes / 1024, - bytesPerType, - idleDrain); - item.addMetaReplacement(srcMeta, storage); - } - } -} diff --git a/src/main/java/com/glodblock/github/crossmod/extracells/ProxyItem.java b/src/main/java/com/glodblock/github/crossmod/extracells/ProxyItem.java deleted file mode 100644 index 167f1a43..00000000 --- a/src/main/java/com/glodblock/github/crossmod/extracells/ProxyItem.java +++ /dev/null @@ -1,156 +0,0 @@ -package com.glodblock.github.crossmod.extracells; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import net.minecraft.entity.Entity; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.EnumChatFormatting; -import net.minecraft.world.World; - -import com.glodblock.github.FluidCraft; -import com.glodblock.github.common.item.FCBaseItem; -import com.glodblock.github.util.ModAndClassUtil; - -import codechicken.nei.api.API; -import cpw.mods.fml.common.registry.GameRegistry; - -/** - * EC2ProxyItem - Item that "holds" the data of a missing item. - */ -public class ProxyItem extends FCBaseItem { - - protected final String name; - - /** - * Maps a metadata value to a replacement. - */ - protected final Map replacements; - - public ProxyItem(String ec2itemName) { - this.name = ec2itemName; - this.replacements = new HashMap<>(); - setUnlocalizedName("ec2placeholder." + name); - } - - @Override - public FCBaseItem register() { - GameRegistry.registerItem(this, "ec2placeholder." + name, FluidCraft.MODID); - if (!ModAndClassUtil.EC2) { - API.hideItem("ec2placeholder." + name); - } - - return this; - } - - protected void addMetaReplacement(int srcMeta, Item replacement, int targetMeta) { - this.replacements.put(srcMeta, new ProxyItemEntry(replacement, targetMeta)); - } - - protected void addMetaReplacement(int srcMeta, ProxyItemEntry replacement) { - this.replacements.put(srcMeta, replacement); - } - - @Override - public boolean getHasSubtypes() { - return true; - } - - @Override - public void addInformation(ItemStack stack, EntityPlayer player, List info, boolean p_77624_4_) { - int meta = stack.getItemDamage(); - ProxyItemEntry itemRepl = replacements.get(meta); - if (itemRepl != null) { - info.add(EnumChatFormatting.RED + "Extra Cells Placeholder for:"); - info.add(EnumChatFormatting.AQUA + itemRepl.replacement.getUnlocalizedName()); - info.add(EnumChatFormatting.GOLD + "Put in your inventory to get a replacement."); - info.add(EnumChatFormatting.GOLD + "It will disappear if no replacement was found."); - info.add(EnumChatFormatting.RED + "Report missing conversions on the GitHub."); - } - } - - @Override - public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int p_77663_4_, boolean p_77663_5_) { - if (!worldIn.isRemote && entityIn instanceof EntityPlayer player) { - for (int i = 0; i < player.inventory.getSizeInventory(); ++i) { - ItemStack s = player.inventory.getStackInSlot(i); - if (s == stack) { - int meta = stack.getItemDamage(); - ProxyItemEntry r = replacements.get(meta); - if (r == null) { - player.inventory.setInventorySlotContents(i, null); - } else { - ItemStack replaceStack = new ItemStack(r.replacement, stack.stackSize, r.replacementMeta); - if (stack.hasTagCompound()) { - replaceStack.setTagCompound(r.replaceNBT(stack.getTagCompound())); - } - player.inventory.setInventorySlotContents(i, replaceStack); - } - break; - } - } - } - } - - /** - * Base class for a mapping from source (Item, meta) -> replacement (Item, meta). Optionally, override the - * {@link ProxyItemEntry#replaceNBT(NBTTagCompound)} method for custom NBT migration. - */ - protected static class ProxyItemEntry { - - protected final Item replacement; - protected final int replacementMeta; - - /** - * Creates a Proxy Replacement. - * - * @param replacement Item that will replace the other. - * @param replacementMeta Metadata/damage value of the replacement - */ - protected ProxyItemEntry(Item replacement, int replacementMeta) { - this.replacement = replacement; - this.replacementMeta = replacementMeta; - } - - NBTTagCompound replaceNBT(NBTTagCompound compound) { - System.out.println(compound); - return compound; - } - } - - protected static class ProxyStorageEntry extends ProxyItemEntry { - - public final long maxBytes; - public final int bytesPerType; - public final double idleDrain; - public final int types; - - protected ProxyStorageEntry(Item replacement, int meta, long kilobytes, int bytesPerType, double idleDrain) { - super(replacement, meta); - this.maxBytes = kilobytes * 1024; - this.bytesPerType = bytesPerType; - this.idleDrain = idleDrain; - this.types = 63; - } - - protected ProxyStorageEntry(Item replacement, long kilobytes, int bytesPerType, double idleDrain, int types) { - super(replacement, 0); - this.maxBytes = kilobytes * 1024; - this.bytesPerType = bytesPerType; - this.idleDrain = idleDrain; - this.types = types; - } - - @Override - NBTTagCompound replaceNBT(NBTTagCompound compound) { - if (compound != null && compound.hasKey("ecc")) { - compound.removeTag("ecc"); - } - return compound; - } - } -} diff --git a/src/main/java/com/glodblock/github/crossmod/extracells/ProxyPart.java b/src/main/java/com/glodblock/github/crossmod/extracells/ProxyPart.java deleted file mode 100644 index 012a1f9e..00000000 --- a/src/main/java/com/glodblock/github/crossmod/extracells/ProxyPart.java +++ /dev/null @@ -1,235 +0,0 @@ -package com.glodblock.github.crossmod.extracells; - -import java.lang.ref.WeakReference; -import java.util.List; -import java.util.Random; - -import javax.annotation.Nonnull; - -import net.minecraft.client.renderer.RenderBlocks; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.IIcon; -import net.minecraft.util.Vec3; -import net.minecraft.world.World; -import net.minecraftforge.common.util.ForgeDirection; -import net.minecraftforge.fluids.Fluid; -import net.minecraftforge.fluids.FluidRegistry; -import net.minecraftforge.fluids.FluidStack; - -import appeng.api.networking.IGridNode; -import appeng.api.parts.BusSupport; -import appeng.api.parts.IPart; -import appeng.api.parts.IPartCollisionHelper; -import appeng.api.parts.IPartDeprecated; -import appeng.api.parts.IPartHost; -import appeng.api.parts.IPartRenderHelper; -import appeng.api.parts.PartItemStack; -import appeng.api.storage.data.IAEItemStack; -import appeng.util.item.AEItemStack; -import cpw.mods.fml.common.registry.GameRegistry; -import io.netty.buffer.ByteBuf; - -/** - * ProxyPart is expected to be immediately replaced with the replacement part on load. - */ -public class ProxyPart implements IPart, IPartDeprecated { - - /** - * Prevent memory leaks by having one of the instances be a weak ref. - */ - private final WeakReference item; - - /** - * Name for debug - */ - private final String name; - - public ProxyPart(ProxyPartItem item) { - this.item = new WeakReference<>(item); - this.name = item.name; - } - - @Override - public ItemStack getItemStack(PartItemStack type) { - return null; - } - - @Override - public void renderInventory(IPartRenderHelper rh, RenderBlocks renderer) {} - - @Override - public void renderStatic(int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer) {} - - @Override - public void renderDynamic(double x, double y, double z, IPartRenderHelper rh, RenderBlocks renderer) {} - - @Override - public IIcon getBreakingTexture() { - return null; - } - - @Override - public boolean requireDynamicRender() { - return false; - } - - @Override - public boolean isSolid() { - return false; - } - - @Override - public boolean canConnectRedstone() { - return false; - } - - @Override - public void writeToNBT(NBTTagCompound data) {} - - @Override - public void readFromNBT(NBTTagCompound data) {} - - @Override - public int getLightLevel() { - return 0; - } - - @Override - public boolean isLadder(EntityLivingBase entity) { - return false; - } - - @Override - public void onNeighborChanged() {} - - @Override - public int isProvidingStrongPower() { - return 0; - } - - @Override - public int isProvidingWeakPower() { - return 0; - } - - @Override - public void writeToStream(ByteBuf data) {} - - @Override - public boolean readFromStream(ByteBuf data) { - return false; - } - - @Override - public IGridNode getGridNode() { - return null; - } - - @Override - public void onEntityCollision(Entity entity) {} - - @Override - public void removeFromWorld() {} - - @Override - public void addToWorld() {} - - @Override - public IGridNode getExternalFacingNode() { - return null; - } - - @Override - public void setPartHostInfo(ForgeDirection side, IPartHost host, TileEntity tile) {} - - @Override - public boolean onActivate(EntityPlayer player, Vec3 pos) { - return false; - } - - @Override - public boolean onShiftActivate(EntityPlayer player, Vec3 pos) { - return false; - } - - @Override - public void getDrops(List drops, boolean wrenched) {} - - @Override - public int cableConnectionRenderTo() { - return 0; - } - - @Override - public void randomDisplayTick(World world, int x, int y, int z, Random r) { - - } - - @Override - public void onPlacement(EntityPlayer player, ItemStack held, ForgeDirection side) {} - - @Override - public boolean canBePlacedOn(BusSupport what) { - return false; - } - - @Override - public void getBoxes(IPartCollisionHelper boxes) {} - - @Override - public NBTTagCompound transformPart(NBTTagCompound def) { - int meta = def.getShort("Damage"); - if (item.get() == null) { - throw new NullPointerException("Umm, this wasn't supposed to happen. The ref item " + name + " was GC'd."); - } - ProxyItem.ProxyItemEntry r = item.get().replacements.get(meta); - def.setInteger("id", Item.getIdFromItem(r.replacement)); - def.setShort("Damage", (short) r.replacementMeta); - return def; - } - - @Nonnull - @Override - public NBTTagCompound transformNBT(NBTTagCompound extra) { - return extra; - } - - /** - * Creates a new fluid display NBT tag from the fluid name - */ - public static NBTTagCompound createFluidDisplayTag(String fluidName) { - NBTTagCompound fluidDisplay = new NBTTagCompound(); - Fluid fluid = FluidRegistry.getFluid(fluidName); - if (fluid != null) { - ItemStack fluidPacket = new ItemStack(GameRegistry.findItem("ae2fc", "fluid_packet"), 1, 0); - NBTTagCompound fluidPacketTag = new NBTTagCompound(); - // FluidStack - FluidStack fluidStack = new FluidStack(fluid, 1000); - NBTTagCompound fluidStackNbt = new NBTTagCompound(); - fluidStack.writeToNBT(fluidStackNbt); - fluidPacketTag.setTag("FluidStack", fluidStackNbt); - // FluidPacket - fluidPacketTag.setBoolean("DisplayOnly", true); - fluidPacket.setTagCompound(fluidPacketTag); - // Final Item - IAEItemStack aeStack = AEItemStack.create(fluidPacket); - aeStack.writeToNBT(fluidDisplay); - } - return fluidDisplay; - } - - public static NBTTagCompound createFluidNBT(String fluidName, long amount) { - NBTTagCompound fluid = new NBTTagCompound(); - fluid.setString("FluidName", fluidName); - fluid.setBoolean("Craft", false); - fluid.setLong("Req", 0); - fluid.setLong("Cnt", amount); - return fluid; - } -} diff --git a/src/main/java/com/glodblock/github/crossmod/extracells/ProxyPartItem.java b/src/main/java/com/glodblock/github/crossmod/extracells/ProxyPartItem.java deleted file mode 100644 index aa19a5cd..00000000 --- a/src/main/java/com/glodblock/github/crossmod/extracells/ProxyPartItem.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.glodblock.github.crossmod.extracells; - -import java.util.function.Function; - -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; - -import org.jetbrains.annotations.Nullable; - -import appeng.api.definitions.IItemDefinition; -import appeng.api.parts.IPart; -import appeng.api.parts.IPartItem; - -public class ProxyPartItem extends ProxyItem implements IPartItem { - - /** - * Creates a ProxyPartItem associated with the ProxyPart instance. This instance is reused on each call to - * {@link #createPartFromItemStack(ItemStack)}. - * - * @param ec2itemName extra cells internal name - */ - public ProxyPartItem(String ec2itemName) { - super(ec2itemName); - } - - protected void addItemPart(int srcMeta, Item replacement, Function part) { - this.replacements.put(srcMeta, new PartReplacement(replacement, part)); - } - - protected void addItemPart(int srcMeta, IItemDefinition replacement, Function part) { - ItemStack stack = replacement.maybeStack(1).get(); - this.replacements.put(srcMeta, new PartReplacement(stack.getItem(), stack.getItemDamage(), part)); - } - - @Nullable - @Override - public IPart createPartFromItemStack(ItemStack is) { - final int meta = is.getItemDamage(); - if (this.replacements.get(meta) instanceof PartReplacement part) { - return part.proxyPart.apply(this); - } - return null; - } -} - -/** - * Item replacement entry for ItemParts. All targets replace into 0. - */ -class PartReplacement extends ProxyItem.ProxyItemEntry { - - Function proxyPart; - - PartReplacement(Item replacement, Function proxyPart) { - this(replacement, 0, proxyPart); - } - - PartReplacement(Item replacement, int meta, Function proxyPart) { - super(replacement, meta); - this.proxyPart = proxyPart; - } -} diff --git a/src/main/java/com/glodblock/github/crossmod/extracells/parts/ProxyFluidBusIO.java b/src/main/java/com/glodblock/github/crossmod/extracells/parts/ProxyFluidBusIO.java deleted file mode 100644 index 3d04e7c9..00000000 --- a/src/main/java/com/glodblock/github/crossmod/extracells/parts/ProxyFluidBusIO.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.glodblock.github.crossmod.extracells.parts; - -import static net.minecraftforge.common.util.Constants.NBT.TAG_COMPOUND; - -import javax.annotation.Nonnull; - -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; - -import com.glodblock.github.crossmod.extracells.ProxyPart; -import com.glodblock.github.crossmod.extracells.ProxyPartItem; - -import appeng.api.config.RedstoneMode; - -public class ProxyFluidBusIO extends ProxyPart { - - /** - * Map for converting slots from bus EC2 -> AE2FC - */ - private static int[] FILTER_MAP = null; - - public static void init() { - FILTER_MAP = new int[] { 5, 3, 6, 1, 0, 2, 7, 4, 8 }; - } - - public ProxyFluidBusIO(ProxyPartItem partItem) { - super(partItem); - } - - @Nonnull - @Override - public NBTTagCompound transformNBT(NBTTagCompound extra) { - // Transform NBT in place - // Fluid Filter - NBTTagCompound fluidFilterNew = new NBTTagCompound(); - for (int slot = 0; slot < 9; ++slot) { - String oldFilterName = "FilterFluid#" + slot; - fluidFilterNew - .setTag("#" + FILTER_MAP[slot], ProxyPart.createFluidDisplayTag(extra.getString(oldFilterName))); - extra.removeTag(oldFilterName); - } - extra.setTag("config", fluidFilterNew); - // Upgrades - NBTTagList upgrades = extra.getTagList("upgradeInventory", TAG_COMPOUND); - NBTTagCompound upgradesNew = new NBTTagCompound(); - for (int i = 0; i < 4; ++i) { - NBTTagCompound upgrade = upgrades.getCompoundTagAt(i); - upgrade.removeTag("Slot"); - upgradesNew.setTag("#" + i, upgrade); - } - extra.removeTag("upgradeInventory"); - extra.setTag("upgrades", upgradesNew); - // Redstone mode - RedstoneMode redstoneMode = RedstoneMode.values()[extra.getInteger("redstoneMode")]; - switch (redstoneMode) { - case LOW_SIGNAL -> extra.setString("REDSTONE_CONTROLLED", "LOW_SIGNAL"); - case HIGH_SIGNAL -> extra.setString("REDSTONE_CONTROLLED", "HIGH_SIGNAL"); - case SIGNAL_PULSE -> extra.setString("REDSTONE_CONTROLLED", "SIGNAL_PULSE"); - default -> extra.setString("REDSTONE_CONTROLLED", "IGNORE"); - } - extra.removeTag("redstoneMode"); - // Part data - extra.setTag("part", extra.getCompoundTag("node").getCompoundTag("node0")); - extra.removeTag("node"); - // Extra tags - extra.setString("CRAFT_ONLY", "NO"); - extra.setString("FUZZY_MODE", "IGNORE_ALL"); - extra.setString("SCHEDULING_MODE", "DEFAULT"); - return extra; - } -} diff --git a/src/main/java/com/glodblock/github/crossmod/extracells/parts/ProxyFluidInterface.java b/src/main/java/com/glodblock/github/crossmod/extracells/parts/ProxyFluidInterface.java deleted file mode 100644 index 1e7cd55f..00000000 --- a/src/main/java/com/glodblock/github/crossmod/extracells/parts/ProxyFluidInterface.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.glodblock.github.crossmod.extracells.parts; - -import javax.annotation.Nonnull; - -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraftforge.common.util.Constants; - -import com.glodblock.github.crossmod.extracells.ProxyPart; -import com.glodblock.github.crossmod.extracells.ProxyPartItem; - -public class ProxyFluidInterface extends ProxyPart { - - public ProxyFluidInterface(ProxyPartItem item) { - super(item); - } - - @Nonnull - @Override - public NBTTagCompound transformNBT(NBTTagCompound extra) { - // Internal fluids - ConfigInv and FluidInv - NBTTagCompound tank = extra.getCompoundTag("tank"); - NBTTagCompound configTank = new NBTTagCompound(); - configTank.setTag("#0", ProxyPart.createFluidDisplayTag(tank.getString("FluidName"))); - extra.setTag("ConfigInv", configTank); - NBTTagCompound fluidTank = new NBTTagCompound(); - NBTTagCompound fluid = ProxyPart.createFluidNBT(tank.getString("FluidName"), tank.getLong("Amount")); - fluidTank.setTag("#0", fluid); - extra.setTag("FluidInv", fluidTank); - extra.removeTag("tank"); - // Patterns - NBTTagList patterns = extra.getCompoundTag("inventory").getTagList("Inventory", Constants.NBT.TAG_COMPOUND); - NBTTagCompound newPatterns = new NBTTagCompound(); - for (int i = 0; i < patterns.tagCount(); ++i) { - NBTTagCompound p = patterns.getCompoundTagAt(i); - p.removeTag("Slot"); - newPatterns.setTag("#" + i, p); - } - extra.removeTag("inventory"); - extra.setTag("patterns", newPatterns); - // Part - extra.setTag("part", extra.getCompoundTag("node").getCompoundTag("node0")); - extra.removeTag("node"); - return extra; - } - -} diff --git a/src/main/java/com/glodblock/github/crossmod/extracells/parts/ProxyFluidStorage.java b/src/main/java/com/glodblock/github/crossmod/extracells/parts/ProxyFluidStorage.java deleted file mode 100644 index 7ca5381e..00000000 --- a/src/main/java/com/glodblock/github/crossmod/extracells/parts/ProxyFluidStorage.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.glodblock.github.crossmod.extracells.parts; - -import static net.minecraftforge.common.util.Constants.NBT.TAG_COMPOUND; - -import javax.annotation.Nonnull; - -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; - -import com.glodblock.github.crossmod.extracells.ProxyPart; -import com.glodblock.github.crossmod.extracells.ProxyPartItem; - -public class ProxyFluidStorage extends ProxyPart { - - private static int[] FILTER_MAP = null; - - protected static void init() { - // spotless:off - FILTER_MAP = new int[] { - 0, 9, 18, 27, 36, 45, - 1, 10, 19, 28, 37, 46, - 2, 11, 20, 29, 38, 47, - 3, 12, 21, 30, 39, 48, - 4, 13, 22, 31, 40, 49, - 5, 14, 23, 32, 41, 50, - 6, 15, 24, 33, 42, 51, - 7, 16, 25, 34, 43, 52, - 8, 17, 26, 35, 44, 53 }; - //spotless:on - } - - public ProxyFluidStorage(ProxyPartItem item) { - super(item); - } - - @Nonnull - @Override - public NBTTagCompound transformNBT(NBTTagCompound extra) { - // Transform in place, less messy IMO - // Fluid filter slots - NBTTagCompound fluidFilterNew = new NBTTagCompound(); - for (int slot = 0; slot < 54; ++slot) { - String oldFilterName = "FilterFluid#" + slot; - fluidFilterNew - .setTag("#" + FILTER_MAP[slot], ProxyPart.createFluidDisplayTag(extra.getString(oldFilterName))); - extra.removeTag(oldFilterName); - } - extra.setTag("config", fluidFilterNew); - - // Part data - extra.setTag("part", extra.getCompoundTag("node").getCompoundTag("node0")); - extra.removeTag("node"); - - // Access - extra.setString("ACCESS", extra.getString("access")); - extra.removeTag("access"); - - // Upgrades - NBTTagList upgrades = extra.getTagList("upgradeInventory", TAG_COMPOUND); - NBTTagCompound upgradeNew = new NBTTagCompound(); - upgradeNew.setTag("#0", upgrades.getCompoundTagAt(0)); - upgradeNew.setTag("#1", new NBTTagCompound()); - upgradeNew.setTag("#2", new NBTTagCompound()); - upgradeNew.setTag("#3", new NBTTagCompound()); - upgradeNew.setTag("#4", new NBTTagCompound()); - extra.setTag("upgrades", upgradeNew); - extra.removeTag("upgradeInventory"); - return extra; - } -} diff --git a/src/main/java/com/glodblock/github/crossmod/extracells/parts/ProxyLevelEmitter.java b/src/main/java/com/glodblock/github/crossmod/extracells/parts/ProxyLevelEmitter.java deleted file mode 100644 index a140cd57..00000000 --- a/src/main/java/com/glodblock/github/crossmod/extracells/parts/ProxyLevelEmitter.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.glodblock.github.crossmod.extracells.parts; - -import javax.annotation.Nonnull; - -import net.minecraft.nbt.NBTTagCompound; - -import com.glodblock.github.crossmod.extracells.ProxyPart; -import com.glodblock.github.crossmod.extracells.ProxyPartItem; - -import appeng.api.config.RedstoneMode; - -public class ProxyLevelEmitter extends ProxyPart { - - public ProxyLevelEmitter(ProxyPartItem item) { - super(item); - } - - @Nonnull - @Override - public NBTTagCompound transformNBT(NBTTagCompound extra) { - // Fluid - NBTTagCompound fluidSlots = new NBTTagCompound(); - fluidSlots.setTag("#0", ProxyPart.createFluidDisplayTag(extra.getString("fluid"))); - extra.setTag("config", fluidSlots); - extra.removeTag("fluid"); - // Redstone - RedstoneMode redstoneMode = RedstoneMode.values()[extra.getInteger("mode")]; - if (redstoneMode == RedstoneMode.LOW_SIGNAL) { - extra.setString("REDSTONE_EMITTER", "LOW_SIGNAL"); - } else { - extra.setString("REDSTONE_EMITTER", "HIGH_SIGNAL"); - } - extra.removeTag("mode"); - // Level - long wanted = extra.getLong("wantedAmount"); - extra.setLong("reportingValue", wanted); - extra.setLong("lastReportingValue", wanted); - extra.removeTag("wantedAmount"); - // Part - extra.setTag("part", extra.getCompoundTag("node").getCompoundTag("node0")); - extra.removeTag("node"); - return extra; - } -} diff --git a/src/main/java/com/glodblock/github/crossmod/extracells/parts/ProxyOreDictExportBus.java b/src/main/java/com/glodblock/github/crossmod/extracells/parts/ProxyOreDictExportBus.java deleted file mode 100644 index 0997eb36..00000000 --- a/src/main/java/com/glodblock/github/crossmod/extracells/parts/ProxyOreDictExportBus.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.glodblock.github.crossmod.extracells.parts; - -import javax.annotation.Nonnull; - -import net.minecraft.nbt.NBTTagCompound; - -import com.glodblock.github.crossmod.extracells.ProxyPart; -import com.glodblock.github.crossmod.extracells.ProxyPartItem; - -import appeng.api.AEApi; - -public class ProxyOreDictExportBus extends ProxyPart { - - public ProxyOreDictExportBus(ProxyPartItem item) { - super(item); - } - - @Nonnull - @Override - public NBTTagCompound transformNBT(NBTTagCompound extra) { - // TODO: Node tag... should use OOP here. - extra.setTag("part", extra.getCompoundTag("node").getCompoundTag("node0")); - extra.removeTag("node"); - // Ore dict card - NBTTagCompound upgrades = new NBTTagCompound(); - NBTTagCompound oreDictCard = new NBTTagCompound(); - AEApi.instance().definitions().materials().cardOreFilter().maybeStack(1).get().writeToNBT(oreDictCard); - upgrades.setTag("#0", oreDictCard); - extra.setTag("upgrades", upgrades); - return super.transformNBT(extra); - } -} diff --git a/src/main/java/com/glodblock/github/crossmod/extracells/parts/ProxyStorageMonitor.java b/src/main/java/com/glodblock/github/crossmod/extracells/parts/ProxyStorageMonitor.java deleted file mode 100644 index b4d8c5e2..00000000 --- a/src/main/java/com/glodblock/github/crossmod/extracells/parts/ProxyStorageMonitor.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.glodblock.github.crossmod.extracells.parts; - -import javax.annotation.Nonnull; - -import net.minecraft.nbt.NBTTagCompound; -import net.minecraftforge.fluids.Fluid; -import net.minecraftforge.fluids.FluidRegistry; - -import com.glodblock.github.crossmod.extracells.ProxyPart; -import com.glodblock.github.crossmod.extracells.ProxyPartItem; - -public class ProxyStorageMonitor extends ProxyPart { - - public ProxyStorageMonitor(ProxyPartItem item) { - super(item); - } - - @Nonnull - @Override - public NBTTagCompound transformNBT(NBTTagCompound extra) { - // Fluid - int fluid = extra.getInteger("fluid"); - Fluid f = FluidRegistry.getFluid(fluid); - NBTTagCompound itemDisplay = ProxyPart.createFluidNBT(f.getName(), 0L); - extra.setTag("configuredItem", itemDisplay); - extra.removeTag("amount"); - extra.removeTag("fluid"); - // Locked and other props - extra.setBoolean("isLocked", extra.getBoolean("locked")); - extra.removeTag("locked"); - extra.setByte("spin", (byte) 0); - extra.setFloat("opacity", 255.0f); - // Part - extra.setTag("part", extra.getCompoundTag("node").getCompoundTag("node0")); - extra.removeTag("node"); - return extra; - } - -} diff --git a/src/main/java/com/glodblock/github/crossmod/extracells/storage/ProxyExtremeStorageCell.java b/src/main/java/com/glodblock/github/crossmod/extracells/storage/ProxyExtremeStorageCell.java deleted file mode 100644 index c6e05083..00000000 --- a/src/main/java/com/glodblock/github/crossmod/extracells/storage/ProxyExtremeStorageCell.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.glodblock.github.crossmod.extracells.storage; - -import net.minecraft.item.ItemStack; - -public class ProxyExtremeStorageCell extends ProxyItemStorageCell { - - public ProxyExtremeStorageCell(String ec2itemName) { - super(ec2itemName); - } - - @Override - public int getTotalTypes(ItemStack cellItem) { - return 1; - } -} diff --git a/src/main/java/com/glodblock/github/crossmod/extracells/storage/ProxyFluidCellInventory.java b/src/main/java/com/glodblock/github/crossmod/extracells/storage/ProxyFluidCellInventory.java deleted file mode 100644 index f0d0a27a..00000000 --- a/src/main/java/com/glodblock/github/crossmod/extracells/storage/ProxyFluidCellInventory.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.glodblock.github.crossmod.extracells.storage; - -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTBase; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraftforge.fluids.FluidStack; - -import com.glodblock.github.common.storage.FluidCellInventory; - -import appeng.api.AEApi; -import appeng.api.exceptions.AppEngException; -import appeng.api.storage.ISaveProvider; -import appeng.api.storage.data.IAEFluidStack; -import appeng.util.item.AEFluidStack; - -public class ProxyFluidCellInventory extends FluidCellInventory { - - private static final String EC_CONVERTED = "ecc"; - - public ProxyFluidCellInventory(ItemStack o, ISaveProvider container) throws AppEngException { - super(o, container); - } - - @Override - protected void loadCellFluids() { - // If we've already converted the tag to AE2FC, just go to super. - // Else, proceed with conversion - if (!this.tagCompound.hasKey(EC_CONVERTED)) { - if (this.cellFluids == null) { - this.cellFluids = AEApi.instance().storage().createFluidList(); - } - this.cellFluids.resetStatus(); // clears totals and stuff. - // Load using Extra Cell's NBT format - for (int i = 0; i < this.cellType.getTotalTypes(this.cellItem); i++) { - FluidStack fs = FluidStack.loadFluidStackFromNBT(tagCompound.getCompoundTag("Fluid#" + i)); - tagCompound.removeTag("Fluid#" + i); - final AEFluidStack aet = AEFluidStack.create(fs); - if (aet != null) { - if (aet.getStackSize() > 0) { - this.cellFluids.add(aet); - } - } - } - this.tagCompound.setBoolean(EC_CONVERTED, true); - // Convert to the new format - long fluidCount = 0; - int x = 0; - - for (final IAEFluidStack v : this.cellFluids) { - fluidCount += v.getStackSize(); - final NBTBase c = this.tagCompound.getTag(fluidSlots[x]); - if (c instanceof NBTTagCompound) { - v.writeToNBT((NBTTagCompound) c); - } else { - final NBTTagCompound g = new NBTTagCompound(); - v.writeToNBT(g); - this.tagCompound.setTag(fluidSlots[x], g); - } - this.tagCompound.setLong(fluidSlotCount[x], v.getStackSize()); - x++; - } - this.storedFluids = (short) this.cellFluids.size(); - - if (!this.cellFluids.isEmpty()) { - this.tagCompound.setShort(FLUID_TYPE_TAG, this.storedFluids); - } - - this.storedFluidCount = fluidCount; - if (fluidCount > 0) { - this.tagCompound.setLong(FLUID_COUNT_TAG, fluidCount); - } - } else { - super.loadCellFluids(); - } - - } -} diff --git a/src/main/java/com/glodblock/github/crossmod/extracells/storage/ProxyFluidStorageCell.java b/src/main/java/com/glodblock/github/crossmod/extracells/storage/ProxyFluidStorageCell.java deleted file mode 100644 index 3ae624c9..00000000 --- a/src/main/java/com/glodblock/github/crossmod/extracells/storage/ProxyFluidStorageCell.java +++ /dev/null @@ -1,108 +0,0 @@ -package com.glodblock.github.crossmod.extracells.storage; - -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; - -import com.glodblock.github.api.FluidCraftAPI; -import com.glodblock.github.common.storage.IStorageFluidCell; -import com.glodblock.github.crossmod.extracells.ProxyItem; -import com.glodblock.github.inventory.FluidCellConfig; - -import appeng.api.config.FuzzyMode; -import appeng.api.storage.data.IAEFluidStack; -import appeng.items.contents.CellUpgrades; -import appeng.util.Platform; - -public class ProxyFluidStorageCell extends ProxyItem implements IStorageFluidCell { - - public ProxyFluidStorageCell(String ec2itemName) { - super(ec2itemName); - } - - @Override - public long getBytes(ItemStack cellItem) { - int meta = cellItem.getItemDamage(); - if (replacements.containsKey(meta)) { - ProxyItemEntry entry = replacements.get(meta); - if (entry instanceof ProxyStorageEntry) { - return ((ProxyStorageEntry) entry).maxBytes; - } - } - return 0; - } - - @Override - public int getBytesPerType(ItemStack cellItem) { - int meta = cellItem.getItemDamage(); - if (replacements.containsKey(meta)) { - ProxyItemEntry entry = replacements.get(meta); - if (entry instanceof ProxyStorageEntry) { - return ((ProxyStorageEntry) entry).bytesPerType; - } - } - return 0; - } - - @Override - public boolean isBlackListed(ItemStack cellItem, IAEFluidStack requestedAddition) { - return requestedAddition == null || requestedAddition.getFluid() == null - || FluidCraftAPI.instance().isBlacklistedInStorage(requestedAddition.getFluid().getClass()); - } - - @Override - public boolean storableInStorageCell() { - return false; - } - - @Override - public boolean isStorageCell(ItemStack i) { - return true; - } - - @Override - public double getIdleDrain(ItemStack is) { - int meta = is.getItemDamage(); - if (replacements.containsKey(meta)) { - ProxyItemEntry entry = replacements.get(meta); - if (entry instanceof ProxyStorageEntry) { - return ((ProxyStorageEntry) entry).idleDrain; - } - } - return 0; - } - - @Override - public int getTotalTypes(ItemStack cellItem) { - return 5; - } - - @Override - public boolean isEditable(ItemStack is) { - return true; - } - - @Override - public IInventory getUpgradesInventory(ItemStack is) { - return new CellUpgrades(is, 0); - } - - @Override - public IInventory getConfigInventory(ItemStack is) { - return new FluidCellConfig(is); - } - - @Override - public FuzzyMode getFuzzyMode(ItemStack is) { - final String fz = Platform.openNbtData(is).getString("FuzzyMode"); - try { - return FuzzyMode.valueOf(fz); - } catch (final Throwable t) { - return FuzzyMode.IGNORE_ALL; - } - } - - @Override - public void setFuzzyMode(ItemStack is, FuzzyMode fzMode) { - - } -} diff --git a/src/main/java/com/glodblock/github/crossmod/extracells/storage/ProxyItemCellHandler.java b/src/main/java/com/glodblock/github/crossmod/extracells/storage/ProxyItemCellHandler.java deleted file mode 100644 index 2b2c6dcc..00000000 --- a/src/main/java/com/glodblock/github/crossmod/extracells/storage/ProxyItemCellHandler.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.glodblock.github.crossmod.extracells.storage; - -import net.minecraft.item.ItemStack; - -import appeng.core.features.registries.entries.BasicCellHandler; - -public class ProxyItemCellHandler extends BasicCellHandler { - - @Override - public boolean isCell(ItemStack is) { - return is != null && is.getItem() != null && is.getItem() instanceof ProxyItemStorageCell; - } -} diff --git a/src/main/java/com/glodblock/github/crossmod/extracells/storage/ProxyItemStorageCell.java b/src/main/java/com/glodblock/github/crossmod/extracells/storage/ProxyItemStorageCell.java deleted file mode 100644 index 42a96f36..00000000 --- a/src/main/java/com/glodblock/github/crossmod/extracells/storage/ProxyItemStorageCell.java +++ /dev/null @@ -1,161 +0,0 @@ -package com.glodblock.github.crossmod.extracells.storage; - -import javax.annotation.Nullable; - -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; - -import com.glodblock.github.crossmod.extracells.ProxyItem; - -import appeng.api.config.FuzzyMode; -import appeng.api.implementations.items.IStorageCell; -import appeng.api.storage.data.IAEItemStack; -import appeng.items.contents.CellConfig; -import appeng.items.contents.CellUpgrades; -import appeng.util.Platform; - -/** - * Proxy Item Storage. 256K, 1024K, etc. -> AE2's version. For now its just mirroring AE2's version, will need to - * transition to something better. - */ -public class ProxyItemStorageCell extends ProxyItem implements IStorageCell { - - public ProxyItemStorageCell(String ec2itemName) { - super(ec2itemName); - } - - @Override - public int getBytes(ItemStack cellItem) { - if (cellItem == null) { - return 0; - } - int meta = cellItem.getItemDamage(); - if (replacements.containsKey(meta)) { - ProxyItemEntry entry = replacements.get(meta); - if (entry instanceof ProxyStorageEntry) { - return (int) ((ProxyStorageEntry) entry).maxBytes; - } - } - return 0; - } - - @Override - public int BytePerType(ItemStack cellItem) { - if (cellItem == null) { - return 0; - } - int meta = cellItem.getItemDamage(); - if (replacements.containsKey(meta)) { - ProxyItemEntry entry = replacements.get(meta); - if (entry instanceof ProxyStorageEntry) { - return ((ProxyStorageEntry) entry).bytesPerType; - } - } - return 0; - } - - @Override - public int getBytesPerType(ItemStack cellItem) { - if (cellItem == null) { - return 0; - } - int meta = cellItem.getItemDamage(); - if (replacements.containsKey(meta)) { - ProxyItemEntry entry = replacements.get(meta); - if (entry instanceof ProxyStorageEntry) { - return ((ProxyStorageEntry) entry).bytesPerType; - } - } - return 0; - } - - @Override - public long getBytesLong(ItemStack cellItem) { - if (cellItem == null) { - return 0; - } - int meta = cellItem.getItemDamage(); - if (replacements.containsKey(meta)) { - ProxyItemEntry entry = replacements.get(meta); - if (entry instanceof ProxyStorageEntry) { - return ((ProxyStorageEntry) entry).maxBytes; - } - } - return 0; - } - - @Override - public int getTotalTypes(ItemStack cellItem) { - return 63; - } - - @Override - public boolean isBlackListed(ItemStack cellItem, IAEItemStack requestedAddition) { - return false; - } - - @Override - public boolean storableInStorageCell() { - return false; - } - - @Override - public boolean isStorageCell(ItemStack i) { - return true; - } - - @Override - public double getIdleDrain(@Nullable ItemStack cellItem) { - if (cellItem == null) { - return 0.0; - } - int meta = cellItem.getItemDamage(); - if (replacements.containsKey(meta)) { - ProxyItemEntry entry = replacements.get(meta); - if (entry instanceof ProxyStorageEntry) { - return ((ProxyStorageEntry) entry).bytesPerType; - } - } - return 0; - } - - @Override - public double getIdleDrain() { - return 0; - } - - @Override - public boolean isEditable(ItemStack is) { - return true; - } - - @Override - public IInventory getUpgradesInventory(ItemStack is) { - return new CellUpgrades(is, 2); - } - - @Override - public IInventory getConfigInventory(ItemStack is) { - return new CellConfig(is); - } - - @Override - public FuzzyMode getFuzzyMode(ItemStack is) { - final String fz = Platform.openNbtData(is).getString("FuzzyMode"); - try { - return FuzzyMode.valueOf(fz); - } catch (final Throwable t) { - return FuzzyMode.IGNORE_ALL; - } - } - - @Override - public void setFuzzyMode(ItemStack is, FuzzyMode fzMode) { - Platform.openNbtData(is).setString("FuzzyMode", fzMode.name()); - } - - @Override - public String getOreFilter(ItemStack is) { - return Platform.openNbtData(is).getString("OreFilter"); - } -} diff --git a/src/main/java/com/glodblock/github/crossmod/extracells/storage/ProxyVoidCellHandler.java b/src/main/java/com/glodblock/github/crossmod/extracells/storage/ProxyVoidCellHandler.java deleted file mode 100644 index aaf11ce2..00000000 --- a/src/main/java/com/glodblock/github/crossmod/extracells/storage/ProxyVoidCellHandler.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.glodblock.github.crossmod.extracells.storage; - -import net.minecraft.item.ItemStack; - -import appeng.core.features.registries.entries.VoidCellHandler; - -public class ProxyVoidCellHandler extends VoidCellHandler { - - @Override - public boolean isCell(ItemStack is) { - return is != null && is.getItem() != null && is.getItem() instanceof ProxyVoidStorageCell; - } -} diff --git a/src/main/java/com/glodblock/github/crossmod/extracells/storage/ProxyVoidStorageCell.java b/src/main/java/com/glodblock/github/crossmod/extracells/storage/ProxyVoidStorageCell.java deleted file mode 100644 index da29ac72..00000000 --- a/src/main/java/com/glodblock/github/crossmod/extracells/storage/ProxyVoidStorageCell.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.glodblock.github.crossmod.extracells.storage; - -import java.util.List; - -import net.minecraft.entity.Entity; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.util.EnumChatFormatting; -import net.minecraft.world.World; - -import appeng.api.AEApi; -import appeng.items.storage.ItemVoidStorageCell; - -public class ProxyVoidStorageCell extends ItemVoidStorageCell { - - private final String name = AEApi.instance().definitions().items().cellVoid().maybeStack(1).get() - .getUnlocalizedName(); - - public ProxyVoidStorageCell() { - this.setUnlocalizedName("ec2placeholder.storage.physical.void"); - } - - @Override - public void addCheckedInformation(ItemStack stack, EntityPlayer player, List info, - boolean displayMoreInfo) { - info.add(EnumChatFormatting.RED + "Extra Cells Placeholder for:"); - info.add(EnumChatFormatting.AQUA + name); - info.add(EnumChatFormatting.GOLD + "Put in your inventory to get a replacement."); - info.add(EnumChatFormatting.GOLD + "It will disappear if no replacement was found."); - info.add(EnumChatFormatting.RED + "Report missing conversions on the GitHub."); - } - - @Override - public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int p_77663_4_, boolean p_77663_5_) { - if (!worldIn.isRemote && entityIn instanceof EntityPlayer player) { - for (int i = 0; i < player.inventory.getSizeInventory(); ++i) { - ItemStack s = player.inventory.getStackInSlot(i); - if (s == stack) { - ItemStack replaceStack = AEApi.instance().definitions().items().cellVoid().maybeStack(1).get(); - player.inventory.setInventorySlotContents(i, replaceStack); - break; - } - } - } - - } -} diff --git a/src/main/java/com/glodblock/github/crossmod/opencomputers/DriverLevelMaintainer.java b/src/main/java/com/glodblock/github/crossmod/opencomputers/DriverLevelMaintainer.java index 81691399..67f9ce9e 100644 --- a/src/main/java/com/glodblock/github/crossmod/opencomputers/DriverLevelMaintainer.java +++ b/src/main/java/com/glodblock/github/crossmod/opencomputers/DriverLevelMaintainer.java @@ -3,7 +3,6 @@ package com.glodblock.github.crossmod.opencomputers; import java.util.HashMap; import java.util.Map; -import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; @@ -13,6 +12,10 @@ import com.glodblock.github.common.tile.TileLevelMaintainer; import com.glodblock.github.loader.ItemAndBlockHolder; import com.glodblock.github.util.NameConst; +import appeng.api.storage.data.IAEStack; +import appeng.tile.inventory.IAEStackInventory; +import appeng.util.Platform; +import appeng.util.item.AEItemStack; import cpw.mods.fml.common.registry.GameRegistry; import li.cil.oc.api.driver.EnvironmentProvider; import li.cil.oc.api.driver.NamedBlock; @@ -44,7 +47,7 @@ public class DriverLevelMaintainer extends DriverSidedTileEntity { super(tileEntity, NameConst.BLOCK_LEVEL_MAINTAINER); } - private int getSlot(Arguments args, IInventory inv, int index, int def) { + private int getSlot(Arguments args, IAEStackInventory inv, int index, int def) { if (index >= 0 && index < args.count()) { int slot = args.checkInteger(index) - 1; if (slot < 0 || slot >= inv.getSizeInventory()) { @@ -93,10 +96,11 @@ public class DriverLevelMaintainer extends DriverSidedTileEntity { @Callback(doc = "function([slot:number]):table -- Get the slot status.") public Object[] getSlot(Context context, Arguments args) { - IInventory config = tileEntity.getInventory(); - int slot = getSlot(args, config, 0, 0); - ItemStack stack = config.getStackInSlot(slot); - if (stack != null) { + IAEStackInventory inventory = tileEntity.getAEStackInventory(); + int slot = getSlot(args, inventory, 0, 0); + IAEStack aeStack = inventory.getAEStackInSlot(slot); + if (aeStack != null) { + ItemStack stack = Platform.stackConvert(aeStack).getItemStack(); Map result = new HashMap<>(); result.put("damage", stack.getItemDamage()); result.put("hasTag", stack.hasTagCompound()); @@ -122,7 +126,7 @@ public class DriverLevelMaintainer extends DriverSidedTileEntity { if (dbStack == null) { throw new IllegalArgumentException("Invalid slot"); } - tileEntity.updateStack(slot, dbStack); + tileEntity.updateStack(slot, AEItemStack.create(dbStack)); } else { throw new IllegalArgumentException("Not a database"); } diff --git a/src/main/java/com/glodblock/github/crossmod/waila/part/SpeedWailaDataProvider.java b/src/main/java/com/glodblock/github/crossmod/waila/part/SpeedWailaDataProvider.java index 7fc376fe..1255ada7 100644 --- a/src/main/java/com/glodblock/github/crossmod/waila/part/SpeedWailaDataProvider.java +++ b/src/main/java/com/glodblock/github/crossmod/waila/part/SpeedWailaDataProvider.java @@ -7,11 +7,11 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; -import com.glodblock.github.common.parts.base.FCSharedFluidBus; import com.glodblock.github.crossmod.waila.Tooltip; import appeng.api.parts.IPart; import appeng.integration.modules.waila.part.BasePartWailaDataProvider; +import appeng.parts.automation.PartSharedItemBus; import mcp.mobius.waila.api.IWailaConfigHandler; import mcp.mobius.waila.api.IWailaDataAccessor; @@ -29,7 +29,7 @@ public class SpeedWailaDataProvider extends BasePartWailaDataProvider { @Override public NBTTagCompound getNBTData(final EntityPlayerMP player, final IPart part, final TileEntity te, final NBTTagCompound tag, final World world, final int x, final int y, final int z) { - if (part instanceof FCSharedFluidBus bus) { + if (part instanceof PartSharedItemBusbus) { tag.setInteger("BusSpeed", bus.calculateAmountToSend() / 5); } return tag; diff --git a/src/main/java/com/glodblock/github/crossmod/waila/tile/LevelMaintainerWailaDataProvider.java b/src/main/java/com/glodblock/github/crossmod/waila/tile/LevelMaintainerWailaDataProvider.java index 297c8d46..5da4f56e 100644 --- a/src/main/java/com/glodblock/github/crossmod/waila/tile/LevelMaintainerWailaDataProvider.java +++ b/src/main/java/com/glodblock/github/crossmod/waila/tile/LevelMaintainerWailaDataProvider.java @@ -37,7 +37,7 @@ public class LevelMaintainerWailaDataProvider extends BaseWailaDataProvider { tileLevelMaintainer); currentToolTip.add( Tooltip.tileLevelMaintainerFormat( - request.getAEItemStack().getItemStack().getDisplayName(), + request.getAEStack().getDisplayName(), request.getQuantity(), request.getBatchSize(), request.isEnable())); diff --git a/src/main/java/com/glodblock/github/inventory/FluidCellConfig.java b/src/main/java/com/glodblock/github/inventory/FluidCellConfig.java deleted file mode 100644 index d4a0ea34..00000000 --- a/src/main/java/com/glodblock/github/inventory/FluidCellConfig.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.glodblock.github.inventory; - -import net.minecraft.item.ItemStack; - -import com.glodblock.github.common.item.ItemFluidPacket; -import com.glodblock.github.util.Util; - -import appeng.items.contents.CellConfig; - -public class FluidCellConfig extends CellConfig { - - public FluidCellConfig(ItemStack is) { - super(is); - } - - @Override - public void setInventorySlotContents(int slot, ItemStack newItemStack) { - if (newItemStack != null && !(newItemStack.getItem() instanceof ItemFluidPacket)) { - ItemStack fluidPacket = ItemFluidPacket.newDisplayStack(Util.getFluidFromItem(newItemStack)); - if (fluidPacket != null) { - super.setInventorySlotContents(slot, fluidPacket); - return; - } - } - super.setInventorySlotContents(slot, newItemStack); - } -} diff --git a/src/main/java/com/glodblock/github/inventory/InventoryHandler.java b/src/main/java/com/glodblock/github/inventory/InventoryHandler.java index 045ed173..0bc85c9f 100644 --- a/src/main/java/com/glodblock/github/inventory/InventoryHandler.java +++ b/src/main/java/com/glodblock/github/inventory/InventoryHandler.java @@ -8,9 +8,9 @@ import net.minecraftforge.common.util.ForgeDirection; import com.glodblock.github.FluidCraft; import com.glodblock.github.inventory.gui.GuiType; -import com.glodblock.github.network.CPacketSwitchGuis; import com.glodblock.github.util.BlockPos; +import appeng.core.sync.GuiBridge; import appeng.util.Platform; import cpw.mods.fml.common.network.IGuiHandler; import cpw.mods.fml.relauncher.Side; @@ -18,21 +18,22 @@ import cpw.mods.fml.relauncher.SideOnly; public class InventoryHandler implements IGuiHandler { - public static void switchGui(GuiType guiType) { - FluidCraft.proxy.netHandler.sendToServer(new CPacketSwitchGuis(guiType)); - } - - public static void openGui(EntityPlayer player, World world, BlockPos pos, ForgeDirection face, GuiType guiType) { + public static void openGui(EntityPlayer player, World world, BlockPos pos, ForgeDirection face, Object guiType) { if (Platform.isClient()) { return; } - player.openGui( - FluidCraft.INSTANCE, - (guiType.ordinal() << 3) | face.ordinal(), - world, - pos.getX(), - pos.getY(), - pos.getZ()); + + if (guiType instanceof GuiType gt) { + player.openGui( + FluidCraft.INSTANCE, + (gt.ordinal() << 3) | face.ordinal(), + world, + pos.getX(), + pos.getY(), + pos.getZ()); + } else if (guiType instanceof GuiBridge gb) { + Platform.openGUI(player, world.getTileEntity(pos.getX(), pos.getY(), pos.getZ()), face, gb); + } } @Nullable diff --git a/src/main/java/com/glodblock/github/inventory/ItemBiggerAppEngInventory.java b/src/main/java/com/glodblock/github/inventory/ItemBiggerAppEngInventory.java index 0ae64bea..f3d28d18 100644 --- a/src/main/java/com/glodblock/github/inventory/ItemBiggerAppEngInventory.java +++ b/src/main/java/com/glodblock/github/inventory/ItemBiggerAppEngInventory.java @@ -2,8 +2,6 @@ package com.glodblock.github.inventory; import net.minecraft.item.ItemStack; -import com.glodblock.github.inventory.gui.GuiType; - import appeng.tile.inventory.BiggerAppEngInventory; import appeng.util.Platform; @@ -29,19 +27,6 @@ public class ItemBiggerAppEngInventory extends BiggerAppEngInventory { @Override public void markDirty() { - boolean isCraft = Platform.openNbtData(is).getBoolean("craftingMode"); - boolean isCraftingTerm = Platform.openNbtData(is).getString("mode_main") - .equals(GuiType.WIRELESS_CRAFTING_TERMINAL.toString()); - boolean isExPattern = Platform.openNbtData(is).getString("mode_main") - .equals(GuiType.WIRELESS_FLUID_PATTERN_TERMINAL_EX.toString()); - if (!isCraftingTerm && !isExPattern && isCraft) { - for (int x = 0; x < this.getSizeInventory(); x++) { - final ItemStack is = this.getStackInSlot(x); - if (is != null) { - is.stackSize = 1; - } - } - } this.writeToNBT(Platform.openNbtData(is), this.name); } diff --git a/src/main/java/com/glodblock/github/inventory/MEMonitorIFluidHandler.java b/src/main/java/com/glodblock/github/inventory/MEMonitorIFluidHandler.java index 3dc37b08..e1ced089 100644 --- a/src/main/java/com/glodblock/github/inventory/MEMonitorIFluidHandler.java +++ b/src/main/java/com/glodblock/github/inventory/MEMonitorIFluidHandler.java @@ -28,6 +28,7 @@ import appeng.api.storage.IMEMonitor; import appeng.api.storage.IMEMonitorHandlerReceiver; import appeng.api.storage.StorageChannel; import appeng.api.storage.data.IAEFluidStack; +import appeng.api.storage.data.IAEStack; import appeng.api.storage.data.IItemList; import appeng.core.AELog; import appeng.util.item.AEFluidStack; @@ -39,7 +40,7 @@ public class MEMonitorIFluidHandler implements IMEMonitor { private final IFluidHandler handler; private final ForgeDirection side; private IItemList cache = AEApi.instance().storage().createFluidList(); - private final HashMap, Object> listeners = new HashMap<>(); + private final HashMap listeners = new HashMap<>(); private BaseActionSource mySource; private StorageFilter mode; private boolean init = false; @@ -56,11 +57,11 @@ public class MEMonitorIFluidHandler implements IMEMonitor { this.side = ForgeDirection.UNKNOWN; } - public void addListener(IMEMonitorHandlerReceiver l, Object verificationToken) { + public void addListener(IMEMonitorHandlerReceiver l, Object verificationToken) { this.listeners.put(l, verificationToken); } - public void removeListener(IMEMonitorHandlerReceiver l) { + public void removeListener(IMEMonitorHandlerReceiver l) { this.listeners.remove(l); } @@ -155,7 +156,7 @@ public class MEMonitorIFluidHandler implements IMEMonitor { } // make diff between cache and new contents - IItemList changes = AEApi.instance().storage().createFluidList(); + IItemList> changes = AEApi.instance().storage().createAEStackList(); // using non-enhanced for to prevent concurrency errors for (Iterator iter = this.cache.iterator(); iter.hasNext();) { IAEFluidStack copy = iter.next().copy(); @@ -168,7 +169,7 @@ public class MEMonitorIFluidHandler implements IMEMonitor { // update cache as soon as possible this.cache = currentlyOnStorage; // remove unchanged values - for (Iterator iter = changes.iterator(); iter.hasNext();) { + for (Iterator> iter = changes.iterator(); iter.hasNext();) { if (iter.next().getStackSize() == 0L) { iter.remove(); } @@ -182,14 +183,13 @@ public class MEMonitorIFluidHandler implements IMEMonitor { return TickRateModulation.SLOWER; } - private void postDifference(Iterable a) { + private void postDifference(Iterable> a) { if (a != null) { - Iterator, Object>> i = this.listeners.entrySet() - .iterator(); + Iterator> i = this.listeners.entrySet().iterator(); while (i.hasNext()) { - Map.Entry, Object> l = i.next(); - IMEMonitorHandlerReceiver key = l.getKey(); + Map.Entry l = i.next(); + IMEMonitorHandlerReceiver key = l.getKey(); if (key.isValid(l.getValue())) { key.postChange(this, a, this.getActionSource()); } else { diff --git a/src/main/java/com/glodblock/github/inventory/WirelessFluidPatternTerminalPatterns.java b/src/main/java/com/glodblock/github/inventory/WirelessFluidPatternTerminalPatterns.java deleted file mode 100644 index 90b62b5c..00000000 --- a/src/main/java/com/glodblock/github/inventory/WirelessFluidPatternTerminalPatterns.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.glodblock.github.inventory; - -import net.minecraft.item.ItemStack; - -import com.glodblock.github.inventory.item.IWirelessPatternTerminal; - -import appeng.tile.inventory.AppEngInternalInventory; -import appeng.tile.inventory.InvOperation; -import appeng.util.Platform; - -public class WirelessFluidPatternTerminalPatterns extends AppEngInternalInventory { - - private final ItemStack is; - private final IWirelessPatternTerminal terminal; - - public WirelessFluidPatternTerminalPatterns(final ItemStack is, final IWirelessPatternTerminal term) { - super(null, 2); - this.is = is; - this.terminal = term; - this.readFromNBT(Platform.openNbtData(is), "pattern"); - - } - - @Override - public void markDirty() { - this.writeToNBT(Platform.openNbtData(is), "pattern"); - } - - @Override - public void markDirty(int slotIndex) { - this.markDirty(); - } - - @Override - public void setInventorySlotContents(final int slot, final ItemStack newItemStack) { - final ItemStack oldStack = this.inv[slot]; - this.inv[slot] = newItemStack; - - if (this.eventsEnabled()) { - ItemStack removed = oldStack; - ItemStack added = newItemStack; - - if (oldStack != null && newItemStack != null && Platform.isSameItemPrecise(oldStack, newItemStack)) { - if (oldStack.stackSize > newItemStack.stackSize) { - removed = removed.copy(); - removed.stackSize -= newItemStack.stackSize; - added = null; - } else if (oldStack.stackSize < newItemStack.stackSize) { - added = added.copy(); - added.stackSize -= oldStack.stackSize; - removed = null; - } else { - removed = added = null; - } - } - this.terminal.onChangeInventory(this, slot, InvOperation.setInventorySlotContents, removed, added); - } - - this.markDirty(); - } -} diff --git a/src/main/java/com/glodblock/github/inventory/gui/GuiType.java b/src/main/java/com/glodblock/github/inventory/gui/GuiType.java index 236e5e21..87d3e16e 100644 --- a/src/main/java/com/glodblock/github/inventory/gui/GuiType.java +++ b/src/main/java/com/glodblock/github/inventory/gui/GuiType.java @@ -5,31 +5,12 @@ import java.util.List; import javax.annotation.Nullable; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.tileentity.TileEntity; -import com.glodblock.github.client.gui.GuiCraftingStatus; -import com.glodblock.github.client.gui.GuiDualInterface; -import com.glodblock.github.client.gui.GuiEssentiaTerminal; -import com.glodblock.github.client.gui.GuiFCPriority; import com.glodblock.github.client.gui.GuiFluidAutoFiller; -import com.glodblock.github.client.gui.GuiFluidCraftAmount; -import com.glodblock.github.client.gui.GuiFluidCraftConfirm; -import com.glodblock.github.client.gui.GuiFluidCraftingWireless; -import com.glodblock.github.client.gui.GuiFluidIO; import com.glodblock.github.client.gui.GuiFluidInterface; -import com.glodblock.github.client.gui.GuiFluidLevelEmitter; -import com.glodblock.github.client.gui.GuiFluidOptimizePatterns; import com.glodblock.github.client.gui.GuiFluidPacketDecoder; import com.glodblock.github.client.gui.GuiFluidPatternEncoder; -import com.glodblock.github.client.gui.GuiFluidPatternExWireless; -import com.glodblock.github.client.gui.GuiFluidPatternTerminal; -import com.glodblock.github.client.gui.GuiFluidPatternTerminalEx; -import com.glodblock.github.client.gui.GuiFluidPatternWireless; -import com.glodblock.github.client.gui.GuiFluidPortableCell; -import com.glodblock.github.client.gui.GuiFluidStorageBus; -import com.glodblock.github.client.gui.GuiFluidTerminal; import com.glodblock.github.client.gui.GuiIngredientBuffer; -import com.glodblock.github.client.gui.GuiInterfaceWireless; import com.glodblock.github.client.gui.GuiLargeIngredientBuffer; import com.glodblock.github.client.gui.GuiLevelEmitterProxy; import com.glodblock.github.client.gui.GuiLevelMaintainer; @@ -37,45 +18,19 @@ import com.glodblock.github.client.gui.GuiLevelTerminal; import com.glodblock.github.client.gui.GuiLevelWireless; import com.glodblock.github.client.gui.GuiMagnetFilter; import com.glodblock.github.client.gui.GuiOCPatternEditor; -import com.glodblock.github.client.gui.GuiPatternItemRenamer; -import com.glodblock.github.client.gui.GuiPatternMulti; -import com.glodblock.github.client.gui.GuiPatternValueAmount; -import com.glodblock.github.client.gui.GuiRenamer; import com.glodblock.github.client.gui.GuiSuperStockReplenisher; -import com.glodblock.github.client.gui.container.ContainerCraftingWireless; -import com.glodblock.github.client.gui.container.ContainerDualInterface; -import com.glodblock.github.client.gui.container.ContainerEssentiaMonitor; import com.glodblock.github.client.gui.container.ContainerFluidAutoFiller; -import com.glodblock.github.client.gui.container.ContainerFluidCraftConfirm; -import com.glodblock.github.client.gui.container.ContainerFluidIO; import com.glodblock.github.client.gui.container.ContainerFluidInterface; -import com.glodblock.github.client.gui.container.ContainerFluidLevelEmitter; -import com.glodblock.github.client.gui.container.ContainerFluidMonitor; -import com.glodblock.github.client.gui.container.ContainerFluidOptimizePatterns; import com.glodblock.github.client.gui.container.ContainerFluidPacketDecoder; import com.glodblock.github.client.gui.container.ContainerFluidPatternEncoder; -import com.glodblock.github.client.gui.container.ContainerFluidPatternExWireless; -import com.glodblock.github.client.gui.container.ContainerFluidPatternTerminal; -import com.glodblock.github.client.gui.container.ContainerFluidPatternTerminalEx; -import com.glodblock.github.client.gui.container.ContainerFluidPatternWireless; -import com.glodblock.github.client.gui.container.ContainerFluidPortableCell; -import com.glodblock.github.client.gui.container.ContainerFluidStorageBus; import com.glodblock.github.client.gui.container.ContainerIngredientBuffer; -import com.glodblock.github.client.gui.container.ContainerInterfaceWireless; import com.glodblock.github.client.gui.container.ContainerLargeIngredientBuffer; import com.glodblock.github.client.gui.container.ContainerLevelMaintainer; import com.glodblock.github.client.gui.container.ContainerLevelTerminal; import com.glodblock.github.client.gui.container.ContainerLevelWireless; import com.glodblock.github.client.gui.container.ContainerMagnetFilter; import com.glodblock.github.client.gui.container.ContainerOCPatternEditor; -import com.glodblock.github.client.gui.container.ContainerPatternMulti; -import com.glodblock.github.client.gui.container.ContainerPatternValueAmount; -import com.glodblock.github.client.gui.container.ContainerRenamer; import com.glodblock.github.client.gui.container.ContainerSuperStockReplenisher; -import com.glodblock.github.common.parts.PartFluidLevelEmitter; -import com.glodblock.github.common.parts.PartFluidStorageBus; -import com.glodblock.github.common.parts.base.FCPart; -import com.glodblock.github.common.parts.base.FCSharedFluidBus; import com.glodblock.github.common.tile.TileFluidAutoFiller; import com.glodblock.github.common.tile.TileFluidPacketDecoder; import com.glodblock.github.common.tile.TileFluidPatternEncoder; @@ -85,34 +40,15 @@ import com.glodblock.github.common.tile.TileLevelMaintainer; import com.glodblock.github.common.tile.TileOCPatternEditor; import com.glodblock.github.common.tile.TileSuperStockReplenisher; import com.glodblock.github.inventory.IDualHost; -import com.glodblock.github.inventory.item.IFluidPortableCell; import com.glodblock.github.inventory.item.IWirelessTerminal; import com.google.common.collect.ImmutableList; +import appeng.api.parts.ILevelEmitter; import appeng.api.storage.ITerminalHost; -import appeng.container.implementations.ContainerCraftAmount; -import appeng.container.implementations.ContainerCraftingStatus; import appeng.container.implementations.ContainerLevelEmitter; -import appeng.container.implementations.ContainerPatternItemRenamer; -import appeng.container.implementations.ContainerPriority; -import appeng.helpers.IInterfaceHost; -import appeng.helpers.IPriorityHost; -import appeng.parts.automation.PartLevelEmitter; public enum GuiType { - RENAMER(new PartOrItemGuiFactory<>(ITerminalHost.class) { - - @Override - protected Object createServerGui(EntityPlayer player, ITerminalHost inv) { - return new ContainerRenamer(player.inventory, inv); - } - - @Override - protected Object createClientGui(EntityPlayer player, ITerminalHost inv) { - return new GuiRenamer(player.inventory, inv); - } - }), FLUID_AUTO_FILLER(new TileGuiFactory<>(TileFluidAutoFiller.class) { @Override @@ -126,32 +62,19 @@ public enum GuiType { } }), - LEVEL_EMITTER_PROXY(new PartGuiFactory<>(PartLevelEmitter.class) { + LEVEL_EMITTER_PROXY(new PartGuiFactory<>(ILevelEmitter.class) { @Override - protected Object createServerGui(EntityPlayer player, PartLevelEmitter inv) { + protected Object createServerGui(EntityPlayer player, ILevelEmitter inv) { return new ContainerLevelEmitter(player.inventory, inv); } @Override - protected Object createClientGui(EntityPlayer player, PartLevelEmitter inv) { + protected Object createClientGui(EntityPlayer player, ILevelEmitter inv) { return new GuiLevelEmitterProxy(player.inventory, inv); } }), - FLUID_LEVEL_EMITTER(new PartGuiFactory<>(PartFluidLevelEmitter.class) { - - @Override - protected Object createServerGui(EntityPlayer player, PartFluidLevelEmitter inv) { - return new ContainerFluidLevelEmitter(player.inventory, inv); - } - - @Override - protected Object createClientGui(EntityPlayer player, PartFluidLevelEmitter inv) { - return new GuiFluidLevelEmitter(player.inventory, inv); - } - }), - LEVEL_MAINTAINER(new TileGuiFactory<>(TileLevelMaintainer.class) { @Override @@ -178,19 +101,6 @@ public enum GuiType { } }), - DUAL_INTERFACE(new TileOrPartGuiFactory<>(IInterfaceHost.class) { - - @Override - protected Object createServerGui(EntityPlayer player, IInterfaceHost inv) { - return new ContainerDualInterface(player.inventory, inv); - } - - @Override - protected Object createClientGui(EntityPlayer player, IInterfaceHost inv) { - return new GuiDualInterface(player.inventory, inv); - } - }), - DUAL_INTERFACE_FLUID(new TileOrPartGuiFactory<>(IDualHost.class) { @Override @@ -204,45 +114,6 @@ public enum GuiType { } }), - PRIORITY(new TileOrPartGuiFactory<>(IPriorityHost.class) { - - @Override - protected Object createServerGui(EntityPlayer player, IPriorityHost inv) { - return new ContainerPriority(player.inventory, inv); - } - - @Override - protected Object createClientGui(EntityPlayer player, IPriorityHost inv) { - return new GuiFCPriority(player.inventory, inv); - } - }), - - FLUID_BUS_IO(new PartGuiFactory<>(FCSharedFluidBus.class) { - - @Override - protected Object createServerGui(EntityPlayer player, FCSharedFluidBus inv) { - return new ContainerFluidIO(player.inventory, inv); - } - - @Override - protected Object createClientGui(EntityPlayer player, FCSharedFluidBus inv) { - return new GuiFluidIO(player.inventory, inv); - } - }), - - FLUID_STORAGE_BUS(new PartGuiFactory<>(PartFluidStorageBus.class) { - - @Override - protected Object createServerGui(EntityPlayer player, PartFluidStorageBus inv) { - return new ContainerFluidStorageBus(player.inventory, inv); - } - - @Override - protected Object createClientGui(EntityPlayer player, PartFluidStorageBus inv) { - return new GuiFluidStorageBus(player.inventory, inv); - } - }), - INGREDIENT_BUFFER(new TileGuiFactory<>(TileIngredientBuffer.class) { @Override @@ -269,32 +140,6 @@ public enum GuiType { } }), - CRAFTING_STATUS(new PartOrItemGuiFactory<>(ITerminalHost.class) { - - @Override - protected Object createServerGui(EntityPlayer player, ITerminalHost inv) { - return new ContainerCraftingStatus(player.inventory, inv); - } - - @Override - protected Object createClientGui(EntityPlayer player, ITerminalHost inv) { - return new GuiCraftingStatus(player.inventory, inv); - } - }), - - FLUID_TERMINAL(new TileOrPartGuiFactory<>(ITerminalHost.class) { - - @Override - protected Object createServerGui(EntityPlayer player, ITerminalHost inv) { - return new ContainerFluidMonitor(player.inventory, inv); - } - - @Override - protected Object createClientGui(EntityPlayer player, ITerminalHost inv) { - return new GuiFluidTerminal(player.inventory, inv); - } - }), - LEVEL_TERMINAL(new TileOrPartGuiFactory<>(ITerminalHost.class) { @Override @@ -308,82 +153,6 @@ public enum GuiType { } }), - PORTABLE_FLUID_CELL(new ItemGuiFactory<>(IFluidPortableCell.class) { - - @Override - protected Object createServerGui(EntityPlayer player, IFluidPortableCell inv) { - return new ContainerFluidPortableCell(player.inventory, inv); - } - - @Override - protected Object createClientGui(EntityPlayer player, IFluidPortableCell inv) { - return new GuiFluidPortableCell(player.inventory, inv); - } - }), - - WIRELESS_FLUID_TERMINAL(new ItemGuiFactory<>(IWirelessTerminal.class) { - - @Override - protected Object createServerGui(EntityPlayer player, IWirelessTerminal inv) { - return new ContainerFluidPortableCell(player.inventory, inv); - } - - @Override - protected Object createClientGui(EntityPlayer player, IWirelessTerminal inv) { - return new GuiFluidPortableCell(player.inventory, inv); - } - }), - - WIRELESS_ESSENTIA_TERMINAL(new ItemGuiFactory<>(IWirelessTerminal.class) { - - @Override - protected Object createServerGui(EntityPlayer player, IWirelessTerminal inv) { - return new ContainerEssentiaMonitor(player.inventory, inv); - } - - @Override - protected Object createClientGui(EntityPlayer player, IWirelessTerminal inv) { - return new GuiEssentiaTerminal(player.inventory, inv); - } - }), - - WIRELESS_FLUID_PATTERN_TERMINAL(new ItemGuiFactory<>(IWirelessTerminal.class) { - - @Override - protected Object createServerGui(EntityPlayer player, IWirelessTerminal inv) { - return new ContainerFluidPatternWireless(player.inventory, inv); - } - - @Override - protected Object createClientGui(EntityPlayer player, IWirelessTerminal inv) { - return new GuiFluidPatternWireless(player.inventory, inv); - } - }), - WIRELESS_FLUID_PATTERN_TERMINAL_EX(new ItemGuiFactory<>(IWirelessTerminal.class) { - - @Override - protected Object createServerGui(EntityPlayer player, IWirelessTerminal inv) { - return new ContainerFluidPatternExWireless(player.inventory, inv); - } - - @Override - protected Object createClientGui(EntityPlayer player, IWirelessTerminal inv) { - return new GuiFluidPatternExWireless(player.inventory, inv); - } - }), - WIRELESS_INTERFACE_TERMINAL(new ItemGuiFactory<>(IWirelessTerminal.class) { - - @Override - protected Object createServerGui(EntityPlayer player, IWirelessTerminal inv) { - return new ContainerInterfaceWireless(player.inventory, inv); - } - - @Override - protected Object createClientGui(EntityPlayer player, IWirelessTerminal inv) { - return new GuiInterfaceWireless(player.inventory, inv); - } - }), - WIRELESS_LEVEL_TERMINAL(new ItemGuiFactory<>(IWirelessTerminal.class) { @Override @@ -397,45 +166,6 @@ public enum GuiType { } }), - WIRELESS_CRAFTING_TERMINAL(new ItemGuiFactory<>(IWirelessTerminal.class) { - - @Override - protected Object createServerGui(EntityPlayer player, IWirelessTerminal inv) { - return new ContainerCraftingWireless(player.inventory, inv); - } - - @Override - protected Object createClientGui(EntityPlayer player, IWirelessTerminal inv) { - return new GuiFluidCraftingWireless(player.inventory, inv); - } - }), - - FLUID_PATTERN_TERMINAL(new PartGuiFactory<>(ITerminalHost.class) { - - @Override - protected Object createServerGui(EntityPlayer player, ITerminalHost inv) { - return new ContainerFluidPatternTerminal(player.inventory, inv); - } - - @Override - protected Object createClientGui(EntityPlayer player, ITerminalHost inv) { - return new GuiFluidPatternTerminal(player.inventory, inv); - } - }), - - FLUID_PATTERN_TERMINAL_EX(new PartGuiFactory<>(ITerminalHost.class) { - - @Override - protected Object createServerGui(EntityPlayer player, ITerminalHost inv) { - return new ContainerFluidPatternTerminalEx(player.inventory, inv); - } - - @Override - protected Object createClientGui(EntityPlayer player, ITerminalHost inv) { - return new GuiFluidPatternTerminalEx(player.inventory, inv); - } - }), - FLUID_PATTERN_ENCODER(new TileGuiFactory<>(TileFluidPatternEncoder.class) { @Override @@ -449,71 +179,6 @@ public enum GuiType { } }), - FLUID_CRAFTING_CONFIRM(new PartGuiFactory<>(FCPart.class) { - - @Override - protected Object createServerGui(EntityPlayer player, FCPart inv) { - return new ContainerFluidCraftConfirm(player.inventory, inv); - } - - @Override - protected Object createClientGui(EntityPlayer player, FCPart inv) { - return new GuiFluidCraftConfirm(player.inventory, inv); - } - }), - - FLUID_CRAFTING_CONFIRM_ITEM(new ItemGuiFactory<>(IWirelessTerminal.class) { - - @Override - protected Object createServerGui(EntityPlayer player, IWirelessTerminal inv) { - return new ContainerFluidCraftConfirm(player.inventory, inv); - } - - @Override - protected Object createClientGui(EntityPlayer player, IWirelessTerminal inv) { - return new GuiFluidCraftConfirm(player.inventory, inv); - } - }), - - FLUID_OPTIMIZE_PATTERNS(new PartGuiFactory<>(FCPart.class) { - - @Override - protected Object createServerGui(EntityPlayer player, FCPart inv) { - return new ContainerFluidOptimizePatterns(player.inventory, inv); - } - - @Override - protected Object createClientGui(EntityPlayer player, FCPart inv) { - return new GuiFluidOptimizePatterns(player.inventory, inv); - } - }), - - FLUID_OPTIMIZE_PATTERNS_ITEM(new ItemGuiFactory<>(IWirelessTerminal.class) { - - @Override - protected Object createServerGui(EntityPlayer player, IWirelessTerminal inv) { - return new ContainerFluidOptimizePatterns(player.inventory, inv); - } - - @Override - protected Object createClientGui(EntityPlayer player, IWirelessTerminal inv) { - return new GuiFluidOptimizePatterns(player.inventory, inv); - } - }), - - FLUID_CRAFTING_AMOUNT(new PartOrItemGuiFactory<>(ITerminalHost.class) { - - @Override - protected Object createServerGui(EntityPlayer player, ITerminalHost inv) { - return new ContainerCraftAmount(player.inventory, inv); - } - - @Override - protected Object createClientGui(EntityPlayer player, ITerminalHost inv) { - return new GuiFluidCraftAmount(player.inventory, inv); - } - }), - FLUID_PACKET_DECODER(new TileGuiFactory<>(TileFluidPacketDecoder.class) { @Override @@ -527,57 +192,6 @@ public enum GuiType { } }), - PATTERN_VALUE_SET(new PartOrItemGuiFactory<>(ITerminalHost.class) { - - @Override - protected Object createServerGui(EntityPlayer player, ITerminalHost inv) { - return new ContainerPatternValueAmount(player.inventory, inv); - } - - @Override - protected Object createClientGui(EntityPlayer player, ITerminalHost inv) { - return new GuiPatternValueAmount(player.inventory, inv); - } - }), - PATTERN_VALUE_SET_TILE(new TileGuiFactory<>(TileEntity.class) { - - @Override - protected Object createServerGui(EntityPlayer player, TileEntity inv) { - return new ContainerPatternValueAmount(player.inventory, inv); - } - - @Override - protected Object createClientGui(EntityPlayer player, TileEntity inv) { - return new GuiPatternValueAmount(player.inventory, inv); - } - }), - - GUI_PATTERN_MULTI(new PartOrItemGuiFactory<>(ITerminalHost.class) { - - @Override - protected Object createServerGui(EntityPlayer player, ITerminalHost inv) { - return new ContainerPatternMulti(player.inventory, inv); - } - - @Override - protected Object createClientGui(EntityPlayer player, ITerminalHost inv) { - return new GuiPatternMulti(player.inventory, inv); - } - }), - - GUI_PATTERN_ITEM_RENAMER(new PartOrItemGuiFactory<>(ITerminalHost.class) { - - @Override - protected Object createServerGui(EntityPlayer player, ITerminalHost inv) { - return new ContainerPatternItemRenamer(player.inventory, inv); - } - - @Override - protected Object createClientGui(EntityPlayer player, ITerminalHost inv) { - return new GuiPatternItemRenamer(player.inventory, inv); - } - }), - WIRELESS_MAGNET_FILTER(new ItemGuiFactory<>(ITerminalHost.class) { @Override diff --git a/src/main/java/com/glodblock/github/inventory/item/BaseWirelessInventory.java b/src/main/java/com/glodblock/github/inventory/item/BaseWirelessInventory.java index 9c46b446..06b81a58 100644 --- a/src/main/java/com/glodblock/github/inventory/item/BaseWirelessInventory.java +++ b/src/main/java/com/glodblock/github/inventory/item/BaseWirelessInventory.java @@ -1,6 +1,7 @@ package com.glodblock.github.inventory.item; -import static com.glodblock.github.common.item.ItemBaseWirelessTerminal.restockItems; +import static appeng.util.Platform.nextEnum; +import static com.glodblock.github.client.UltraTerminalButtons.restockItems; import static com.glodblock.github.inventory.item.WirelessMagnet.modeKey; import java.util.Objects; @@ -10,7 +11,6 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.common.util.ForgeDirection; -import com.glodblock.github.common.item.ItemBaseWirelessTerminal; import com.glodblock.github.util.Util; import appeng.api.config.Actionable; @@ -33,8 +33,7 @@ import appeng.items.tools.powered.ToolWirelessTerminal; import appeng.me.storage.NullInventory; import appeng.util.Platform; -public abstract class BaseWirelessInventory extends MEMonitorHandler - implements IWirelessTerminal, IWirelessExtendCard, ITerminalPins { +public abstract class BaseWirelessInventory extends MEMonitorHandler implements IWirelessTerminal, ITerminalPins { protected final ItemStack target; protected final IAEItemPowerStorage ips; @@ -81,8 +80,8 @@ public abstract class BaseWirelessInventory extends MEMonitorHandler private void readFromNBT() { NBTTagCompound data = Platform.openNbtData(this.target); - this.setMagnetCardMode(WirelessMagnet.Mode.getModes()[data.getInteger(modeKey)]); - this.setRestock(data.getBoolean(ItemBaseWirelessTerminal.restockItems)); + this.setMagnetCardMode(WirelessMagnet.Mode.values()[data.getInteger(modeKey)]); + this.setRestock(data.getBoolean(restockItems)); } public StorageChannel getChannel() { @@ -131,24 +130,20 @@ public abstract class BaseWirelessInventory extends MEMonitorHandler return this.grid; } - @Override public PlayerSource getActionSource() { return this.source; } - @Override public void setMagnetCardMode(WirelessMagnet.Mode mode) { this.magnetMode = mode; } - @Override public WirelessMagnet.Mode getMagnetCardMode() { return this.magnetMode; } public void setMagnetCardNextMode() { - final WirelessMagnet.Mode[] MODES = WirelessMagnet.Mode.getModes(); - setMagnetCardMode(MODES[(getMagnetCardMode().ordinal() + 1) % MODES.length]); + setMagnetCardMode(nextEnum(getMagnetCardMode())); } public void setRestock(boolean val) { diff --git a/src/main/java/com/glodblock/github/inventory/item/IItemPatternTerminal.java b/src/main/java/com/glodblock/github/inventory/item/IItemPatternTerminal.java deleted file mode 100644 index 730530f2..00000000 --- a/src/main/java/com/glodblock/github/inventory/item/IItemPatternTerminal.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.glodblock.github.inventory.item; - -import appeng.api.storage.data.IAEItemStack; - -public interface IItemPatternTerminal extends IItemTerminal { - - boolean isInverted(); - - boolean canBeSubstitute(); - - boolean isPrioritize(); - - boolean isSubstitution(); - - boolean shouldCombine(); - - void onChangeCrafting(IAEItemStack[] newCrafting, IAEItemStack[] newOutput); - - void setCraftingRecipe(final boolean craftingMode); - - void setSubstitution(boolean canSubstitute); - - void setBeSubstitute(boolean canBeSubstitute); - - void setCombineMode(boolean shouldCombine); - - void setPrioritization(boolean canPrioritize); - - void setInverted(boolean inverted); - - int getActivePage(); - - void setActivePage(int activePage); - - boolean isCraftingRecipe(); - - void sortCraftingItems(); - - boolean isAutoFillPattern(); - - void setAutoFillPattern(boolean canFill); -} diff --git a/src/main/java/com/glodblock/github/inventory/item/IWirelessCraftTerminal.java b/src/main/java/com/glodblock/github/inventory/item/IWirelessCraftTerminal.java deleted file mode 100644 index 2b4526ea..00000000 --- a/src/main/java/com/glodblock/github/inventory/item/IWirelessCraftTerminal.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.glodblock.github.inventory.item; - -public interface IWirelessCraftTerminal extends IWirelessTerminal, IItemTerminal { - -} diff --git a/src/main/java/com/glodblock/github/inventory/item/IWirelessExtendCard.java b/src/main/java/com/glodblock/github/inventory/item/IWirelessExtendCard.java deleted file mode 100644 index ef4efa3e..00000000 --- a/src/main/java/com/glodblock/github/inventory/item/IWirelessExtendCard.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.glodblock.github.inventory.item; - -import appeng.api.networking.security.PlayerSource; -import appeng.api.storage.data.IAEStack; - -public interface IWirelessExtendCard { - - default void setMagnetCardMode(WirelessMagnet.Mode mode) {} - - WirelessMagnet.Mode getMagnetCardMode(); - - PlayerSource getActionSource(); - - IAEStack injectItems(IAEStack aeStack); - - IAEStack extractItems(IAEStack aeStack); - - default void setMagnetCardNextMode() {}; - - void setRestock(boolean val); - - default boolean isRestock() { - return false; - } - -} diff --git a/src/main/java/com/glodblock/github/inventory/item/IWirelessMagnetFilter.java b/src/main/java/com/glodblock/github/inventory/item/IWirelessMagnetFilter.java index 2cbee079..00cc498e 100644 --- a/src/main/java/com/glodblock/github/inventory/item/IWirelessMagnetFilter.java +++ b/src/main/java/com/glodblock/github/inventory/item/IWirelessMagnetFilter.java @@ -14,7 +14,7 @@ public interface IWirelessMagnetFilter extends IWirelessTerminal, IItemTerminal String getOreDictFilter(); - void setListMode(WirelessMagnet.ListMode mode); + void setListMode(boolean mode); void setNBTMode(boolean ignoreNBT); diff --git a/src/main/java/com/glodblock/github/inventory/item/IWirelessPatternTerminal.java b/src/main/java/com/glodblock/github/inventory/item/IWirelessPatternTerminal.java deleted file mode 100644 index ccada8e4..00000000 --- a/src/main/java/com/glodblock/github/inventory/item/IWirelessPatternTerminal.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.glodblock.github.inventory.item; - -public interface IWirelessPatternTerminal extends IWirelessTerminal, IItemPatternTerminal { - -} diff --git a/src/main/java/com/glodblock/github/inventory/item/PortableFluidCellInventory.java b/src/main/java/com/glodblock/github/inventory/item/PortableFluidCellInventory.java deleted file mode 100644 index 15e48199..00000000 --- a/src/main/java/com/glodblock/github/inventory/item/PortableFluidCellInventory.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.glodblock.github.inventory.item; - -import java.util.Objects; - -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; - -import com.glodblock.github.common.storage.FluidCellInventory; - -import appeng.api.config.Actionable; -import appeng.api.config.PowerMultiplier; -import appeng.api.config.Settings; -import appeng.api.config.SortDir; -import appeng.api.config.SortOrder; -import appeng.api.config.ViewItems; -import appeng.api.implementations.items.IAEItemPowerStorage; -import appeng.api.storage.IMEMonitor; -import appeng.api.storage.MEMonitorHandler; -import appeng.api.storage.data.IAEFluidStack; -import appeng.api.storage.data.IAEItemStack; -import appeng.api.util.IConfigManager; -import appeng.util.ConfigManager; -import appeng.util.Platform; - -public class PortableFluidCellInventory extends MEMonitorHandler implements IFluidPortableCell { - - private final ItemStack target; - private final IAEItemPowerStorage ips; - private final int inventorySlot; - - public PortableFluidCellInventory(final ItemStack is, final int slot) { - super(Objects.requireNonNull(FluidCellInventory.getCell(is, null))); - this.ips = (IAEItemPowerStorage) is.getItem(); - this.target = is; - this.inventorySlot = slot; - } - - @Override - public int getInventorySlot() { - return this.inventorySlot; - } - - @Override - public ItemStack getItemStack() { - return this.target; - } - - @Override - public double extractAEPower(double amt, final Actionable mode, final PowerMultiplier usePowerMultiplier) { - amt = usePowerMultiplier.multiply(amt); - if (mode == Actionable.SIMULATE) { - return usePowerMultiplier.divide(Math.min(amt, this.ips.getAECurrentPower(this.target))); - } - return usePowerMultiplier.divide(this.ips.extractAEPower(this.target, amt)); - } - - @Override - public IMEMonitor getItemInventory() { - return null; - } - - @Override - public IMEMonitor getFluidInventory() { - return this; - } - - @Override - public IConfigManager getConfigManager() { - final ConfigManager out = new ConfigManager((manager, settingName, newValue) -> { - final NBTTagCompound data = Platform.openNbtData(PortableFluidCellInventory.this.target); - manager.writeToNBT(data); - }); - out.registerSetting(Settings.SORT_BY, SortOrder.NAME); - out.registerSetting(Settings.VIEW_MODE, ViewItems.ALL); - out.registerSetting(Settings.SORT_DIRECTION, SortDir.ASCENDING); - out.readFromNBT((NBTTagCompound) Platform.openNbtData(this.target).copy()); - return out; - } -} diff --git a/src/main/java/com/glodblock/github/inventory/item/WirelessCraftingTerminalInventory.java b/src/main/java/com/glodblock/github/inventory/item/WirelessCraftingTerminalInventory.java deleted file mode 100644 index c4c03de5..00000000 --- a/src/main/java/com/glodblock/github/inventory/item/WirelessCraftingTerminalInventory.java +++ /dev/null @@ -1,154 +0,0 @@ -package com.glodblock.github.inventory.item; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraftforge.common.util.ForgeDirection; - -import com.glodblock.github.inventory.ItemBiggerAppEngInventory; - -import appeng.api.config.Actionable; -import appeng.api.config.PowerMultiplier; -import appeng.api.config.Settings; -import appeng.api.config.SortDir; -import appeng.api.config.SortOrder; -import appeng.api.config.TypeFilter; -import appeng.api.config.ViewItems; -import appeng.api.implementations.items.IAEItemPowerStorage; -import appeng.api.networking.IGridNode; -import appeng.api.storage.IMEMonitor; -import appeng.api.storage.StorageChannel; -import appeng.api.storage.data.IAEFluidStack; -import appeng.api.storage.data.IAEItemStack; -import appeng.api.util.AECableType; -import appeng.api.util.IConfigManager; -import appeng.items.contents.WirelessTerminalViewCells; -import appeng.items.tools.powered.ToolWirelessTerminal; -import appeng.tile.inventory.AppEngInternalInventory; -import appeng.tile.inventory.InvOperation; -import appeng.util.ConfigManager; -import appeng.util.Platform; - -public class WirelessCraftingTerminalInventory extends BaseWirelessInventory implements IWirelessCraftTerminal { - - private final ItemStack target; - private final IAEItemPowerStorage ips; - private final int inventorySlot; - private final AppEngInternalInventory viewCell; - private final StorageChannel channel; - private final IGridNode grid; - - protected AppEngInternalInventory crafting; - protected AppEngInternalInventory output; - - @SuppressWarnings("unchecked") - public WirelessCraftingTerminalInventory(final ItemStack is, final int slot, IGridNode gridNode, - EntityPlayer player) { - super(is, slot, gridNode, player, StorageChannel.ITEMS); - this.ips = (ToolWirelessTerminal) is.getItem(); - this.grid = gridNode; - this.target = is; - this.inventorySlot = slot; - this.viewCell = new WirelessTerminalViewCells(is); - this.channel = StorageChannel.ITEMS; - this.crafting = new ItemBiggerAppEngInventory(is, "crafting_c", 9); - this.output = new ItemBiggerAppEngInventory(is, "output_c", 3); - } - - public StorageChannel getChannel() { - return this.channel; - } - - @Override - public ItemStack getItemStack() { - return this.target; - } - - @Override - public double extractAEPower(double amt, Actionable mode, PowerMultiplier usePowerMultiplier) { - amt = usePowerMultiplier.multiply(amt); - if (mode == Actionable.SIMULATE) { - return usePowerMultiplier.divide(Math.min(amt, this.ips.getAECurrentPower(this.target))); - } - return usePowerMultiplier.divide(this.ips.extractAEPower(this.target, amt)); - } - - @Override - public IMEMonitor getItemInventory() { - return this; - } - - @Override - public IMEMonitor getFluidInventory() { - return null; - } - - @Override - public IConfigManager getConfigManager() { - final ConfigManager out = new ConfigManager((manager, settingName, newValue) -> { - final NBTTagCompound data = Platform.openNbtData(this.target); - manager.writeToNBT(data); - }); - out.registerSetting(Settings.SORT_BY, SortOrder.NAME); - out.registerSetting(Settings.VIEW_MODE, ViewItems.ALL); - out.registerSetting(Settings.SORT_DIRECTION, SortDir.ASCENDING); - out.registerSetting(Settings.TYPE_FILTER, TypeFilter.ALL); - out.readFromNBT((NBTTagCompound) Platform.openNbtData(this.target).copy()); - return out; - } - - @Override - public int getInventorySlot() { - return this.inventorySlot; - } - - @Override - public IInventory getViewCellStorage() { - return this.viewCell; - } - - @Override - public IGridNode getGridNode(ForgeDirection dir) { - return this.grid; - } - - @Override - public AECableType getCableConnectionType(ForgeDirection dir) { - return AECableType.NONE; - } - - @Override - public void securityBreak() { - this.getGridNode(ForgeDirection.UNKNOWN).getMachine().securityBreak(); - } - - @Override - public void saveChanges() { - // NO-OP - } - - @Override - public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removedStack, - ItemStack newStack) { - // NO-OP - } - - @Override - public IInventory getInventoryByName(String name) { - if (name.equals("crafting")) { - return this.crafting; - } - - if (name.equals("output")) { - return this.output; - } - - return null; - } - - @Override - public IGridNode getActionableNode() { - return this.grid; - } -} diff --git a/src/main/java/com/glodblock/github/inventory/item/WirelessFluidTerminalInventory.java b/src/main/java/com/glodblock/github/inventory/item/WirelessFluidTerminalInventory.java deleted file mode 100644 index d0cb1ab3..00000000 --- a/src/main/java/com/glodblock/github/inventory/item/WirelessFluidTerminalInventory.java +++ /dev/null @@ -1,135 +0,0 @@ -package com.glodblock.github.inventory.item; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraftforge.common.util.ForgeDirection; - -import appeng.api.config.Actionable; -import appeng.api.config.PowerMultiplier; -import appeng.api.config.Settings; -import appeng.api.config.SortDir; -import appeng.api.config.SortOrder; -import appeng.api.config.ViewItems; -import appeng.api.implementations.items.IAEItemPowerStorage; -import appeng.api.networking.IGridNode; -import appeng.api.storage.IMEMonitor; -import appeng.api.storage.StorageChannel; -import appeng.api.storage.data.IAEFluidStack; -import appeng.api.storage.data.IAEItemStack; -import appeng.api.util.AECableType; -import appeng.api.util.IConfigManager; -import appeng.items.contents.WirelessTerminalViewCells; -import appeng.items.tools.powered.ToolWirelessTerminal; -import appeng.tile.inventory.AppEngInternalInventory; -import appeng.tile.inventory.InvOperation; -import appeng.util.ConfigManager; -import appeng.util.Platform; - -public class WirelessFluidTerminalInventory extends BaseWirelessInventory implements IWirelessTerminal, IItemTerminal { - - private final ItemStack target; - private final IAEItemPowerStorage ips; - private final int inventorySlot; - private final AppEngInternalInventory viewCell; - private final StorageChannel channel; - private final IGridNode grid; - - @SuppressWarnings("unchecked") - public WirelessFluidTerminalInventory(final ItemStack is, final int slot, IGridNode gridNode, EntityPlayer player) { - super(is, slot, gridNode, player, StorageChannel.FLUIDS); - this.ips = (ToolWirelessTerminal) is.getItem(); - this.grid = gridNode; - this.target = is; - this.inventorySlot = slot; - this.viewCell = new WirelessTerminalViewCells(is); - this.channel = StorageChannel.FLUIDS; - } - - public StorageChannel getChannel() { - return this.channel; - } - - @Override - public ItemStack getItemStack() { - return this.target; - } - - @Override - public double extractAEPower(double amt, Actionable mode, PowerMultiplier usePowerMultiplier) { - amt = usePowerMultiplier.multiply(amt); - if (mode == Actionable.SIMULATE) { - return usePowerMultiplier.divide(Math.min(amt, this.ips.getAECurrentPower(this.target))); - } - return usePowerMultiplier.divide(this.ips.extractAEPower(this.target, amt)); - } - - @Override - public IMEMonitor getItemInventory() { - return null; - } - - @Override - public IMEMonitor getFluidInventory() { - return this; - } - - @Override - public IConfigManager getConfigManager() { - final ConfigManager out = new ConfigManager((manager, settingName, newValue) -> { - final NBTTagCompound data = Platform.openNbtData(this.target); - manager.writeToNBT(data); - }); - out.registerSetting(Settings.SORT_BY, SortOrder.NAME); - out.registerSetting(Settings.VIEW_MODE, ViewItems.ALL); - out.registerSetting(Settings.SORT_DIRECTION, SortDir.ASCENDING); - out.readFromNBT((NBTTagCompound) Platform.openNbtData(this.target).copy()); - out.putSetting(Settings.VIEW_MODE, ViewItems.ALL); - return out; - } - - @Override - public int getInventorySlot() { - return this.inventorySlot; - } - - @Override - public IInventory getViewCellStorage() { - return this.viewCell; - } - - @Override - public IGridNode getGridNode(ForgeDirection dir) { - return this.grid; - } - - @Override - public AECableType getCableConnectionType(ForgeDirection dir) { - return AECableType.NONE; - } - - @Override - public void securityBreak() { - this.getGridNode(ForgeDirection.UNKNOWN).getMachine().securityBreak(); - } - - @Override - public void saveChanges() { - - } - - @Override - public IGridNode getActionableNode() { - return this.grid; - } - - @Override - public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removedStack, - ItemStack newStack) {} - - @Override - public IInventory getInventoryByName(String name) { - return null; - } -} diff --git a/src/main/java/com/glodblock/github/inventory/item/WirelessInterfaceTerminalInventory.java b/src/main/java/com/glodblock/github/inventory/item/WirelessInterfaceTerminalInventory.java deleted file mode 100644 index d3bee52b..00000000 --- a/src/main/java/com/glodblock/github/inventory/item/WirelessInterfaceTerminalInventory.java +++ /dev/null @@ -1,146 +0,0 @@ -package com.glodblock.github.inventory.item; - -import java.util.Objects; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraftforge.common.util.ForgeDirection; - -import com.glodblock.github.util.Util; - -import appeng.api.config.Actionable; -import appeng.api.config.PowerMultiplier; -import appeng.api.config.Settings; -import appeng.api.config.TerminalStyle; -import appeng.api.implementations.items.IAEItemPowerStorage; -import appeng.api.networking.IGridNode; -import appeng.api.storage.IMEMonitor; -import appeng.api.storage.StorageChannel; -import appeng.api.storage.data.IAEFluidStack; -import appeng.api.storage.data.IAEItemStack; -import appeng.api.util.AECableType; -import appeng.api.util.IConfigManager; -import appeng.items.tools.powered.ToolWirelessTerminal; -import appeng.tile.inventory.InvOperation; -import appeng.util.ConfigManager; -import appeng.util.Platform; - -public class WirelessInterfaceTerminalInventory implements IClickableInTerminal, IWirelessTerminal { - - private final ItemStack target; - private final IAEItemPowerStorage ips; - private final int inventorySlot; - private final IGridNode grid; - private Util.DimensionalCoordSide tile; - - public WirelessInterfaceTerminalInventory(ItemStack is, int slot, IGridNode gridNode, EntityPlayer player) { - Objects.requireNonNull(Util.getWirelessInv(is, player, StorageChannel.ITEMS)); - this.ips = (ToolWirelessTerminal) is.getItem(); - this.grid = gridNode; - this.target = is; - this.inventorySlot = slot; - readFromNBT(); - } - - public void readFromNBT() { - NBTTagCompound data = Platform.openNbtData(this.target); - if (data.hasKey("clickedInterface")) { - NBTTagCompound tileMsg = (NBTTagCompound) data.getTag("clickedInterface"); - this.tile = Util.DimensionalCoordSide.readFromNBT(tileMsg); - } - } - - public void writeToNBT() { - NBTTagCompound data = Platform.openNbtData(this.target); - NBTTagCompound tileMsg = new NBTTagCompound(); - tile.writeToNBT(tileMsg); - data.setTag("clickedInterface", tileMsg); - } - - @Override - public IGridNode getActionableNode() { - return this.grid; - } - - @Override - public IGridNode getGridNode(ForgeDirection dir) { - return this.grid; - } - - @Override - public AECableType getCableConnectionType(ForgeDirection dir) { - return AECableType.NONE; - } - - @Override - public void securityBreak() { - this.getGridNode(ForgeDirection.UNKNOWN).getMachine().securityBreak(); - } - - @Override - public ItemStack getItemStack() { - return this.target; - } - - @Override - public IInventory getViewCellStorage() { - return null; - } - - @Override - public double extractAEPower(double amt, Actionable mode, PowerMultiplier usePowerMultiplier) { - amt = usePowerMultiplier.multiply(amt); - if (mode == Actionable.SIMULATE) { - return usePowerMultiplier.divide(Math.min(amt, this.ips.getAECurrentPower(this.target))); - } - return usePowerMultiplier.divide(this.ips.extractAEPower(this.target, amt)); - } - - @Override - public IMEMonitor getItemInventory() { - return null; - } - - @Override - public IMEMonitor getFluidInventory() { - return null; - } - - @Override - public IConfigManager getConfigManager() { - final ConfigManager out = new ConfigManager((manager, settingName, newValue) -> { - final NBTTagCompound data = Platform.openNbtData(this.target); - manager.writeToNBT(data); - }); - out.registerSetting(Settings.TERMINAL_STYLE, TerminalStyle.SMALL); - out.readFromNBT((NBTTagCompound) Platform.openNbtData(this.target).copy()); - return out; - } - - @Override - public int getInventorySlot() { - return this.inventorySlot; - } - - @Override - public void saveChanges() {} - - @Override - public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removedStack, - ItemStack newStack) { - - } - - @Override - public void setClickedInterface(Util.DimensionalCoordSide tile) { - this.tile = tile; - this.writeToNBT(); - } - - @Override - public Util.DimensionalCoordSide getClickedInterface() { - return this.tile; - } -} diff --git a/src/main/java/com/glodblock/github/inventory/item/WirelessLevelTerminalInventory.java b/src/main/java/com/glodblock/github/inventory/item/WirelessLevelTerminalInventory.java index 8150d6a1..bb3ed76b 100644 --- a/src/main/java/com/glodblock/github/inventory/item/WirelessLevelTerminalInventory.java +++ b/src/main/java/com/glodblock/github/inventory/item/WirelessLevelTerminalInventory.java @@ -1,7 +1,9 @@ package com.glodblock.github.inventory.item; +import java.util.List; import java.util.Objects; +import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; @@ -22,12 +24,17 @@ import appeng.api.storage.data.IAEFluidStack; import appeng.api.storage.data.IAEItemStack; import appeng.api.util.AECableType; import appeng.api.util.IConfigManager; +import appeng.helpers.ICustomButtonDataObject; +import appeng.helpers.ICustomButtonProvider; +import appeng.helpers.ICustomButtonSource; import appeng.items.tools.powered.ToolWirelessTerminal; import appeng.tile.inventory.InvOperation; import appeng.util.ConfigManager; import appeng.util.Platform; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; -public class WirelessLevelTerminalInventory implements IClickableInTerminal, IWirelessTerminal { +public class WirelessLevelTerminalInventory implements IClickableInTerminal, IWirelessTerminal, ICustomButtonProvider { private final ItemStack target; private final IAEItemPowerStorage ips; @@ -42,6 +49,11 @@ public class WirelessLevelTerminalInventory implements IClickableInTerminal, IWi this.target = is; this.inventorySlot = slot; readFromNBT(); + + if (getItemStack().getItem() instanceof ICustomButtonSource icbs) { + customButtonDataObject = icbs.getCustomDataObject(this); + customButtonDataObject.readData(getItemStack().getTagCompound()); + } } public void readFromNBT() { @@ -143,4 +155,39 @@ public class WirelessLevelTerminalInventory implements IClickableInTerminal, IWi public Util.DimensionalCoordSide getClickedInterface() { return this.tile; } + + private ICustomButtonDataObject customButtonDataObject; + + @Override + public void writeCustomButtonData() { + this.customButtonDataObject.writeData(this.getItemStack().getTagCompound()); + } + + @Override + public void readCustomButtonData() { + this.customButtonDataObject.readData(this.getItemStack().getTagCompound()); + } + + @Override + public void initCustomButtons(int guiLeft, int guiTop, int xSize, int ySize, int xOffset, int yOffset, + List buttonList) { + if (customButtonDataObject != null) + customButtonDataObject.initCustomButtons(guiLeft, guiTop, xSize, ySize, xOffset, yOffset, buttonList); + } + + @SideOnly(Side.CLIENT) + @Override + public boolean actionPerformedCustomButtons(final GuiButton btn) { + return customButtonDataObject != null && customButtonDataObject.actionPerformedCustomButtons(btn); + } + + @Override + public ICustomButtonDataObject getDataObject() { + return customButtonDataObject; + } + + @Override + public void setDataObject(ICustomButtonDataObject dataObject) { + customButtonDataObject = dataObject; + } } diff --git a/src/main/java/com/glodblock/github/inventory/item/WirelessMagnet.java b/src/main/java/com/glodblock/github/inventory/item/WirelessMagnet.java index f4ea1de2..fbd64079 100644 --- a/src/main/java/com/glodblock/github/inventory/item/WirelessMagnet.java +++ b/src/main/java/com/glodblock/github/inventory/item/WirelessMagnet.java @@ -29,13 +29,7 @@ public class WirelessMagnet { Off, Inv, - ME; - - private static final Mode[] MODES = Mode.values(); - - public static Mode[] getModes() { - return MODES; - } + ME } public enum ListMode { @@ -144,7 +138,7 @@ public class WirelessMagnet { if (is != null && is.getItem() instanceof ItemWirelessUltraTerminal) { NBTTagCompound data = Platform.openNbtData(is); if (data.hasKey(modeKey)) { - return Mode.getModes()[data.getInteger(modeKey)]; + return Mode.values()[data.getInteger(modeKey)]; } setMode(is, Mode.Off); } diff --git a/src/main/java/com/glodblock/github/inventory/item/WirelessMagnetCardFilterInventory.java b/src/main/java/com/glodblock/github/inventory/item/WirelessMagnetCardFilterInventory.java index b86c0a63..181b2c94 100644 --- a/src/main/java/com/glodblock/github/inventory/item/WirelessMagnetCardFilterInventory.java +++ b/src/main/java/com/glodblock/github/inventory/item/WirelessMagnetCardFilterInventory.java @@ -123,8 +123,8 @@ public class WirelessMagnetCardFilterInventory extends BaseWirelessInventory imp } @Override - public void setListMode(WirelessMagnet.ListMode mode) { - this.listMode = mode; + public void setListMode(boolean mode) { + this.listMode = mode ? WirelessMagnet.ListMode.WhiteList : WirelessMagnet.ListMode.BlackList; } @Override diff --git a/src/main/java/com/glodblock/github/inventory/item/WirelessPatternTerminalExInventory.java b/src/main/java/com/glodblock/github/inventory/item/WirelessPatternTerminalExInventory.java deleted file mode 100644 index 42ca6fa3..00000000 --- a/src/main/java/com/glodblock/github/inventory/item/WirelessPatternTerminalExInventory.java +++ /dev/null @@ -1,423 +0,0 @@ -package com.glodblock.github.inventory.item; - -import java.util.ArrayList; -import java.util.List; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraftforge.common.util.ForgeDirection; - -import com.glodblock.github.common.item.ItemFluidDrop; -import com.glodblock.github.common.item.ItemFluidPacket; -import com.glodblock.github.inventory.ItemBiggerAppEngInventory; -import com.glodblock.github.inventory.WirelessFluidPatternTerminalPatterns; - -import appeng.api.config.Actionable; -import appeng.api.config.PowerMultiplier; -import appeng.api.config.Settings; -import appeng.api.config.SortDir; -import appeng.api.config.SortOrder; -import appeng.api.config.TypeFilter; -import appeng.api.config.ViewItems; -import appeng.api.implementations.ICraftingPatternItem; -import appeng.api.implementations.items.IAEItemPowerStorage; -import appeng.api.networking.IGridNode; -import appeng.api.networking.crafting.ICraftingPatternDetails; -import appeng.api.storage.IMEMonitor; -import appeng.api.storage.StorageChannel; -import appeng.api.storage.data.IAEFluidStack; -import appeng.api.storage.data.IAEItemStack; -import appeng.api.util.AECableType; -import appeng.api.util.IConfigManager; -import appeng.items.contents.WirelessTerminalViewCells; -import appeng.items.tools.powered.ToolWirelessTerminal; -import appeng.tile.inventory.AppEngInternalInventory; -import appeng.tile.inventory.InvOperation; -import appeng.util.ConfigManager; -import appeng.util.Platform; - -public class WirelessPatternTerminalExInventory extends BaseWirelessInventory implements IWirelessPatternTerminal { - - private final ItemStack target; - private final IAEItemPowerStorage ips; - private final int inventorySlot; - private final AppEngInternalInventory viewCell; - private final StorageChannel channel; - private final IGridNode grid; - - protected AppEngInternalInventory crafting; - protected AppEngInternalInventory output; - protected final WirelessFluidPatternTerminalPatterns pattern; - - protected boolean craftingMode = false; - protected boolean substitute = false; - protected boolean combine = false; - protected boolean prioritize = false; - protected boolean inverted = false; - protected boolean beSubstitute = false; - protected boolean autoFillPattern = false; - protected int activePage = 0; - - @SuppressWarnings("unchecked") - public WirelessPatternTerminalExInventory(final ItemStack is, final int slot, IGridNode gridNode, - EntityPlayer player) { - super(is, slot, gridNode, player, StorageChannel.ITEMS); - this.ips = (ToolWirelessTerminal) is.getItem(); - this.grid = gridNode; - this.target = is; - this.inventorySlot = slot; - this.viewCell = new WirelessTerminalViewCells(is); - this.channel = StorageChannel.ITEMS; - this.pattern = new WirelessFluidPatternTerminalPatterns(is, this); - this.crafting = new ItemBiggerAppEngInventory(is, "crafting_ex", 32); - this.output = new ItemBiggerAppEngInventory(is, "output_ex", 32); - } - - public StorageChannel getChannel() { - return this.channel; - } - - @Override - public ItemStack getItemStack() { - return this.target; - } - - @Override - public double extractAEPower(double amt, Actionable mode, PowerMultiplier usePowerMultiplier) { - amt = usePowerMultiplier.multiply(amt); - if (mode == Actionable.SIMULATE) { - return usePowerMultiplier.divide(Math.min(amt, this.ips.getAECurrentPower(this.target))); - } - return usePowerMultiplier.divide(this.ips.extractAEPower(this.target, amt)); - } - - @Override - public IMEMonitor getItemInventory() { - return this; - } - - @Override - public IMEMonitor getFluidInventory() { - return null; - } - - public void readFromNBT() { - NBTTagCompound data = Platform.openNbtData(this.target); - this.setSubstitution(data.getBoolean("substitute")); - this.setCombineMode(data.getBoolean("combine")); - this.setBeSubstitute(data.getBoolean("beSubstitute")); - this.setPrioritization(data.getBoolean("priorization")); - this.setInverted(data.getBoolean("inverted")); - this.setActivePage(data.getInteger("activePage")); - this.setAutoFillPattern(data.getBoolean("autoFillPattern")); - } - - public void writeToNBT() { - NBTTagCompound data = Platform.openNbtData(this.target); - data.setBoolean("substitute", this.substitute); - data.setBoolean("combine", this.combine); - data.setBoolean("beSubstitute", this.beSubstitute); - data.setBoolean("priorization", this.prioritize); - data.setBoolean("inverted", this.inverted); - data.setInteger("activePage", this.activePage); - data.setBoolean("autoFillPattern", this.autoFillPattern); - } - - @Override - public IConfigManager getConfigManager() { - final ConfigManager out = new ConfigManager((manager, settingName, newValue) -> { - final NBTTagCompound data = Platform.openNbtData(this.target); - manager.writeToNBT(data); - }); - out.registerSetting(Settings.SORT_BY, SortOrder.NAME); - out.registerSetting(Settings.VIEW_MODE, ViewItems.ALL); - out.registerSetting(Settings.SORT_DIRECTION, SortDir.ASCENDING); - out.registerSetting(Settings.TYPE_FILTER, TypeFilter.ALL); - out.readFromNBT((NBTTagCompound) Platform.openNbtData(this.target).copy()); - this.readFromNBT(); - return out; - } - - @Override - public int getInventorySlot() { - return this.inventorySlot; - } - - @Override - public IInventory getViewCellStorage() { - return this.viewCell; - } - - @Override - public IGridNode getGridNode(ForgeDirection dir) { - return this.grid; - } - - @Override - public AECableType getCableConnectionType(ForgeDirection dir) { - return AECableType.NONE; - } - - @Override - public void securityBreak() { - this.getGridNode(ForgeDirection.UNKNOWN).getMachine().securityBreak(); - } - - @Override - public void saveChanges() { - // NO-OP - } - - @Override - public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removedStack, - ItemStack newStack) { - if (inv == this.pattern && slot == 1) { - final ItemStack is = inv.getStackInSlot(1); - - if (is != null && is.getItem() instanceof final ICraftingPatternItem craftingPatternItem) { - final ICraftingPatternDetails details = craftingPatternItem - .getPatternForItem(is, this.getActionableNode().getWorld()); - - if (details != null) { - final IAEItemStack[] inItems = details.getInputs(); - final IAEItemStack[] outItems = details.getOutputs(); - int inputsCount = 0; - int outputCount = 0; - for (IAEItemStack inItem : inItems) { - if (inItem != null) { - inputsCount++; - } - } - for (IAEItemStack outItem : outItems) { - if (outItem != null) { - outputCount++; - } - } - - this.setSubstitution(details.canSubstitute()); - if (newStack != null) { - NBTTagCompound data = newStack.getTagCompound(); - this.setCombineMode(data.getInteger("combine") == 1); - this.setBeSubstitute(details.canBeSubstitute()); - } - this.setInverted(inputsCount <= 8 && outputCount > 8); - this.setActivePage(0); - - for (int i = 0; i < this.crafting.getSizeInventory(); i++) { - this.crafting.setInventorySlotContents(i, null); - } - - for (int i = 0; i < this.output.getSizeInventory(); i++) { - this.output.setInventorySlotContents(i, null); - } - - for (int i = 0; i < this.crafting.getSizeInventory() && i < inItems.length; i++) { - final IAEItemStack item = inItems[i]; - if (item != null) { - if (item.getItem() instanceof ItemFluidDrop) { - ItemStack packet = ItemFluidPacket - .newStack(ItemFluidDrop.getFluidStack(item.getItemStack())); - this.crafting.setInventorySlotContents(i, packet); - } else this.crafting.setInventorySlotContents(i, item.getItemStack()); - } - } - - if (inverted) { - for (int i = 0; i < this.output.getSizeInventory() && i < outItems.length; i++) { - final IAEItemStack item = outItems[i]; - if (item != null) { - if (item.getItem() instanceof ItemFluidDrop) { - ItemStack packet = ItemFluidPacket - .newStack(ItemFluidDrop.getFluidStack(item.getItemStack())); - this.output.setInventorySlotContents(i, packet); - } else this.output.setInventorySlotContents(i, item.getItemStack()); - } - } - } else { - for (int i = 0; i < outItems.length && i < 8; i++) { - final IAEItemStack item = outItems[i]; - if (item != null) { - if (item.getItem() instanceof ItemFluidDrop) { - ItemStack packet = ItemFluidPacket - .newStack(ItemFluidDrop.getFluidStack(item.getItemStack())); - this.output.setInventorySlotContents(i >= 4 ? 12 + i : i, packet); - } else this.output.setInventorySlotContents(i >= 4 ? 12 + i : i, item.getItemStack()); - } - } - } - } - } - } - } - - private void fixCraftingRecipes() { - if (this.craftingMode) { - for (int x = 0; x < this.crafting.getSizeInventory(); x++) { - final ItemStack is = this.crafting.getStackInSlot(x); - if (is != null) { - is.stackSize = 1; - } - } - } - } - - @Override - public boolean isInverted() { - return this.inverted; - } - - @Override - public IInventory getInventoryByName(String name) { - if (name.equals("crafting")) { - return this.crafting; - } - - if (name.equals("output")) { - return this.output; - } - - if (name.equals("pattern")) { - return this.pattern; - } - - return null; - } - - @Override - public boolean canBeSubstitute() { - return this.beSubstitute; - } - - @Override - public boolean isPrioritize() { - return this.prioritize; - } - - @Override - public boolean isSubstitution() { - return this.substitute; - } - - @Override - public boolean shouldCombine() { - return this.combine; - } - - @Override - public void onChangeCrafting(IAEItemStack[] newCrafting, IAEItemStack[] newOutput) { - IInventory crafting = this.getInventoryByName("crafting"); - IInventory output = this.getInventoryByName("output"); - if (crafting instanceof AppEngInternalInventory && output instanceof AppEngInternalInventory) { - for (int x = 0; x < crafting.getSizeInventory() && x < newCrafting.length; x++) { - final IAEItemStack item = newCrafting[x]; - crafting.setInventorySlotContents(x, item == null ? null : item.getItemStack()); - } - for (int x = 0; x < output.getSizeInventory() && x < newOutput.length; x++) { - final IAEItemStack item = newOutput[x]; - output.setInventorySlotContents(x, item == null ? null : item.getItemStack()); - } - } - } - - @Override - public void setCraftingRecipe(boolean craftingMode) { - this.craftingMode = craftingMode; - this.fixCraftingRecipes(); - // force update crafting mode - ((ItemBiggerAppEngInventory) this.crafting).setCraftingMode(craftingMode); - } - - @Override - public void setSubstitution(boolean canSubstitute) { - this.substitute = canSubstitute; - } - - @Override - public void setBeSubstitute(boolean canBeSubstitute) { - this.beSubstitute = canBeSubstitute; - } - - @Override - public void setCombineMode(boolean shouldCombine) { - this.combine = shouldCombine; - } - - @Override - public void setPrioritization(boolean canPrioritize) { - this.prioritize = canPrioritize; - } - - @Override - public void setInverted(boolean inverted) { - this.inverted = inverted; - } - - @Override - public int getActivePage() { - return this.activePage; - } - - @Override - public void setActivePage(int activePage) { - this.activePage = activePage; - } - - @Override - public boolean isCraftingRecipe() { - return this.craftingMode; - } - - @Override - public void sortCraftingItems() { - List items = new ArrayList<>(); - List fluids = new ArrayList<>(); - for (ItemStack is : this.crafting) { - if (is == null) continue; - if (is.getItem() instanceof ItemFluidPacket) { - fluids.add(is); - } else { - items.add(is); - } - } - if (this.prioritize) { - fluids.addAll(items); - items.clear(); - } else { - items.addAll(fluids); - fluids.clear(); - } - - for (int i = 0; i < this.crafting.getSizeInventory(); i++) { - if (this.crafting.getStackInSlot(i) == null) break; - if (items.isEmpty()) { - this.crafting.setInventorySlotContents(i, fluids.get(i)); - } else { - this.crafting.setInventorySlotContents(i, items.get(i)); - } - } - saveChanges(); - } - - @Override - public boolean isAutoFillPattern() { - return this.autoFillPattern; - } - - @Override - public void setAutoFillPattern(boolean canFill) { - this.autoFillPattern = canFill; - } - - @Override - public void saveSettings() { - super.saveSettings(); - this.writeToNBT(); - } - - @Override - public IGridNode getActionableNode() { - return this.grid; - } -} diff --git a/src/main/java/com/glodblock/github/inventory/item/WirelessPatternTerminalInventory.java b/src/main/java/com/glodblock/github/inventory/item/WirelessPatternTerminalInventory.java deleted file mode 100644 index cdb39213..00000000 --- a/src/main/java/com/glodblock/github/inventory/item/WirelessPatternTerminalInventory.java +++ /dev/null @@ -1,396 +0,0 @@ -package com.glodblock.github.inventory.item; - -import java.util.ArrayList; -import java.util.List; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraftforge.common.util.ForgeDirection; - -import com.glodblock.github.common.item.ItemFluidDrop; -import com.glodblock.github.common.item.ItemFluidPacket; -import com.glodblock.github.inventory.ItemBiggerAppEngInventory; -import com.glodblock.github.inventory.WirelessFluidPatternTerminalPatterns; - -import appeng.api.config.Actionable; -import appeng.api.config.PowerMultiplier; -import appeng.api.config.Settings; -import appeng.api.config.SortDir; -import appeng.api.config.SortOrder; -import appeng.api.config.TypeFilter; -import appeng.api.config.ViewItems; -import appeng.api.implementations.ICraftingPatternItem; -import appeng.api.implementations.items.IAEItemPowerStorage; -import appeng.api.networking.IGridNode; -import appeng.api.networking.crafting.ICraftingPatternDetails; -import appeng.api.storage.IMEMonitor; -import appeng.api.storage.StorageChannel; -import appeng.api.storage.data.IAEFluidStack; -import appeng.api.storage.data.IAEItemStack; -import appeng.api.util.AECableType; -import appeng.api.util.IConfigManager; -import appeng.items.contents.WirelessTerminalViewCells; -import appeng.items.tools.powered.ToolWirelessTerminal; -import appeng.tile.inventory.AppEngInternalInventory; -import appeng.tile.inventory.InvOperation; -import appeng.util.ConfigManager; -import appeng.util.Platform; - -public class WirelessPatternTerminalInventory extends BaseWirelessInventory implements IWirelessPatternTerminal { - - private final ItemStack target; - private final IAEItemPowerStorage ips; - private final int inventorySlot; - private final AppEngInternalInventory viewCell; - private final StorageChannel channel; - private final IGridNode grid; - - protected AppEngInternalInventory crafting; - protected AppEngInternalInventory output; - protected final WirelessFluidPatternTerminalPatterns pattern; - - protected boolean craftingMode = true; - protected boolean substitute = false; - protected boolean combine = false; - protected boolean prioritize = false; - protected boolean inverted = false; - protected boolean beSubstitute = false; - protected boolean autoFillPattern = false; - protected int activePage = 0; - - @SuppressWarnings("unchecked") - public WirelessPatternTerminalInventory(final ItemStack is, final int slot, IGridNode gridNode, - EntityPlayer player) { - super(is, slot, gridNode, player, StorageChannel.ITEMS); - this.ips = (ToolWirelessTerminal) is.getItem(); - this.grid = gridNode; - this.target = is; - this.inventorySlot = slot; - this.viewCell = new WirelessTerminalViewCells(is); - this.channel = StorageChannel.ITEMS; - this.pattern = new WirelessFluidPatternTerminalPatterns(is, this); - this.crafting = new ItemBiggerAppEngInventory(is, "crafting", 9); - this.output = new ItemBiggerAppEngInventory(is, "output", 3); - } - - public StorageChannel getChannel() { - return this.channel; - } - - @Override - public ItemStack getItemStack() { - return this.target; - } - - @Override - public double extractAEPower(double amt, Actionable mode, PowerMultiplier usePowerMultiplier) { - amt = usePowerMultiplier.multiply(amt); - if (mode == Actionable.SIMULATE) { - return usePowerMultiplier.divide(Math.min(amt, this.ips.getAECurrentPower(this.target))); - } - return usePowerMultiplier.divide(this.ips.extractAEPower(this.target, amt)); - } - - @Override - public IMEMonitor getItemInventory() { - return this; - } - - @Override - public IMEMonitor getFluidInventory() { - return null; - } - - public void readFromNBT() { - NBTTagCompound data = Platform.openNbtData(this.target); - this.setCraftingRecipe(data.getBoolean("craftingMode")); - this.setSubstitution(data.getBoolean("substitute")); - this.setCombineMode(data.getBoolean("combine")); - this.setBeSubstitute(data.getBoolean("beSubstitute")); - this.setActivePage(data.getInteger("activePage")); - this.setAutoFillPattern(data.getBoolean("autoFillPattern")); - } - - public void writeToNBT() { - NBTTagCompound data = Platform.openNbtData(this.target); - data.setBoolean("craftingMode", this.craftingMode); - data.setBoolean("substitute", this.substitute); - data.setBoolean("combine", this.combine); - data.setBoolean("beSubstitute", this.beSubstitute); - data.setInteger("activePage", this.activePage); - data.setBoolean("autoFillPattern", this.autoFillPattern); - } - - @Override - public IConfigManager getConfigManager() { - final ConfigManager out = new ConfigManager((manager, settingName, newValue) -> { - final NBTTagCompound data = Platform.openNbtData(this.target); - manager.writeToNBT(data); - }); - out.registerSetting(Settings.SORT_BY, SortOrder.NAME); - out.registerSetting(Settings.VIEW_MODE, ViewItems.ALL); - out.registerSetting(Settings.SORT_DIRECTION, SortDir.ASCENDING); - out.registerSetting(Settings.TYPE_FILTER, TypeFilter.ALL); - out.readFromNBT((NBTTagCompound) Platform.openNbtData(this.target).copy()); - this.readFromNBT(); - return out; - } - - @Override - public int getInventorySlot() { - return this.inventorySlot; - } - - @Override - public IInventory getViewCellStorage() { - return this.viewCell; - } - - @Override - public IGridNode getGridNode(ForgeDirection dir) { - return this.grid; - } - - @Override - public AECableType getCableConnectionType(ForgeDirection dir) { - return AECableType.NONE; - } - - @Override - public void securityBreak() { - this.getGridNode(ForgeDirection.UNKNOWN).getMachine().securityBreak(); - } - - @Override - public void saveChanges() { - // NO-OP - } - - @Override - public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removedStack, - ItemStack newStack) { - if (inv == this.pattern && slot == 1) { - final ItemStack is = inv.getStackInSlot(1); - if (is != null && is.getItem() instanceof final ICraftingPatternItem craftingPatternItem) { - final ICraftingPatternDetails details = craftingPatternItem - .getPatternForItem(is, this.getActionableNode().getWorld()); - if (details != null) { - final IAEItemStack[] inItems = details.getInputs(); - final IAEItemStack[] outItems = details.getOutputs(); - - this.setCraftingRecipe(details.isCraftable()); - this.setSubstitution(details.canSubstitute()); - if (newStack != null) { - NBTTagCompound data = newStack.getTagCompound(); - this.setCombineMode(data.getInteger("combine") == 1); - this.setBeSubstitute(details.canBeSubstitute()); - } - for (int i = 0; i < this.crafting.getSizeInventory(); i++) { - this.crafting.setInventorySlotContents(i, null); - } - - for (int i = 0; i < this.output.getSizeInventory(); i++) { - this.output.setInventorySlotContents(i, null); - } - - for (int i = 0; i < this.crafting.getSizeInventory() && i < inItems.length; i++) { - if (inItems[i] != null) { - final IAEItemStack item = inItems[i]; - if (item != null && item.getItem() instanceof ItemFluidDrop) { - ItemStack packet = ItemFluidPacket - .newStack(ItemFluidDrop.getFluidStack(item.getItemStack())); - this.crafting.setInventorySlotContents(i, packet); - } else this.crafting.setInventorySlotContents(i, item == null ? null : item.getItemStack()); - } - } - - for (int i = 0; i < this.output.getSizeInventory() && i < outItems.length; i++) { - if (outItems[i] != null) { - final IAEItemStack item = outItems[i]; - if (item != null && item.getItem() instanceof ItemFluidDrop) { - ItemStack packet = ItemFluidPacket - .newStack(ItemFluidDrop.getFluidStack(item.getItemStack())); - this.output.setInventorySlotContents(i, packet); - } else this.output.setInventorySlotContents(i, item == null ? null : item.getItemStack()); - } - } - } - } - } - if (inv == this.crafting) { - this.fixCraftingRecipes(); - } - } - - private void fixCraftingRecipes() { - if (this.craftingMode) { - for (int x = 0; x < this.crafting.getSizeInventory(); x++) { - final ItemStack is = this.crafting.getStackInSlot(x); - if (is != null) { - is.stackSize = 1; - } - } - } - } - - @Override - public boolean isInverted() { - return false; - } - - @Override - public IInventory getInventoryByName(String name) { - if (name.equals("crafting")) { - return this.crafting; - } - - if (name.equals("output")) { - return this.output; - } - - if (name.equals("pattern")) { - return this.pattern; - } - - return null; - } - - @Override - public boolean canBeSubstitute() { - return this.beSubstitute; - } - - @Override - public boolean isPrioritize() { - return false; - } - - @Override - public boolean isSubstitution() { - return this.substitute; - } - - @Override - public boolean shouldCombine() { - return this.combine; - } - - @Override - public void onChangeCrafting(IAEItemStack[] newCrafting, IAEItemStack[] newOutput) { - IInventory crafting = this.getInventoryByName("crafting"); - IInventory output = this.getInventoryByName("output"); - if (crafting instanceof AppEngInternalInventory && output instanceof AppEngInternalInventory) { - for (int x = 0; x < crafting.getSizeInventory() && x < newCrafting.length; x++) { - final IAEItemStack item = newCrafting[x]; - crafting.setInventorySlotContents(x, item == null ? null : item.getItemStack()); - } - for (int x = 0; x < output.getSizeInventory() && x < newOutput.length; x++) { - final IAEItemStack item = newOutput[x]; - output.setInventorySlotContents(x, item == null ? null : item.getItemStack()); - } - } - } - - @Override - public void setCraftingRecipe(boolean craftingMode) { - this.craftingMode = craftingMode; - this.fixCraftingRecipes(); - // force update crafting mode - ((ItemBiggerAppEngInventory) this.crafting).setCraftingMode(craftingMode); - } - - @Override - public void setSubstitution(boolean canSubstitute) { - this.substitute = canSubstitute; - } - - @Override - public void setBeSubstitute(boolean canBeSubstitute) { - this.beSubstitute = canBeSubstitute; - } - - @Override - public void setCombineMode(boolean shouldCombine) { - this.combine = shouldCombine; - } - - @Override - public void setPrioritization(boolean canPrioritize) { - this.prioritize = canPrioritize; - } - - @Override - public void setInverted(boolean inverted) { - this.inverted = inverted; - } - - @Override - public int getActivePage() { - return this.activePage; - } - - @Override - public void setActivePage(int activePage) { - this.activePage = activePage; - } - - @Override - public boolean isCraftingRecipe() { - return this.craftingMode; - } - - @Override - public void sortCraftingItems() { - List items = new ArrayList<>(); - List fluids = new ArrayList<>(); - for (ItemStack is : this.crafting) { - if (is == null) continue; - if (is.getItem() instanceof ItemFluidPacket) { - fluids.add(is); - } else { - items.add(is); - } - } - if (this.prioritize) { - fluids.addAll(items); - items.clear(); - } else { - items.addAll(fluids); - fluids.clear(); - } - - for (int i = 0; i < this.crafting.getSizeInventory(); i++) { - if (this.crafting.getStackInSlot(i) == null) break; - if (items.isEmpty()) { - this.crafting.setInventorySlotContents(i, fluids.get(i)); - } else { - this.crafting.setInventorySlotContents(i, items.get(i)); - } - } - saveChanges(); - } - - @Override - public boolean isAutoFillPattern() { - return this.autoFillPattern; - } - - @Override - public void setAutoFillPattern(boolean canFill) { - this.autoFillPattern = canFill; - } - - @Override - public void saveSettings() { - super.saveSettings(); - this.writeToNBT(); - } - - @Override - public IGridNode getActionableNode() { - return this.grid; - } - -} diff --git a/src/main/java/com/glodblock/github/loader/ChannelLoader.java b/src/main/java/com/glodblock/github/loader/ChannelLoader.java index 9537fd6f..62c4652c 100644 --- a/src/main/java/com/glodblock/github/loader/ChannelLoader.java +++ b/src/main/java/com/glodblock/github/loader/ChannelLoader.java @@ -1,30 +1,18 @@ package com.glodblock.github.loader; import com.glodblock.github.FluidCraft; -import com.glodblock.github.network.CPacketCraftRequest; +import com.glodblock.github.network.CPacketCustomButtonUpdate; import com.glodblock.github.network.CPacketDumpTank; -import com.glodblock.github.network.CPacketEncodePattern; import com.glodblock.github.network.CPacketFluidPatternTermBtns; -import com.glodblock.github.network.CPacketFluidUpdate; -import com.glodblock.github.network.CPacketInventoryAction; import com.glodblock.github.network.CPacketLevelMaintainer; import com.glodblock.github.network.CPacketLevelTerminalCommands; -import com.glodblock.github.network.CPacketPatternMultiSet; -import com.glodblock.github.network.CPacketPatternValueSet; -import com.glodblock.github.network.CPacketRenamer; import com.glodblock.github.network.CPacketSwitchGuis; -import com.glodblock.github.network.CPacketTransferRecipe; import com.glodblock.github.network.CPacketValueConfig; +import com.glodblock.github.network.SPacketCustomButtonUpdate; import com.glodblock.github.network.SPacketFluidUpdate; import com.glodblock.github.network.SPacketLevelMaintainerGuiUpdate; import com.glodblock.github.network.SPacketLevelTerminalUpdate; -import com.glodblock.github.network.SPacketMEFluidInvUpdate; -import com.glodblock.github.network.SPacketMEItemInvUpdate; -import com.glodblock.github.network.SPacketPatternItemRenamer; -import com.glodblock.github.network.SPacketSetItemAmount; -import com.glodblock.github.network.SPacketStringUpdate; import com.glodblock.github.network.SPacketSuperStockReplenisherUpdate; -import com.glodblock.github.network.SPacketSwitchBack; import com.glodblock.github.network.wrapper.FCNetworkWrapper; import cpw.mods.fml.relauncher.Side; @@ -43,19 +31,7 @@ public class ChannelLoader implements Runnable { CPacketFluidPatternTermBtns.class, id++, Side.SERVER); - netHandler.registerMessage(new CPacketEncodePattern.Handler(), CPacketEncodePattern.class, id++, Side.SERVER); - netHandler - .registerMessage(new SPacketMEItemInvUpdate.Handler(), SPacketMEItemInvUpdate.class, id++, Side.CLIENT); - netHandler.registerMessage( - new SPacketMEFluidInvUpdate.Handler(), - SPacketMEFluidInvUpdate.class, - id++, - Side.CLIENT); - netHandler.registerMessage(new CPacketCraftRequest.Handler(), CPacketCraftRequest.class, id++, Side.SERVER); - netHandler - .registerMessage(new CPacketInventoryAction.Handler(), CPacketInventoryAction.class, id++, Side.SERVER); netHandler.registerMessage(new CPacketSwitchGuis.Handler(), CPacketSwitchGuis.class, id++, Side.CLIENT); - netHandler.registerMessage(new CPacketTransferRecipe.Handler(), CPacketTransferRecipe.class, id++, Side.SERVER); netHandler.registerMessage(new CPacketDumpTank.Handler(), CPacketDumpTank.class, id++, Side.SERVER); netHandler.registerMessage(new SPacketFluidUpdate.Handler(), SPacketFluidUpdate.class, id++, Side.CLIENT); netHandler.registerMessage( @@ -63,16 +39,9 @@ public class ChannelLoader implements Runnable { SPacketSuperStockReplenisherUpdate.class, id++, Side.CLIENT); - netHandler - .registerMessage(new CPacketPatternValueSet.Handler(), CPacketPatternValueSet.class, id++, Side.SERVER); netHandler.registerMessage(new CPacketValueConfig.Handler(), CPacketValueConfig.class, id++, Side.SERVER); - netHandler.registerMessage(new CPacketFluidUpdate.Handler(), CPacketFluidUpdate.class, id++, Side.SERVER); netHandler .registerMessage(new CPacketLevelMaintainer.Handler(), CPacketLevelMaintainer.class, id++, Side.SERVER); - netHandler.registerMessage(new SPacketSetItemAmount.Handler(), SPacketSetItemAmount.class, id++, Side.CLIENT); - netHandler.registerMessage(new CPacketRenamer.Handler(), CPacketRenamer.class, id++, Side.SERVER); - netHandler.registerMessage(new SPacketStringUpdate.Handler(), SPacketStringUpdate.class, id++, Side.CLIENT); - netHandler.registerMessage(new SPacketSwitchBack.Handler(), SPacketSwitchBack.class, id++, Side.CLIENT); netHandler.registerMessage( new SPacketLevelTerminalUpdate.Handler(), SPacketLevelTerminalUpdate.class, @@ -83,17 +52,20 @@ public class ChannelLoader implements Runnable { CPacketLevelTerminalCommands.class, id++, Side.SERVER); - netHandler - .registerMessage(new CPacketPatternMultiSet.Handler(), CPacketPatternMultiSet.class, id++, Side.SERVER); - netHandler.registerMessage( - new SPacketPatternItemRenamer.Handler(), - SPacketPatternItemRenamer.class, - id++, - Side.SERVER); netHandler.registerMessage( new SPacketLevelMaintainerGuiUpdate.Handler(), SPacketLevelMaintainerGuiUpdate.class, id++, Side.CLIENT); + netHandler.registerMessage( + new SPacketCustomButtonUpdate.Handler(), + SPacketCustomButtonUpdate.class, + id++, + Side.CLIENT); + netHandler.registerMessage( + new CPacketCustomButtonUpdate.Handler(), + CPacketCustomButtonUpdate.class, + id++, + Side.SERVER); } } diff --git a/src/main/java/com/glodblock/github/loader/ItemAndBlockHolder.java b/src/main/java/com/glodblock/github/loader/ItemAndBlockHolder.java index 98c9054f..6fa0f119 100644 --- a/src/main/java/com/glodblock/github/loader/ItemAndBlockHolder.java +++ b/src/main/java/com/glodblock/github/loader/ItemAndBlockHolder.java @@ -1,7 +1,5 @@ package com.glodblock.github.loader; -import static com.glodblock.github.common.storage.FluidCellInventory.singleByteAmount; - import com.glodblock.github.common.Config; import com.glodblock.github.common.block.BlockCertusQuartzTank; import com.glodblock.github.common.block.BlockFluidAutoFiller; @@ -133,7 +131,7 @@ public class ItemAndBlockHolder { 4.5).register(); public static ItemFluidExtremeStorageCell SINGULARITY_CELL = new ItemFluidExtremeStorageCell( NameConst.ITEM_SINGULARITY_FLUID_STORAGE, - Long.MAX_VALUE / (singleByteAmount * 2), + Long.MAX_VALUE / (256 * 8 * 2), 8, 1, 5).register(); diff --git a/src/main/java/com/glodblock/github/loader/KeybindLoader.java b/src/main/java/com/glodblock/github/loader/KeybindLoader.java index 81654539..ae30e7f4 100644 --- a/src/main/java/com/glodblock/github/loader/KeybindLoader.java +++ b/src/main/java/com/glodblock/github/loader/KeybindLoader.java @@ -9,7 +9,7 @@ import org.apache.commons.lang3.tuple.ImmutablePair; import org.lwjgl.input.Keyboard; import com.glodblock.github.FluidCraft; -import com.glodblock.github.common.item.ItemWirelessUltraTerminal; +import com.glodblock.github.network.CPacketSwitchGuis; import com.glodblock.github.network.CPacketValueConfig; import com.glodblock.github.util.Util; @@ -58,16 +58,9 @@ public class KeybindLoader implements Runnable { private void handleOpenTerminalKey() { if (Minecraft.getMinecraft().currentScreen != null) return; EntityClientPlayerMP player = Minecraft.getMinecraft().thePlayer; - if (player.openContainer == null) { - return; - } - - ImmutablePair term = Util.getUltraWirelessTerm(player); - if (term != null && term.getRight().getItem() instanceof ItemWirelessUltraTerminal) { - ItemWirelessUltraTerminal.switchTerminal( - player, - ((ItemWirelessUltraTerminal) term.getRight().getItem()).guiGuiType(term.getRight())); - } + ImmutablePair temp = Util.getUltraWirelessTerm(player); + if (temp == null) return; + FluidCraft.proxy.netHandler.sendToServer(new CPacketSwitchGuis(null, true)); } private void handleRestockKey() { diff --git a/src/main/java/com/glodblock/github/loader/RecipeLoader.java b/src/main/java/com/glodblock/github/loader/RecipeLoader.java index bb5198eb..681e15a1 100644 --- a/src/main/java/com/glodblock/github/loader/RecipeLoader.java +++ b/src/main/java/com/glodblock/github/loader/RecipeLoader.java @@ -51,7 +51,6 @@ import static com.glodblock.github.loader.ItemAndBlockHolder.QUANTUM_BRIDGE_CARD import static com.glodblock.github.loader.ItemAndBlockHolder.QUANTUM_CELL; import static com.glodblock.github.loader.ItemAndBlockHolder.SINGULARITY_CELL; import static com.glodblock.github.loader.ItemAndBlockHolder.WALRUS; -import static com.glodblock.github.loader.ItemAndBlockHolder.WIRELESS_FLUID_TERM; import static com.glodblock.github.loader.ItemAndBlockHolder.WIRELESS_INTERFACE_TERM; import static com.glodblock.github.loader.ItemAndBlockHolder.WIRELESS_LEVEL_TERM; import static com.glodblock.github.loader.ItemAndBlockHolder.WIRELESS_PATTERN_TERM; @@ -235,8 +234,7 @@ public class RecipeLoader implements Runnable { GameRegistry.addShapelessRecipe(FLUID_INTERFACE_P2P.stack(), AE2_P2P_ME, FLUID_INTERFACE.stack()); } GameRegistry.addShapelessRecipe(INTERFACE.stack(), FLUID_INTERFACE.stack()); - GameRegistry.addShapelessRecipe(WIRELESS_FLUID_TERM.stack(), AE2_WIRELESS_TERMINAL, BUCKET); - GameRegistry.addShapelessRecipe(WIRELESS_PATTERN_TERM.stack(), WIRELESS_FLUID_TERM, FLUID_TERMINAL); + GameRegistry.addShapelessRecipe(WIRELESS_PATTERN_TERM.stack(), FLUID_TERMINAL); GameRegistry.addShapelessRecipe(WIRELESS_INTERFACE_TERM.stack(), AE2_WIRELESS_TERMINAL, AE2_INTERFACE_TERMINAL); GameRegistry.addShapelessRecipe(WIRELESS_LEVEL_TERM.stack(), AE2_WIRELESS_TERMINAL, LEVEL_MAINTAINER); GameRegistry @@ -751,8 +749,8 @@ public class RecipeLoader implements Runnable { } public static void runTerminalRecipe() { - ItemStack[] fc2Terms = { WIRELESS_ULTRA_TERM.stack(), WIRELESS_FLUID_TERM.stack(), - WIRELESS_PATTERN_TERM.stack(), WIRELESS_INTERFACE_TERM.stack(), WIRELESS_LEVEL_TERM.stack() }; + ItemStack[] fc2Terms = { WIRELESS_ULTRA_TERM.stack(), WIRELESS_PATTERN_TERM.stack(), + WIRELESS_INTERFACE_TERM.stack(), WIRELESS_LEVEL_TERM.stack() }; for (ItemStack fc2term : fc2Terms) { if (fc2term != null) { @@ -764,8 +762,8 @@ public class RecipeLoader implements Runnable { } } - ItemStack[] term = { AE2_WIRELESS_TERMINAL, WIRELESS_FLUID_TERM.stack(), WIRELESS_PATTERN_TERM.stack(), - WIRELESS_INTERFACE_TERM.stack(), WIRELESS_LEVEL_TERM.stack(), THE_WIRELESS_TERM, WCT_WIRELESS_TERM }; + ItemStack[] term = { AE2_WIRELESS_TERMINAL, WIRELESS_PATTERN_TERM.stack(), WIRELESS_INTERFACE_TERM.stack(), + WIRELESS_LEVEL_TERM.stack(), THE_WIRELESS_TERM, WCT_WIRELESS_TERM }; GameRegistry.addShapelessRecipe( WIRELESS_ULTRA_TERM.stack(), Arrays.stream(term).filter(Objects::nonNull).toArray()); diff --git a/src/main/java/com/glodblock/github/loader/filter/FluidFilter.java b/src/main/java/com/glodblock/github/loader/filter/FluidFilter.java deleted file mode 100644 index 9f8ac6d7..00000000 --- a/src/main/java/com/glodblock/github/loader/filter/FluidFilter.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.glodblock.github.loader.filter; - -import static appeng.api.config.TypeFilter.ALL; - -import net.minecraft.item.Item; - -import com.glodblock.github.common.item.ItemFluidDrop; - -import appeng.api.config.TypeFilter; -import appeng.api.storage.data.IAEItemStack; -import appeng.api.storage.data.IAEStack; - -public class FluidFilter { - - public static boolean filter(TypeFilter typeFilter, IAEStack stack) { - if (typeFilter == ALL) return true; - if (stack instanceof IAEItemStack) { - Item item = ((IAEItemStack) stack).getItem(); - if (item != null) { - switch (typeFilter) { - case ITEMS -> { - return !(item instanceof ItemFluidDrop); - } - case FLUIDS -> { - return item instanceof ItemFluidDrop; - } - default -> {} - } - } - } - return true; - } -} diff --git a/src/main/java/com/glodblock/github/nei/AE2FC_NEIGuiHandler.java b/src/main/java/com/glodblock/github/nei/AE2FC_NEIGuiHandler.java deleted file mode 100644 index 0aaa48e4..00000000 --- a/src/main/java/com/glodblock/github/nei/AE2FC_NEIGuiHandler.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.glodblock.github.nei; - -import net.minecraft.client.gui.inventory.GuiContainer; -import net.minecraft.item.ItemStack; - -import com.glodblock.github.client.gui.GuiFluidMonitor; -import com.glodblock.github.client.gui.GuiItemMonitor; -import com.glodblock.github.client.gui.GuiLevelMaintainer; - -import codechicken.nei.api.INEIGuiAdapter; - -public class AE2FC_NEIGuiHandler extends INEIGuiAdapter { - - @Override - public boolean hideItemPanelSlot(GuiContainer gui, int x, int y, int w, int h) { - if (gui instanceof GuiItemMonitor) { - return ((GuiItemMonitor) gui).hideItemPanelSlot(x, y, w, h); - } else if (gui instanceof GuiFluidMonitor) { - return ((GuiFluidMonitor) gui).hideItemPanelSlot(x, y, w, h); - } - return false; - } - - @Override - public boolean handleDragNDrop(GuiContainer gui, int mouseX, int mouseY, ItemStack draggedStack, int button) { - if (gui instanceof GuiLevelMaintainer guiLevelMaintainer) { - return guiLevelMaintainer.handleDragNDrop(gui, mouseX, mouseY, draggedStack, button); - } - return super.handleDragNDrop(gui, mouseX, mouseY, draggedStack, button); - } -} diff --git a/src/main/java/com/glodblock/github/nei/FluidCraftingTransferHandler.java b/src/main/java/com/glodblock/github/nei/FluidCraftingTransferHandler.java deleted file mode 100644 index 65657662..00000000 --- a/src/main/java/com/glodblock/github/nei/FluidCraftingTransferHandler.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.glodblock.github.nei; - -import java.io.IOException; -import java.util.LinkedList; -import java.util.List; - -import net.minecraft.client.gui.inventory.GuiContainer; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; - -import com.glodblock.github.client.gui.GuiFluidCraftingWireless; - -import appeng.container.slot.SlotCraftingMatrix; -import appeng.container.slot.SlotFakeCraftingMatrix; -import appeng.core.sync.network.NetworkHandler; -import appeng.core.sync.packets.PacketNEIRecipe; -import appeng.util.Platform; -import codechicken.nei.PositionedStack; -import codechicken.nei.api.IOverlayHandler; -import codechicken.nei.recipe.IRecipeHandler; - -public class FluidCraftingTransferHandler implements IOverlayHandler { - - public static final FluidCraftingTransferHandler INSTANCE = new FluidCraftingTransferHandler(); - - @Override - public void overlayRecipe(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex, boolean shift) { - try { - final List ingredients = recipe.getIngredientStacks(recipeIndex); - if (firstGui instanceof GuiFluidCraftingWireless - && FluidPatternTerminalRecipeTransferHandler.craftSet.contains(recipe.getOverlayIdentifier())) { - PacketNEIRecipe packet = new PacketNEIRecipe(packIngredients(firstGui, ingredients)); - NetworkHandler.instance.sendToServer(packet); - } - } catch (final Exception | Error ignored) { - // NO-OP - } - } - - private NBTTagCompound packIngredients(GuiContainer gui, List ingredients) throws IOException { - final NBTTagCompound recipe = new NBTTagCompound(); - for (final PositionedStack positionedStack : ingredients) { - final int col = (positionedStack.relx - 25) / 18; - final int row = (positionedStack.rely - 6) / 18; - if (positionedStack.items != null && positionedStack.items.length > 0) { - for (final Object o : gui.inventorySlots.inventorySlots) { - if (o instanceof SlotCraftingMatrix || o instanceof SlotFakeCraftingMatrix) { - Slot slot = (Slot) o; - if (slot.getSlotIndex() == col + row * 3) { - final NBTTagList tags = new NBTTagList(); - final List list = new LinkedList<>(); - // prefer pure crystals. - for (int x = 0; x < positionedStack.items.length; x++) { - if (Platform.isRecipePrioritized(positionedStack.items[x])) { - list.add(0, positionedStack.items[x]); - } else { - list.add(positionedStack.items[x]); - } - } - for (final ItemStack is : list) { - final NBTTagCompound tag = new NBTTagCompound(); - is.writeToNBT(tag); - tags.appendTag(tag); - } - recipe.setTag("#" + slot.getSlotIndex(), tags); - break; - } - } - } - } - } - return recipe; - } -} diff --git a/src/main/java/com/glodblock/github/nei/FluidPatternTerminalRecipeTransferHandler.java b/src/main/java/com/glodblock/github/nei/FluidPatternTerminalRecipeTransferHandler.java deleted file mode 100644 index d13d3c7e..00000000 --- a/src/main/java/com/glodblock/github/nei/FluidPatternTerminalRecipeTransferHandler.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.glodblock.github.nei; - -import java.util.HashSet; -import java.util.List; - -import net.minecraft.client.gui.inventory.GuiContainer; - -import com.glodblock.github.FluidCraft; -import com.glodblock.github.client.gui.base.FCGuiEncodeTerminal; -import com.glodblock.github.nei.object.OrderStack; -import com.glodblock.github.nei.recipes.FluidRecipe; -import com.glodblock.github.network.CPacketTransferRecipe; - -import codechicken.nei.api.IOverlayHandler; -import codechicken.nei.recipe.IRecipeHandler; -import codechicken.nei.recipe.TemplateRecipeHandler; - -public class FluidPatternTerminalRecipeTransferHandler implements IOverlayHandler { - - public static final FluidPatternTerminalRecipeTransferHandler INSTANCE = new FluidPatternTerminalRecipeTransferHandler(); - public static final HashSet notOtherSet = new HashSet<>(); - public static final HashSet craftSet = new HashSet<>(); - - static { - notOtherSet.add("smelting"); - notOtherSet.add("brewing"); - craftSet.add("crafting"); - craftSet.add("crafting2x2"); - } - - @Override - public void overlayRecipe(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex, boolean shift) { - if (firstGui instanceof FCGuiEncodeTerminal) { - boolean priority = ((FCGuiEncodeTerminal) firstGui).container.prioritize; - List> in = FluidRecipe.getPackageInputs(recipe, recipeIndex, priority); - List> out = FluidRecipe.getPackageOutputs(recipe, recipeIndex, !notUseOther(recipe)); - boolean craft = shouldCraft(recipe); - FluidCraft.proxy.netHandler.sendToServer(new CPacketTransferRecipe(in, out, craft, shift)); - } - } - - private boolean notUseOther(IRecipeHandler recipeHandler) { - TemplateRecipeHandler tRecipe = (TemplateRecipeHandler) recipeHandler; - return notOtherSet.contains(tRecipe.getOverlayIdentifier()); - } - - private boolean shouldCraft(IRecipeHandler recipeHandler) { - TemplateRecipeHandler tRecipe = (TemplateRecipeHandler) recipeHandler; - return craftSet.contains(tRecipe.getOverlayIdentifier()); - } -} diff --git a/src/main/java/com/glodblock/github/nei/NEICellViewHandler.java b/src/main/java/com/glodblock/github/nei/NEICellViewHandler.java index a15f6f9f..85cea715 100644 --- a/src/main/java/com/glodblock/github/nei/NEICellViewHandler.java +++ b/src/main/java/com/glodblock/github/nei/NEICellViewHandler.java @@ -22,7 +22,6 @@ import net.minecraftforge.fluids.FluidStack; import org.lwjgl.opengl.GL11; import com.glodblock.github.common.item.ItemFluidDrop; -import com.glodblock.github.common.storage.FluidCellInventoryHandler; import appeng.api.AEApi; import appeng.api.config.TerminalFontSize; @@ -31,6 +30,7 @@ import appeng.api.storage.data.IAEFluidStack; import appeng.api.storage.data.IAEStack; import appeng.client.render.StackSizeRenderer; import appeng.core.localization.GuiText; +import appeng.me.storage.FluidCellInventoryHandler; import appeng.util.Platform; import appeng.util.item.FluidList; import codechicken.nei.PositionedStack; diff --git a/src/main/java/com/glodblock/github/nei/NEISearchFilter.java b/src/main/java/com/glodblock/github/nei/NEISearchFilter.java index a4c2da51..05ea3fbd 100644 --- a/src/main/java/com/glodblock/github/nei/NEISearchFilter.java +++ b/src/main/java/com/glodblock/github/nei/NEISearchFilter.java @@ -6,19 +6,17 @@ import java.util.regex.Pattern; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumChatFormatting; -import com.glodblock.github.common.storage.IFluidCellInventory; -import com.glodblock.github.common.storage.IFluidCellInventoryHandler; -import com.glodblock.github.common.storage.IStorageFluidCell; - import appeng.api.AEApi; import appeng.api.implementations.items.IStorageCell; import appeng.api.storage.ICellInventory; import appeng.api.storage.IMEInventoryHandler; import appeng.api.storage.StorageChannel; import appeng.api.storage.data.IAEFluidStack; -import appeng.api.storage.data.IAEItemStack; +import appeng.api.storage.data.IAEStack; import appeng.api.storage.data.IItemList; +import appeng.items.AEBaseCell; import appeng.me.storage.CellInventoryHandler; +import appeng.me.storage.FluidCellInventoryHandler; import appeng.util.IterationCounter; import codechicken.nei.SearchField; import codechicken.nei.SearchTokenParser; @@ -57,15 +55,15 @@ public class NEISearchFilter implements SearchTokenParser.ISearchParserProvider @Override public boolean matches(ItemStack itemStack) { - if (itemStack.getItem() instanceof IStorageFluidCell) { + if (itemStack.getItem() instanceof AEBaseCell) { final IMEInventoryHandler inventory = AEApi.instance().registries().cell() .getCellInventory(itemStack, null, StorageChannel.FLUIDS); - if (inventory instanceof final IFluidCellInventoryHandler handler) { - final IFluidCellInventory cellInventory = handler.getCellInv(); + if (inventory instanceof final FluidCellInventoryHandler handler) { + final ICellInventory cellInventory = handler.getCellInv(); if (cellInventory != null) { final ArrayList out = new ArrayList<>(); - handler.getPartitionInv().forEach(out::add); - out.addAll(cellInventory.getContents()); + //handler.getPartitionInv().forEach(out::add); + //out.addAll(cellInventory.getContents()); for (IAEFluidStack fluid : out) { boolean result = pattern.matcher(fluid.getFluidStack().getLocalizedName().toLowerCase()) .find(); @@ -82,12 +80,12 @@ public class NEISearchFilter implements SearchTokenParser.ISearchParserProvider if (inventory instanceof final CellInventoryHandler handler) { final ICellInventory cellInventory = handler.getCellInv(); if (cellInventory != null) { - final IItemList out = AEApi.instance().storage().createItemFilterList(); - for (IAEItemStack item : handler.getPartitionList().getItems()) - out.add(item); + final IItemList> out = AEApi.instance().storage().createAEStackList(); + for (Object item : handler.getPartitionList().getItems()) + out.add((IAEStack) item); cellInventory.getAvailableItems(out, IterationCounter.fetchNewId()); - for ( IAEItemStack item : out) { - boolean result = pattern.matcher(item.getItemStack().getDisplayName().toLowerCase()) + for (IAEStack item : out) { + boolean result = pattern.matcher(item.getDisplayName().toLowerCase()) .find(); if (result) return true; } diff --git a/src/main/java/com/glodblock/github/nei/NEI_FC_Config.java b/src/main/java/com/glodblock/github/nei/NEI_FC_Config.java deleted file mode 100644 index 1a586139..00000000 --- a/src/main/java/com/glodblock/github/nei/NEI_FC_Config.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.glodblock.github.nei; - -import com.glodblock.github.FluidCraft; -import com.glodblock.github.client.gui.GuiFluidCraftingWireless; -import com.glodblock.github.client.gui.GuiFluidPatternExWireless; -import com.glodblock.github.client.gui.GuiFluidPatternTerminal; -import com.glodblock.github.client.gui.GuiFluidPatternTerminalEx; -import com.glodblock.github.client.gui.GuiFluidPatternWireless; -import com.glodblock.github.nei.recipes.FluidRecipe; -import com.glodblock.github.util.ModAndClassUtil; - -import codechicken.nei.api.API; -import codechicken.nei.api.IConfigureNEI; - -@SuppressWarnings("unused") -public class NEI_FC_Config implements IConfigureNEI { - - @Override - public void loadConfig() { - API.registerNEIGuiHandler(new AE2FC_NEIGuiHandler()); - API.addSearchProvider(new NEISearchFilter()); - API.registerStackStringifyHandler(new FCStackStringifyHandler()); - API.registerUsageHandler(new NEICellViewHandler()); - - if (ModAndClassUtil.AVARITIA) { - API.registerGuiOverlay(GuiFluidPatternWireless.class, "extreme", null); - API.registerGuiOverlay(GuiFluidPatternExWireless.class, "extreme", null); - API.registerGuiOverlay(GuiFluidPatternTerminal.class, "extreme", null); - API.registerGuiOverlay(GuiFluidPatternTerminalEx.class, "extreme", null); - } - - for (String identifier : FluidRecipe.getSupportRecipes()) { - // that NEE handlers take priority - if (!API.hasGuiOverlayHandler(GuiFluidCraftingWireless.class, identifier)) { - API.registerGuiOverlayHandler( - GuiFluidCraftingWireless.class, - FluidCraftingTransferHandler.INSTANCE, - identifier); - } - if (!API.hasGuiOverlayHandler(GuiFluidPatternWireless.class, identifier)) { - API.registerGuiOverlayHandler( - GuiFluidPatternWireless.class, - FluidPatternTerminalRecipeTransferHandler.INSTANCE, - identifier); - } - if (!API.hasGuiOverlayHandler(GuiFluidPatternExWireless.class, identifier)) { - API.registerGuiOverlayHandler( - GuiFluidPatternExWireless.class, - FluidPatternTerminalRecipeTransferHandler.INSTANCE, - identifier); - } - if (!API.hasGuiOverlayHandler(GuiFluidPatternTerminal.class, identifier)) { - API.registerGuiOverlayHandler( - GuiFluidPatternTerminal.class, - FluidPatternTerminalRecipeTransferHandler.INSTANCE, - identifier); - } - if (!API.hasGuiOverlayHandler(GuiFluidPatternTerminalEx.class, identifier)) { - API.registerGuiOverlayHandler( - GuiFluidPatternTerminalEx.class, - FluidPatternTerminalRecipeTransferHandler.INSTANCE, - identifier); - } - } - } - - @Override - public String getName() { - return FluidCraft.MODNAME; - } - - @Override - public String getVersion() { - return FluidCraft.VERSION; - } -} diff --git a/src/main/java/com/glodblock/github/network/CPacketCraftRequest.java b/src/main/java/com/glodblock/github/network/CPacketCraftRequest.java deleted file mode 100644 index 3805757d..00000000 --- a/src/main/java/com/glodblock/github/network/CPacketCraftRequest.java +++ /dev/null @@ -1,145 +0,0 @@ -package com.glodblock.github.network; - -import java.util.Objects; -import java.util.concurrent.Future; - -import javax.annotation.Nullable; - -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.tileentity.TileEntity; -import net.minecraftforge.common.util.ForgeDirection; - -import com.glodblock.github.inventory.InventoryHandler; -import com.glodblock.github.inventory.gui.GuiType; -import com.glodblock.github.inventory.item.IWirelessTerminal; -import com.glodblock.github.util.BlockPos; - -import appeng.api.config.CraftingMode; -import appeng.api.networking.IGrid; -import appeng.api.networking.IGridHost; -import appeng.api.networking.IGridNode; -import appeng.api.networking.crafting.ICraftingGrid; -import appeng.api.networking.crafting.ICraftingJob; -import appeng.container.ContainerOpenContext; -import appeng.container.implementations.ContainerCraftAmount; -import appeng.container.implementations.ContainerCraftConfirm; -import appeng.core.AELog; -import appeng.me.cache.CraftingGridCache; -import cpw.mods.fml.common.network.simpleimpl.IMessage; -import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; -import cpw.mods.fml.common.network.simpleimpl.MessageContext; -import io.netty.buffer.ByteBuf; - -public class CPacketCraftRequest implements IMessage { - - private long amount; - private boolean heldShift; - - private CraftingMode craftingMode; - - public CPacketCraftRequest() {} - - public CPacketCraftRequest(final int craftAmt, final boolean shift) { - this(craftAmt, shift, CraftingMode.STANDARD); - } - - public CPacketCraftRequest(final int craftAmt, final boolean shift, final CraftingMode craftingMode) { - amount = craftAmt; - heldShift = shift; - this.craftingMode = craftingMode; - } - - @Override - public void toBytes(ByteBuf buf) { - buf.writeLong(amount); - buf.writeBoolean(heldShift); - buf.writeBoolean(this.craftingMode == CraftingMode.STANDARD); - } - - @Override - public void fromBytes(ByteBuf buf) { - amount = buf.readLong(); - heldShift = buf.readBoolean(); - craftingMode = buf.readBoolean() ? CraftingMode.STANDARD : CraftingMode.IGNORE_MISSING; - } - - public static class Handler implements IMessageHandler { - - @Nullable - @Override - public IMessage onMessage(CPacketCraftRequest message, MessageContext ctx) { - if (ctx.getServerHandler().playerEntity.openContainer instanceof final ContainerCraftAmount cca) { - EntityPlayerMP player = ctx.getServerHandler().playerEntity; - final Object target = cca.getTarget(); - if (target instanceof final IGridHost gh) { - final IGridNode gn = gh.getGridNode(ForgeDirection.UNKNOWN); - - if (gn == null) { - return null; - } - - final IGrid g = gn.getGrid(); - if (g == null || cca.getItemToCraft() == null) { - return null; - } - - cca.getItemToCraft().setStackSize(message.amount); - - Future futureJob = null; - try { - final ICraftingGrid cg = g.getCache(ICraftingGrid.class); - if(cg instanceof CraftingGridCache cgc) { - futureJob = cgc.beginCraftingJob( - cca.getWorld(), - cca.getGrid(), - cca.getActionSrc(), - cca.getItemToCraft(), - message.craftingMode, - null); - }else { - futureJob = cg.beginCraftingJob( - cca.getWorld(), - cca.getGrid(), - cca.getActionSrc(), - cca.getItemToCraft(), - null); - } - - final ContainerOpenContext context = cca.getOpenContext(); - if (context != null) { - final TileEntity te = context.getTile(); - if (te != null) { - InventoryHandler.openGui( - player, - player.worldObj, - new BlockPos(te), - Objects.requireNonNull(context.getSide()), - GuiType.FLUID_CRAFTING_CONFIRM); - } else if (target instanceof IWirelessTerminal) { - InventoryHandler.openGui( - player, - player.worldObj, - new BlockPos(((IWirelessTerminal) target).getInventorySlot(), 0, 0), - Objects.requireNonNull(context.getSide()), - GuiType.FLUID_CRAFTING_CONFIRM_ITEM); - } - - if (player.openContainer instanceof final ContainerCraftConfirm ccc) { - ccc.setItemToCraft(cca.getItemToCraft()); - ccc.setAutoStart(message.heldShift); - ccc.setJob(futureJob); - cca.detectAndSendChanges(); - } - } - } catch (final Throwable e) { - if (futureJob != null) { - futureJob.cancel(true); - } - AELog.debug(e); - } - } - } - return null; - } - } -} diff --git a/src/main/java/com/glodblock/github/network/CPacketCustomButtonUpdate.java b/src/main/java/com/glodblock/github/network/CPacketCustomButtonUpdate.java new file mode 100644 index 00000000..c640eff9 --- /dev/null +++ b/src/main/java/com/glodblock/github/network/CPacketCustomButtonUpdate.java @@ -0,0 +1,45 @@ +package com.glodblock.github.network; + +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.inventory.Container; + +import com.glodblock.github.FluidCraft; +import com.glodblock.github.client.FluidInterfaceButtons; +import com.glodblock.github.common.tile.TileFluidInterface; + +import appeng.api.config.Settings; +import appeng.api.config.SidelessMode; +import appeng.container.AEBaseContainer; +import cpw.mods.fml.common.network.simpleimpl.IMessage; +import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; +import cpw.mods.fml.common.network.simpleimpl.MessageContext; +import io.netty.buffer.ByteBuf; + +public class CPacketCustomButtonUpdate implements IMessage { + + public CPacketCustomButtonUpdate() {} + + @Override + public void fromBytes(ByteBuf buf) {} + + @Override + public void toBytes(ByteBuf buf) {} + + public static class Handler implements IMessageHandler { + + @Override + public IMessage onMessage(CPacketCustomButtonUpdate message, MessageContext ctx) { + final Container c = ctx.getServerHandler().playerEntity.openContainer; + final EntityPlayerMP player = ctx.getServerHandler().playerEntity; + + if (c instanceof AEBaseContainer abc && abc.getTarget() instanceof TileFluidInterface tfi) { + if (tfi.getDataObject() instanceof FluidInterfaceButtons fib) { + fib.setSidelessMode((SidelessMode) tfi.getConfigManager().getSetting(Settings.SIDELESS_MODE)); + FluidCraft.proxy.netHandler.sendTo(new SPacketCustomButtonUpdate(fib), player); + } + } + + return null; + } + } +} diff --git a/src/main/java/com/glodblock/github/network/CPacketEncodePattern.java b/src/main/java/com/glodblock/github/network/CPacketEncodePattern.java deleted file mode 100644 index 8d0882c5..00000000 --- a/src/main/java/com/glodblock/github/network/CPacketEncodePattern.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.glodblock.github.network; - -import javax.annotation.Nullable; - -import net.minecraft.entity.player.EntityPlayerMP; - -import com.glodblock.github.client.gui.container.ContainerFluidPatternEncoder; - -import cpw.mods.fml.common.network.simpleimpl.IMessage; -import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; -import cpw.mods.fml.common.network.simpleimpl.MessageContext; -import io.netty.buffer.ByteBuf; - -public class CPacketEncodePattern implements IMessage { - - @Override - public void toBytes(ByteBuf buf) { - // NO-OP - } - - @Override - public void fromBytes(ByteBuf buf) { - // NO-OP - } - - public static class Handler implements IMessageHandler { - - @Nullable - @Override - public IMessage onMessage(CPacketEncodePattern message, MessageContext ctx) { - EntityPlayerMP player = ctx.getServerHandler().playerEntity; - if (player.openContainer instanceof ContainerFluidPatternEncoder) { - ((ContainerFluidPatternEncoder) player.openContainer).encodePattern(); - } - return null; - } - } -} diff --git a/src/main/java/com/glodblock/github/network/CPacketFluidPatternTermBtns.java b/src/main/java/com/glodblock/github/network/CPacketFluidPatternTermBtns.java index 98a49ad8..e231b96c 100644 --- a/src/main/java/com/glodblock/github/network/CPacketFluidPatternTermBtns.java +++ b/src/main/java/com/glodblock/github/network/CPacketFluidPatternTermBtns.java @@ -1,21 +1,23 @@ package com.glodblock.github.network; -import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.inventory.Container; import net.minecraftforge.common.util.ForgeDirection; -import com.glodblock.github.client.gui.container.ContainerFluidStorageBus; -import com.glodblock.github.client.gui.container.base.FCBaseContainer; -import com.glodblock.github.client.gui.container.base.FCContainerEncodeTerminal; +import com.glodblock.github.FluidCraft; +import com.glodblock.github.client.UltraTerminalButtons; +import com.glodblock.github.client.gui.container.ContainerMagnetFilter; import com.glodblock.github.inventory.InventoryHandler; import com.glodblock.github.inventory.gui.GuiType; -import com.glodblock.github.inventory.item.IItemTerminal; -import com.glodblock.github.inventory.item.IWirelessExtendCard; import com.glodblock.github.inventory.item.IWirelessMagnetFilter; -import com.glodblock.github.inventory.item.WirelessMagnet; import com.glodblock.github.util.BlockPos; import com.glodblock.github.util.Util; +import appeng.container.AEBaseContainer; +import appeng.container.PrimaryGui; +import appeng.container.interfaces.IContainerSubGui; +import appeng.container.interfaces.IInventorySlotAware; +import appeng.helpers.ICustomButtonProvider; import cpw.mods.fml.common.network.simpleimpl.IMessage; import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; import cpw.mods.fml.common.network.simpleimpl.MessageContext; @@ -23,21 +25,34 @@ import io.netty.buffer.ByteBuf; public class CPacketFluidPatternTermBtns implements IMessage { - private String Name = ""; - private String Value = ""; + private Command command; + private String value = ""; - public CPacketFluidPatternTermBtns(final String name, final String value) { - Name = name; - Value = value; + public enum Command { + RESTOCK, + MAGNET_MODE, + MAGNET_OPEN_FILTER, + MAGNET_FILTER_NBT, + MAGNET_FILTER_META, + MAGNET_FILTER_ORE, + MAGNET_FILTER_OREDICT_STATE, + MAGNET_FILTER_OREDICT_FILTER, + MAGNET_FILTER_MODE, + MAGNET_FILTER_CLEAR } - public CPacketFluidPatternTermBtns(final String name, final Integer value) { - Name = name; - Value = value.toString(); + public CPacketFluidPatternTermBtns(final Command command, final String value) { + this.command = command; + this.value = value; } - public CPacketFluidPatternTermBtns(final String name, final boolean value) { - this(name, value ? 1 : 0); + public CPacketFluidPatternTermBtns(final Command command, final Integer value) { + this.command = command; + this.value = value.toString(); + } + + public CPacketFluidPatternTermBtns(final Command command, final boolean value) { + this(command, value ? 1 : 0); } public CPacketFluidPatternTermBtns() { @@ -46,29 +61,23 @@ public class CPacketFluidPatternTermBtns implements IMessage { @Override public void fromBytes(ByteBuf buf) { - int leName = buf.readInt(); + this.command = Command.values()[buf.readInt()]; + int leVal = buf.readInt(); StringBuilder sb = new StringBuilder(); - for (int i = 0; i < leName; i++) { - sb.append(buf.readChar()); - } - Name = sb.toString(); - sb = new StringBuilder(); for (int i = 0; i < leVal; i++) { sb.append(buf.readChar()); } - Value = sb.toString(); + this.value = sb.toString(); } @Override public void toBytes(ByteBuf buf) { - buf.writeInt(Name.length()); - buf.writeInt(Value.length()); - for (int i = 0; i < Name.length(); i++) { - buf.writeChar(Name.charAt(i)); - } - for (int i = 0; i < Value.length(); i++) { - buf.writeChar(Value.charAt(i)); + buf.writeInt(this.command.ordinal()); + + buf.writeInt(this.value.length()); + for (int i = 0; i < this.value.length(); i++) { + buf.writeChar(this.value.charAt(i)); } } @@ -76,93 +85,62 @@ public class CPacketFluidPatternTermBtns implements IMessage { @Override public IMessage onMessage(CPacketFluidPatternTermBtns message, MessageContext ctx) { - String Name = message.Name; - String Value = message.Value; + final Command command = message.command; + final String value = message.value; final Container c = ctx.getServerHandler().playerEntity.openContainer; - final EntityPlayer player = ctx.getServerHandler().playerEntity; - if (Name.startsWith("WirelessTerminal.") && (c instanceof FCBaseContainer)) { - final FCBaseContainer cpt = (FCBaseContainer) c; - final IItemTerminal itemTerminal = (IItemTerminal) cpt.getHost(); - final IWirelessExtendCard iwt = (IWirelessExtendCard) itemTerminal; - switch (Name) { - case "WirelessTerminal.Stock": - iwt.setRestock(!iwt.isRestock()); - break; - case "WirelessTerminal.MagnetMode": - iwt.setMagnetCardNextMode(); - break; - case "WirelessTerminal.OpenMagnet": + final EntityPlayerMP player = ctx.getServerHandler().playerEntity; + + if (c instanceof ContainerMagnetFilter cmf && cmf.getTarget() instanceof IWirelessMagnetFilter iwmf) { + switch (command) { + case MAGNET_FILTER_NBT -> iwmf.setNBTMode(value.equals("1")); + case MAGNET_FILTER_META -> iwmf.setMetaMode(value.equals("1")); + case MAGNET_FILTER_ORE -> iwmf.setOreMode(value.equals("1")); + case MAGNET_FILTER_OREDICT_STATE -> iwmf.setOreDictMode(value.equals("1")); + case MAGNET_FILTER_OREDICT_FILTER -> iwmf.setOreDictFilter(value); + case MAGNET_FILTER_MODE -> iwmf.setListMode(value.equals("1")); + case MAGNET_FILTER_CLEAR -> iwmf.clearConfig(); + } + iwmf.saveSettings(); + } else if (c instanceof AEBaseContainer abc && abc.getTarget() instanceof ICustomButtonProvider icbp) { + + switch (command) { + case RESTOCK -> { + if (icbp.getDataObject() instanceof UltraTerminalButtons utb) { + utb.toggleRestock(); + } + } + case MAGNET_MODE -> { + if (icbp.getDataObject() instanceof UltraTerminalButtons utb) { + utb.toggleMagnetMode(); + } + } + case MAGNET_OPEN_FILTER -> { + final PrimaryGui pGui = abc.getPrimaryGui(); + final int nextGui = abc.getSwitchAbleGuiNext(); + InventoryHandler.openGui( - player, - player.worldObj, - new BlockPos( - cpt.getPortableCell().getInventorySlot(), - Util.GuiHelper.encodeType(0, Util.GuiHelper.GuiType.ITEM), - -1), - ForgeDirection.UNKNOWN, - GuiType.WIRELESS_MAGNET_FILTER); - break; - case "WirelessTerminal.magnet.NBT": - ((IWirelessMagnetFilter) itemTerminal).setNBTMode(Value.equals("1")); - break; - case "WirelessTerminal.magnet.Meta": - ((IWirelessMagnetFilter) itemTerminal).setMetaMode(Value.equals("1")); - break; - case "WirelessTerminal.magnet.Ore": - ((IWirelessMagnetFilter) itemTerminal).setOreMode(Value.equals("1")); - break; - case "WirelessTerminal.magnet.OreDictState": - ((IWirelessMagnetFilter) itemTerminal).setOreDictMode(Value.equals("1")); - break; - case "WirelessTerminal.magnet.OreDictFilter": - ((IWirelessMagnetFilter) itemTerminal).setOreDictFilter(Value); - break; - case "WirelessTerminal.magnet.FilterMode": - ((IWirelessMagnetFilter) itemTerminal).setListMode( - Value.equals("1") ? WirelessMagnet.ListMode.WhiteList - : WirelessMagnet.ListMode.BlackList); - break; - case "WirelessTerminal.magnet.clear": - ((IWirelessMagnetFilter) itemTerminal).clearConfig(); - break; - } - itemTerminal.saveSettings(); - } else if (Name.startsWith("PatternTerminal.") && (c instanceof final FCContainerEncodeTerminal cpt)) { - switch (Name) { - case "PatternTerminal.CraftMode" -> cpt.getPatternTerminal().setCraftingRecipe(Value.equals("1")); - case "PatternTerminal.Encode" -> { - switch (Value) { - case "0" -> cpt.encode(); - case "1" -> cpt.encodeAndMoveToInventory(); - case "3" -> cpt.encodeAllItemAndMoveToInventory(); + player, + player.worldObj, + new BlockPos( + ((IInventorySlotAware) abc.getTarget()).getInventorySlot(), + Util.GuiHelper.encodeType(0, Util.GuiHelper.GuiType.ITEM), + -1), + ForgeDirection.UNKNOWN, + GuiType.WIRELESS_MAGNET_FILTER); + + if (player.openContainer instanceof IContainerSubGui sg) { + sg.setPrimaryGui(pGui); + } + + if (player.openContainer instanceof AEBaseContainer ab) { + ab.setSwitchAbleGuiNext(nextGui); } } - case "PatternTerminal.Clear" -> cpt.clear(); - case "PatternTerminal.Substitute" -> cpt.getPatternTerminal().setSubstitution(Value.equals("1")); - case "PatternTerminal.Invert" -> cpt.getPatternTerminal().setInverted(Value.equals("1")); - case "PatternTerminal.Double" -> cpt.doubleStacks(Integer.parseInt(message.Value)); - case "PatternTerminal.Combine" -> cpt.getPatternTerminal().setCombineMode(Value.equals("1")); - case "PatternTerminal.beSubstitute" -> cpt.getPatternTerminal().setBeSubstitute(Value.equals("1")); - case "PatternTerminal.ActivePage" -> - cpt.getPatternTerminal().setActivePage(Integer.parseInt(Value)); - case "PatternTerminal.Prioritize" -> { - switch (Value) { - case "0", "1" -> cpt.getPatternTerminal().setPrioritization(Value.equals("1")); - case "2" -> cpt.getPatternTerminal().sortCraftingItems(); - } - } - case "PatternTerminal.AutoFillerPattern" -> - cpt.getPatternTerminal().setAutoFillPattern(Value.equals("1")); - } - cpt.getPatternTerminal().saveSettings(); - } else if (Name.startsWith("StorageBus.") && c instanceof ContainerFluidStorageBus ccw) { - if (Name.equals("StorageBus.Action")) { - if (Value.equals("Partition")) { - ccw.partition(); - } else if (Value.equals("Clear")) { - ccw.clear(); - } } + + icbp.writeCustomButtonData(); + + FluidCraft.proxy.netHandler.sendTo(new SPacketCustomButtonUpdate(icbp.getDataObject()), player); } return null; } diff --git a/src/main/java/com/glodblock/github/network/CPacketFluidUpdate.java b/src/main/java/com/glodblock/github/network/CPacketFluidUpdate.java deleted file mode 100644 index 6461e24e..00000000 --- a/src/main/java/com/glodblock/github/network/CPacketFluidUpdate.java +++ /dev/null @@ -1,88 +0,0 @@ -package com.glodblock.github.network; - -import java.io.IOException; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.Container; - -import com.glodblock.github.client.gui.container.ContainerFluidMonitor; - -import appeng.api.storage.data.IAEFluidStack; -import appeng.util.item.AEFluidStack; -import cpw.mods.fml.common.network.simpleimpl.IMessage; -import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; -import cpw.mods.fml.common.network.simpleimpl.MessageContext; -import io.netty.buffer.ByteBuf; - -public class CPacketFluidUpdate implements IMessage { - - private IAEFluidStack fluid; - private boolean shift; - private int slotIndex; - - public CPacketFluidUpdate() {} - - /** - * Used by transferStackInSlot. No clicked fluid, always shift. - */ - public CPacketFluidUpdate(int slotIndex) { - this(null, slotIndex, true); - } - - /** - * Used by handleMouseClick. Always uses mouse stack. - */ - public CPacketFluidUpdate(IAEFluidStack fluid, boolean shift) { - this(fluid, -1, shift); - } - - private CPacketFluidUpdate(IAEFluidStack fluid, int slotIndex, boolean shift) { - this.fluid = fluid; - this.slotIndex = slotIndex; - this.shift = shift; - } - - @Override - public void fromBytes(ByteBuf buf) { - try { - if (buf.readBoolean()) { - this.fluid = AEFluidStack.loadFluidStackFromPacket(buf); - } else { - this.fluid = null; - } - this.slotIndex = buf.readInt(); - this.shift = buf.readBoolean(); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public void toBytes(ByteBuf buf) { - try { - if (fluid == null) { - buf.writeBoolean(false); - } else { - buf.writeBoolean(true); - fluid.writeToPacket(buf); - } - buf.writeInt(this.slotIndex); - buf.writeBoolean(this.shift); - } catch (IOException e) { - e.printStackTrace(); - } - } - - public static class Handler implements IMessageHandler { - - @Override - public IMessage onMessage(CPacketFluidUpdate message, MessageContext ctx) { - Container container = ctx.getServerHandler().playerEntity.openContainer; - EntityPlayer player = ctx.getServerHandler().playerEntity; - if (container instanceof ContainerFluidMonitor) { - ((ContainerFluidMonitor) container).postChange(message.fluid, player, message.slotIndex, message.shift); - } - return null; - } - } -} diff --git a/src/main/java/com/glodblock/github/network/CPacketInventoryAction.java b/src/main/java/com/glodblock/github/network/CPacketInventoryAction.java deleted file mode 100644 index 9fdbe73f..00000000 --- a/src/main/java/com/glodblock/github/network/CPacketInventoryAction.java +++ /dev/null @@ -1,240 +0,0 @@ -package com.glodblock.github.network; - -import java.io.IOException; -import java.util.Objects; - -import javax.annotation.Nullable; - -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.tileentity.TileEntity; -import net.minecraftforge.common.util.ForgeDirection; -import net.minecraftforge.fluids.FluidStack; - -import com.glodblock.github.FluidCraft; -import com.glodblock.github.client.gui.container.ContainerPatternMulti; -import com.glodblock.github.client.gui.container.ContainerPatternValueAmount; -import com.glodblock.github.common.item.ItemFluidPacket; -import com.glodblock.github.inventory.InventoryHandler; -import com.glodblock.github.inventory.gui.GuiType; -import com.glodblock.github.inventory.item.IWirelessTerminal; -import com.glodblock.github.util.BlockPos; -import com.glodblock.github.util.Util; - -import appeng.api.storage.data.IAEItemStack; -import appeng.container.AEBaseContainer; -import appeng.container.ContainerOpenContext; -import appeng.container.implementations.ContainerCraftAmount; -import appeng.container.implementations.ContainerPatternItemRenamer; -import appeng.helpers.InventoryAction; -import appeng.tile.networking.TileCableBus; -import appeng.util.item.AEItemStack; -import cpw.mods.fml.common.network.simpleimpl.IMessage; -import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; -import cpw.mods.fml.common.network.simpleimpl.MessageContext; -import io.netty.buffer.ByteBuf; - -public class CPacketInventoryAction implements IMessage { - - private InventoryAction action; - private int slot; - private long id; - private IAEItemStack stack; - private boolean isEmpty; - - public CPacketInventoryAction() {} - - public CPacketInventoryAction(final InventoryAction action, final int slot, final long id) { - this.action = action; - this.slot = slot; - this.id = id; - this.stack = null; - this.isEmpty = true; - } - - public CPacketInventoryAction(final InventoryAction action, final int slot, final long id, IAEItemStack stack) { - this.action = action; - this.slot = slot; - this.id = id; - this.stack = stack; - this.isEmpty = stack == null; - } - - @Override - public void toBytes(ByteBuf buf) { - buf.writeInt(action.ordinal()); - buf.writeInt(slot); - buf.writeLong(id); - buf.writeBoolean(isEmpty); - if (!isEmpty) { - try { - stack.writeToPacket(buf); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - - @Override - public void fromBytes(ByteBuf buf) { - action = InventoryAction.values()[buf.readInt()]; - slot = buf.readInt(); - id = buf.readLong(); - isEmpty = buf.readBoolean(); - if (!isEmpty) { - try { - stack = AEItemStack.loadItemStackFromPacket(buf); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - - public static class Handler implements IMessageHandler { - - @Nullable - @Override - public IMessage onMessage(CPacketInventoryAction message, MessageContext ctx) { - final EntityPlayerMP sender = ctx.getServerHandler().playerEntity; - if (sender.openContainer instanceof final AEBaseContainer baseContainer) { - Object target = baseContainer.getTarget(); - if (message.action == InventoryAction.AUTO_CRAFT) { - final ContainerOpenContext context = baseContainer.getOpenContext(); - if (context != null) { - final TileEntity te = context.getTile(); - if (te != null) { - InventoryHandler.openGui( - sender, - te.getWorldObj(), - new BlockPos(te), - Objects.requireNonNull(baseContainer.getOpenContext().getSide()), - GuiType.FLUID_CRAFTING_AMOUNT); - } else if (target instanceof IWirelessTerminal wt) { - InventoryHandler.openGui( - sender, - sender.worldObj, - new BlockPos( - wt.getInventorySlot(), - Util.GuiHelper.encodeType(0, Util.GuiHelper.GuiType.ITEM), - 0), - ForgeDirection.UNKNOWN, - GuiType.FLUID_CRAFTING_AMOUNT); - } - if (sender.openContainer instanceof final ContainerCraftAmount cca) { - if (baseContainer.getTargetStack() != null) { - cca.getCraftingItem().putStack(baseContainer.getTargetStack().getItemStack()); - cca.setItemToCraft(baseContainer.getTargetStack()); - if (message.id > 0) { - cca.setInitialCraftAmount(message.id); - } - } - cca.detectAndSendChanges(); - } - } - } else if (message.action == InventoryAction.SET_PATTERN_VALUE) { - final ContainerOpenContext context = baseContainer.getOpenContext(); - if (context != null && message.stack != null) { - final TileEntity te = context.getTile(); - if (te != null) { - if (te instanceof TileCableBus) { - InventoryHandler.openGui( - sender, - te.getWorldObj(), - new BlockPos(te), - Objects.requireNonNull(baseContainer.getOpenContext().getSide()), - GuiType.PATTERN_VALUE_SET); - } else { - InventoryHandler.openGui( - sender, - te.getWorldObj(), - new BlockPos(te), - Objects.requireNonNull(baseContainer.getOpenContext().getSide()), - GuiType.PATTERN_VALUE_SET_TILE); - } - } else if (target instanceof IWirelessTerminal wt) { - InventoryHandler.openGui( - sender, - sender.worldObj, - new BlockPos( - wt.getInventorySlot(), - Util.GuiHelper.encodeType(0, Util.GuiHelper.GuiType.ITEM), - 0), - ForgeDirection.UNKNOWN, - GuiType.PATTERN_VALUE_SET); - } - int amt = (int) message.stack.getStackSize(); - if (message.stack.getItem() instanceof ItemFluidPacket) { - FluidStack fluid = ItemFluidPacket.getFluidStack(message.stack); - amt = fluid == null ? 1 : fluid.amount; - } - FluidCraft.proxy.netHandler.sendTo(new SPacketSetItemAmount(amt), sender); - if (sender.openContainer instanceof final ContainerPatternValueAmount cpv) { - if (baseContainer.getTargetStack() != null) { - cpv.setValueIndex(message.slot); - cpv.getPatternValue().putStack(baseContainer.getTargetStack().getItemStack()); - } - cpv.detectAndSendChanges(); - } - } - } else if (message.action == InventoryAction.SET_PATTERN_MULTI) { - final ContainerOpenContext context = baseContainer.getOpenContext(); - if (context != null) { - final TileEntity te = context.getTile(); - if (te != null) { - InventoryHandler.openGui( - sender, - te.getWorldObj(), - new BlockPos(te), - Objects.requireNonNull(baseContainer.getOpenContext().getSide()), - GuiType.GUI_PATTERN_MULTI); - } else if (target instanceof IWirelessTerminal wt) { - InventoryHandler.openGui( - sender, - sender.worldObj, - new BlockPos( - wt.getInventorySlot(), - Util.GuiHelper.encodeType(0, Util.GuiHelper.GuiType.ITEM), - 0), - ForgeDirection.UNKNOWN, - GuiType.GUI_PATTERN_MULTI); - } - if (sender.openContainer instanceof ContainerPatternMulti cpm) { - cpm.detectAndSendChanges(); - } - } - } else if (message.action == InventoryAction.RENAME_PATTERN_ITEM) { - final ContainerOpenContext context = baseContainer.getOpenContext(); - if (context != null) { - final TileEntity te = context.getTile(); - if (te != null) { - InventoryHandler.openGui( - sender, - te.getWorldObj(), - new BlockPos(te), - Objects.requireNonNull(baseContainer.getOpenContext().getSide()), - GuiType.GUI_PATTERN_ITEM_RENAMER); - } else if (target instanceof IWirelessTerminal wt) { - InventoryHandler.openGui( - sender, - sender.worldObj, - new BlockPos( - wt.getInventorySlot(), - Util.GuiHelper.encodeType(0, Util.GuiHelper.GuiType.ITEM), - 0), - ForgeDirection.UNKNOWN, - GuiType.GUI_PATTERN_ITEM_RENAMER); - } - if (sender.openContainer instanceof ContainerPatternItemRenamer cpir) { - if (baseContainer.getTargetStack() != null) { - cpir.getPatternValue().putStack(baseContainer.getTargetStack().getItemStack()); - } - cpir.detectAndSendChanges(); - } - } - }else { - baseContainer.doAction(sender, message.action, message.slot, message.id); - } - } - return null; - } - } -} diff --git a/src/main/java/com/glodblock/github/network/CPacketLevelTerminalCommands.java b/src/main/java/com/glodblock/github/network/CPacketLevelTerminalCommands.java index 3848122d..2331f0db 100644 --- a/src/main/java/com/glodblock/github/network/CPacketLevelTerminalCommands.java +++ b/src/main/java/com/glodblock/github/network/CPacketLevelTerminalCommands.java @@ -1,18 +1,24 @@ package com.glodblock.github.network; +import java.util.Objects; + import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.DimensionManager; import net.minecraftforge.common.util.ForgeDirection; -import com.glodblock.github.common.parts.PartFluidLevelEmitter; import com.glodblock.github.inventory.InventoryHandler; import com.glodblock.github.inventory.gui.GuiType; import com.glodblock.github.util.BlockPos; +import appeng.api.parts.ILevelEmitter; import appeng.api.parts.IPart; import appeng.api.parts.IPartHost; -import appeng.parts.automation.PartLevelEmitter; +import appeng.container.AEBaseContainer; +import appeng.container.PrimaryGui; +import appeng.container.interfaces.IContainerSubGui; +import appeng.core.sync.GuiBridge; +import appeng.util.Platform; import cpw.mods.fml.common.network.simpleimpl.IMessage; import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; import cpw.mods.fml.common.network.simpleimpl.MessageContext; @@ -35,6 +41,7 @@ public class CPacketLevelTerminalCommands implements IMessage { DISABLE, ENABLE_ALL, DISABLE_ALL, + RENAME } public CPacketLevelTerminalCommands() {} @@ -57,7 +64,7 @@ public class CPacketLevelTerminalCommands implements IMessage { public void fromBytes(ByteBuf buf) { action = Action.values()[buf.readInt()]; switch (action) { - case EDIT -> { + case EDIT, RENAME -> { x = buf.readInt(); y = buf.readInt(); z = buf.readInt(); @@ -83,7 +90,7 @@ public class CPacketLevelTerminalCommands implements IMessage { public void toBytes(ByteBuf buf) { buf.writeInt(action.ordinal()); switch (action) { - case EDIT -> { + case EDIT, RENAME -> { buf.writeInt(x); buf.writeInt(y); buf.writeInt(z); @@ -110,30 +117,25 @@ public class CPacketLevelTerminalCommands implements IMessage { @Override public IMessage onMessage(CPacketLevelTerminalCommands message, MessageContext ctx) { EntityPlayerMP player = ctx.getServerHandler().playerEntity; - switch (message.action) { - case EDIT -> { + + if (Objects.requireNonNull(message.action) == Action.EDIT) { + if (player.openContainer instanceof AEBaseContainer abc) { + final PrimaryGui pGui = abc.getPrimaryGui(); + TileEntity tile = DimensionManager.getWorld(message.dim) .getTileEntity(message.x, message.y, message.z); if (tile instanceof IPartHost host) { IPart part = host.getPart(message.side); - if (part instanceof PartLevelEmitter) { + if (part instanceof ILevelEmitter) { InventoryHandler.openGui( player, tile.getWorldObj(), new BlockPos(tile), message.side, GuiType.LEVEL_EMITTER_PROXY); - } else if (part instanceof PartFluidLevelEmitter) { - InventoryHandler.openGui( - player, - tile.getWorldObj(), - new BlockPos(tile), - message.side, - GuiType.FLUID_LEVEL_EMITTER); } } else { - InventoryHandler.openGui( player, tile.getWorldObj(), @@ -141,21 +143,24 @@ public class CPacketLevelTerminalCommands implements IMessage { message.side, GuiType.LEVEL_MAINTAINER); } - } - case BACK -> { - GuiType originalGui = GuiType.getByOrdinal(message.originalGui); - if (originalGui == null) { - return null; - } - InventoryHandler.openGui( - player, - player.worldObj, - new BlockPos(message.x, message.y, message.z, DimensionManager.getWorld(message.dim)), - message.side, - originalGui); + if (player.openContainer instanceof IContainerSubGui sg) { + sg.setPrimaryGui(pGui); + } + } + } else if (Objects.requireNonNull(message.action) == Action.RENAME) { + if (player.openContainer instanceof AEBaseContainer abc) { + final PrimaryGui pGui = abc.getPrimaryGui(); + + TileEntity tile = DimensionManager.getWorld(message.dim) + .getTileEntity(message.x, message.y, message.z); + + Platform.openGUI(player, tile, message.side, GuiBridge.GUI_RENAMER); + + if (player.openContainer instanceof IContainerSubGui sg) { + sg.setPrimaryGui(pGui); + } } - default -> {} } return null; } diff --git a/src/main/java/com/glodblock/github/network/CPacketPatternMultiSet.java b/src/main/java/com/glodblock/github/network/CPacketPatternMultiSet.java deleted file mode 100644 index e3656d2b..00000000 --- a/src/main/java/com/glodblock/github/network/CPacketPatternMultiSet.java +++ /dev/null @@ -1,89 +0,0 @@ -package com.glodblock.github.network; - -import java.util.Objects; - -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.tileentity.TileEntity; -import net.minecraftforge.common.util.ForgeDirection; - -import com.glodblock.github.client.gui.container.ContainerPatternMulti; -import com.glodblock.github.client.gui.container.base.FCContainerEncodeTerminal; -import com.glodblock.github.inventory.InventoryHandler; -import com.glodblock.github.inventory.gui.GuiType; -import com.glodblock.github.inventory.item.IWirelessTerminal; -import com.glodblock.github.util.BlockPos; -import com.glodblock.github.util.Util; - -import appeng.api.networking.IGridHost; -import appeng.container.ContainerOpenContext; -import cpw.mods.fml.common.network.simpleimpl.IMessage; -import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; -import cpw.mods.fml.common.network.simpleimpl.MessageContext; -import io.netty.buffer.ByteBuf; - -public class CPacketPatternMultiSet implements IMessage { - - private static GuiType guiType; - private static int multi; - - public CPacketPatternMultiSet(GuiType guiType, int multi) { - CPacketPatternMultiSet.guiType = guiType; - CPacketPatternMultiSet.multi = multi; - } - - public CPacketPatternMultiSet() { - // NO-OP - } - - @Override - public void fromBytes(ByteBuf byteBuf) { - guiType = GuiType.getByOrdinal(byteBuf.readByte()); - multi = byteBuf.readInt(); - } - - @Override - public void toBytes(ByteBuf byteBuf) { - byteBuf.writeByte(guiType != null ? guiType.ordinal() : 0); - byteBuf.writeInt(multi); - } - - public static class Handler implements IMessageHandler { - - @Override - public IMessage onMessage(CPacketPatternMultiSet message, MessageContext ctx) { - EntityPlayerMP player = ctx.getServerHandler().playerEntity; - if (player.openContainer instanceof ContainerPatternMulti cpv) { - final Object target = cpv.getTarget(); - if (target instanceof IGridHost) { - final ContainerOpenContext context = cpv.getOpenContext(); - if (context != null) { - final TileEntity te = context.getTile(); - if (te != null) { - InventoryHandler.openGui( - player, - te.getWorldObj(), - new BlockPos(te), - Objects.requireNonNull(cpv.getOpenContext().getSide()), - guiType); - } else if (target instanceof IWirelessTerminal wt) { - InventoryHandler.openGui( - player, - player.worldObj, - new BlockPos( - wt.getInventorySlot(), - Util.GuiHelper.encodeType(0, Util.GuiHelper.GuiType.ITEM), - 0), - ForgeDirection.UNKNOWN, - guiType); - } - if (player.openContainer instanceof FCContainerEncodeTerminal cpt) { - cpt.multiplyOrDivideStacks(multi); - } - } - } - } - return null; - } - } - -} diff --git a/src/main/java/com/glodblock/github/network/CPacketPatternValueSet.java b/src/main/java/com/glodblock/github/network/CPacketPatternValueSet.java deleted file mode 100644 index e17557a9..00000000 --- a/src/main/java/com/glodblock/github/network/CPacketPatternValueSet.java +++ /dev/null @@ -1,120 +0,0 @@ -package com.glodblock.github.network; - -import java.util.Objects; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; -import net.minecraftforge.fluids.FluidStack; - -import com.glodblock.github.client.gui.container.ContainerPatternValueAmount; -import com.glodblock.github.client.gui.container.ContainerSuperStockReplenisher; -import com.glodblock.github.client.gui.container.base.FCContainerEncodeTerminal; -import com.glodblock.github.common.item.ItemFluidPacket; -import com.glodblock.github.inventory.InventoryHandler; -import com.glodblock.github.inventory.gui.GuiType; -import com.glodblock.github.inventory.gui.PartOrItemGuiFactory; -import com.glodblock.github.inventory.item.IWirelessTerminal; -import com.glodblock.github.util.BlockPos; -import com.glodblock.github.util.Util; - -import appeng.api.networking.IGridHost; -import appeng.container.ContainerOpenContext; -import appeng.container.slot.SlotFake; -import cpw.mods.fml.common.network.simpleimpl.IMessage; -import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; -import cpw.mods.fml.common.network.simpleimpl.MessageContext; -import io.netty.buffer.ByteBuf; - -public class CPacketPatternValueSet implements IMessage { - - private GuiType originGui; - private int amount; - private int valueIndex; - - public CPacketPatternValueSet() { - // NO-OP - } - - public CPacketPatternValueSet(int originalGui, int amount, int valueIndex) { - this.originGui = GuiType.getByOrdinal(originalGui); - this.amount = amount; - this.valueIndex = valueIndex; - } - - @Override - public void toBytes(ByteBuf buf) { - buf.writeInt(originGui.ordinal()); - buf.writeInt(amount); - buf.writeInt(valueIndex); - } - - @Override - public void fromBytes(ByteBuf buf) { - this.originGui = GuiType.getByOrdinal(buf.readInt()); - this.amount = buf.readInt(); - this.valueIndex = buf.readInt(); - } - - public static class Handler implements IMessageHandler { - - @Override - public IMessage onMessage(CPacketPatternValueSet message, MessageContext ctx) { - EntityPlayer player = ctx.getServerHandler().playerEntity; - if (player.openContainer instanceof ContainerPatternValueAmount cpv) { - final Object target = cpv.getTarget(); - if (target instanceof IGridHost) { - final ContainerOpenContext context = cpv.getOpenContext(); - if (context != null) { - final TileEntity te = context.getTile(); - if (te != null) { - InventoryHandler.openGui( - player, - player.worldObj, - new BlockPos(te), - Objects.requireNonNull(context.getSide()), - message.originGui); - } else if (message.originGui.guiFactory instanceof PartOrItemGuiFactory) { - InventoryHandler.openGui( - player, - player.worldObj, - new BlockPos( - player.inventory.currentItem, - Util.GuiHelper.encodeType(0, Util.GuiHelper.GuiType.ITEM), - 0), - Objects.requireNonNull(context.getSide()), - message.originGui); - } else if (target instanceof IWirelessTerminal) { - InventoryHandler.openGui( - player, - player.worldObj, - new BlockPos(((IWirelessTerminal) target).getInventorySlot(), 0, 0), - Objects.requireNonNull(context.getSide()), - message.originGui); - } - if (player.openContainer instanceof FCContainerEncodeTerminal - || player.openContainer instanceof ContainerSuperStockReplenisher) { - Slot slot = player.openContainer.getSlot(message.valueIndex); - if (slot instanceof SlotFake) { - ItemStack stack = slot.getStack().copy(); - if (Util.isFluidPacket(stack)) { - FluidStack fluidStack = ItemFluidPacket.getFluidStack(stack); - if (fluidStack != null) { - fluidStack = ItemFluidPacket.getFluidStack(stack).copy(); - fluidStack.amount = message.amount; - } - slot.putStack(ItemFluidPacket.newStack(fluidStack)); - } else { - stack.stackSize = message.amount; - slot.putStack(stack); - } - } - } - } - } - } - return null; - } - } -} diff --git a/src/main/java/com/glodblock/github/network/CPacketRenamer.java b/src/main/java/com/glodblock/github/network/CPacketRenamer.java deleted file mode 100644 index 7acef54f..00000000 --- a/src/main/java/com/glodblock/github/network/CPacketRenamer.java +++ /dev/null @@ -1,187 +0,0 @@ -package com.glodblock.github.network; - -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.tileentity.TileEntity; -import net.minecraftforge.common.DimensionManager; -import net.minecraftforge.common.util.ForgeDirection; - -import com.glodblock.github.FluidCraft; -import com.glodblock.github.inventory.InventoryHandler; -import com.glodblock.github.inventory.gui.GuiType; -import com.glodblock.github.inventory.item.IClickableInTerminal; -import com.glodblock.github.inventory.item.IWirelessTerminal; -import com.glodblock.github.util.BlockPos; -import com.glodblock.github.util.Util; - -import appeng.api.implementations.IUpgradeableHost; -import appeng.container.AEBaseContainer; -import appeng.helpers.ICustomNameObject; -import appeng.tile.networking.TileCableBus; -import cpw.mods.fml.common.network.simpleimpl.IMessage; -import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; -import cpw.mods.fml.common.network.simpleimpl.MessageContext; -import io.netty.buffer.ByteBuf; - -public class CPacketRenamer implements IMessage { - - private int x; - private int y; - private int z; - private int dim; - private ForgeDirection side; - private Action action; - private String text; - - public enum Action { - OPEN, - GET_TEXT, - SET_TEXT, - } - - public CPacketRenamer() {} - - public CPacketRenamer(String text) { - this.action = Action.SET_TEXT; - this.text = text; - } - - public CPacketRenamer(Action a) { - this.action = a; - } - - public CPacketRenamer(int x, int y, int z, int dim, ForgeDirection side) { - this.action = Action.OPEN; - this.x = x; - this.y = y; - this.z = z; - this.dim = dim; - this.side = side; - } - - @Override - public void fromBytes(ByteBuf buf) { - this.action = Action.values()[buf.readInt()]; - if (this.action == Action.OPEN) { - this.x = buf.readInt(); - this.y = buf.readInt(); - this.z = buf.readInt(); - this.dim = buf.readInt(); - this.side = ForgeDirection.getOrientation(buf.readInt()); - } else if (this.action == Action.SET_TEXT) { - int leName = buf.readInt(); - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < leName; i++) { - sb.append(buf.readChar()); - } - this.text = sb.toString(); - } - - } - - @Override - public void toBytes(ByteBuf buf) { - buf.writeInt(this.action.ordinal()); - if (this.action == Action.OPEN) { - buf.writeInt(this.x); - buf.writeInt(this.y); - buf.writeInt(this.z); - buf.writeInt(this.dim); - buf.writeInt(side.ordinal()); - } else if (this.action == Action.SET_TEXT) { - buf.writeInt(this.text.length()); - for (int i = 0; i < this.text.length(); i++) { - buf.writeChar(this.text.charAt(i)); - } - } - } - - public static class Handler implements IMessageHandler { - - private String getName(ICustomNameObject obj) { - return obj.hasCustomName() ? obj.getCustomName() : ""; - } - - private String getName(TileEntity tile, ForgeDirection side) { - if (tile instanceof TileCableBus) { - return getName((ICustomNameObject) ((TileCableBus) tile).getPart(side)); - } else { - return getName((ICustomNameObject) tile); - } - } - - private void setName(TileEntity tile, ForgeDirection side, String text) { - if (tile instanceof TileCableBus) { - ((ICustomNameObject) ((TileCableBus) tile).getPart(side)).setCustomName(text); - } else { - ((ICustomNameObject) tile).setCustomName(text); - } - } - - @Override - public IMessage onMessage(CPacketRenamer message, MessageContext ctx) { - EntityPlayerMP player = ctx.getServerHandler().playerEntity; - AEBaseContainer con = (AEBaseContainer) player.openContainer; - switch (message.action) { - case OPEN -> { - if (con.getTarget() instanceof IClickableInTerminal clickableInterface) { - TileEntity tile = DimensionManager.getWorld(message.dim) - .getTileEntity(message.x, message.y, message.z); - if (!(tile instanceof ICustomNameObject)) { - break; - } - - String name = getName(tile, message.side); - clickableInterface.setClickedInterface( - new Util.DimensionalCoordSide( - message.x, - message.y, - message.z, - message.dim, - message.side, - name)); - - if (con.getTarget() instanceof IWirelessTerminal terminal) { - InventoryHandler.openGui( - player, - player.worldObj, - new BlockPos( - terminal.getInventorySlot(), - Util.GuiHelper.encodeType(0, Util.GuiHelper.GuiType.ITEM), - 1), - message.side, - GuiType.RENAMER); - } else if (con.getTarget() instanceof IUpgradeableHost host) { - InventoryHandler.openGui( - player, - player.worldObj, - new BlockPos(host.getTile()), - con.getOpenContext().getSide(), - GuiType.RENAMER); - } - } - } - case GET_TEXT -> { - if (con.getTarget() instanceof IClickableInTerminal clickableInterface) { - Util.DimensionalCoordSide intMsg = clickableInterface.getClickedInterface(); - TileEntity tile = DimensionManager.getWorld(intMsg.getDimension()) - .getTileEntity(intMsg.x, intMsg.y, intMsg.z); - FluidCraft.proxy.netHandler - .sendTo(new SPacketStringUpdate(this.getName(tile, intMsg.getSide())), player); - } - } - case SET_TEXT -> { - if (con.getTarget() instanceof IClickableInTerminal clickableInterface) { - Util.DimensionalCoordSide intMsg = clickableInterface.getClickedInterface(); - TileEntity tile = DimensionManager.getWorld(intMsg.getDimension()) - .getTileEntity(intMsg.x, intMsg.y, intMsg.z); - this.setName(tile, intMsg.getSide(), message.text); - - FluidCraft.proxy.netHandler.sendTo(new SPacketSwitchBack(), player); - } - } - } - return null; - } - - } -} diff --git a/src/main/java/com/glodblock/github/network/CPacketSwitchGuis.java b/src/main/java/com/glodblock/github/network/CPacketSwitchGuis.java index 834a88e0..14cf3846 100644 --- a/src/main/java/com/glodblock/github/network/CPacketSwitchGuis.java +++ b/src/main/java/com/glodblock/github/network/CPacketSwitchGuis.java @@ -6,17 +6,28 @@ import javax.annotation.Nullable; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.inventory.Container; +import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; +import org.apache.commons.lang3.tuple.ImmutablePair; + +import com.glodblock.github.FluidCraft; import com.glodblock.github.common.item.ItemWirelessUltraTerminal; +import com.glodblock.github.common.parts.PartFluidInterface; +import com.glodblock.github.common.parts.PartFluidP2PInterface; +import com.glodblock.github.common.tile.TileFluidInterface; +import com.glodblock.github.common.tile.TileSuperStockReplenisher; import com.glodblock.github.inventory.InventoryHandler; import com.glodblock.github.inventory.gui.GuiType; -import com.glodblock.github.inventory.item.IWirelessTerminal; import com.glodblock.github.util.BlockPos; +import com.glodblock.github.util.UltraTerminalModes; import com.glodblock.github.util.Util; import appeng.container.AEBaseContainer; import appeng.container.ContainerOpenContext; +import appeng.container.PrimaryGui; +import appeng.container.interfaces.IContainerSubGui; +import appeng.helpers.ICustomButtonProvider; import cpw.mods.fml.common.network.simpleimpl.IMessage; import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; import cpw.mods.fml.common.network.simpleimpl.MessageContext; @@ -24,15 +35,15 @@ import io.netty.buffer.ByteBuf; public class CPacketSwitchGuis implements IMessage { - private GuiType guiType; + private UltraTerminalModes mode; private boolean switchTerminal; - public CPacketSwitchGuis(GuiType guiType) { - this(guiType, false); + public CPacketSwitchGuis(UltraTerminalModes mode) { + this(mode, false); } - public CPacketSwitchGuis(GuiType guiType, boolean switchTerminal) { - this.guiType = guiType; + public CPacketSwitchGuis(UltraTerminalModes mode, boolean switchTerminal) { + this.mode = mode; this.switchTerminal = switchTerminal; } @@ -42,13 +53,14 @@ public class CPacketSwitchGuis implements IMessage { @Override public void fromBytes(ByteBuf byteBuf) { - guiType = GuiType.getByOrdinal(byteBuf.readByte()); + final int ord = byteBuf.readInt(); + mode = ord != -1 ? UltraTerminalModes.values()[ord] : null; switchTerminal = byteBuf.readBoolean(); } @Override public void toBytes(ByteBuf byteBuf) { - byteBuf.writeByte(guiType != null ? guiType.ordinal() : 0); + byteBuf.writeInt(mode != null ? mode.ordinal() : -1); byteBuf.writeBoolean(this.switchTerminal); } @@ -57,43 +69,51 @@ public class CPacketSwitchGuis implements IMessage { @Nullable @Override public IMessage onMessage(CPacketSwitchGuis message, MessageContext ctx) { - if (message.guiType == null) { - return null; - } - EntityPlayerMP player = ctx.getServerHandler().playerEntity; Container cont = player.openContainer; // switch terminal - if (message.switchTerminal) { - ItemWirelessUltraTerminal.switchTerminal(player, message.guiType); - return null; - } - // open new terminal - if (cont instanceof AEBaseContainer) { - ContainerOpenContext context = ((AEBaseContainer) cont).getOpenContext(); - if (context == null) { - return null; + if (message.switchTerminal) { + ImmutablePair temp = Util.getUltraWirelessTerm(player); + if (temp != null && temp.getRight().getItem() instanceof ItemWirelessUltraTerminal iwut) { + if (message.mode != null && cont instanceof AEBaseContainer abc) { + abc.setSwitchAbleGuiNext(message.mode.ordinal()); + + } + iwut.switchTerminal(player, temp, message.mode); + if (player.openContainer instanceof AEBaseContainer abc) { + if (abc.getTarget() instanceof ICustomButtonProvider icbp) { + FluidCraft.proxy.netHandler + .sendTo(new SPacketCustomButtonUpdate(icbp.getDataObject()), player); + } + } } - TileEntity te = context.getTile(); - if (te != null) { + } else { + if (cont instanceof AEBaseContainer aeBaseContainer) { + final PrimaryGui pGui = aeBaseContainer.getPrimaryGui(); + ContainerOpenContext context = aeBaseContainer.getOpenContext(); + if (context == null) return null; + TileEntity te = context.getTile(); + Object target = aeBaseContainer.getTarget(); + GuiType guiType; + + if (te instanceof TileSuperStockReplenisher) guiType = GuiType.GUI_SUPER_STOCK_REPLENISHER; + else if (te instanceof TileFluidInterface || target instanceof PartFluidInterface + || target instanceof PartFluidP2PInterface) + guiType = GuiType.DUAL_INTERFACE_FLUID; + else return null; + InventoryHandler.openGui( player, player.worldObj, new BlockPos(te), Objects.requireNonNull(context.getSide()), - message.guiType); - } else if (((AEBaseContainer) cont).getTarget() instanceof IWirelessTerminal) { - InventoryHandler.openGui( - player, - player.worldObj, - new BlockPos( - ((IWirelessTerminal) ((AEBaseContainer) cont).getTarget()).getInventorySlot(), - Util.GuiHelper.encodeType(0, Util.GuiHelper.GuiType.ITEM), - 0), - Objects.requireNonNull(context.getSide()), - message.guiType); + guiType); + + if (player.openContainer instanceof IContainerSubGui sg) { + sg.setPrimaryGui(pGui); + } } } return null; diff --git a/src/main/java/com/glodblock/github/network/CPacketTransferRecipe.java b/src/main/java/com/glodblock/github/network/CPacketTransferRecipe.java deleted file mode 100644 index 77917c8f..00000000 --- a/src/main/java/com/glodblock/github/network/CPacketTransferRecipe.java +++ /dev/null @@ -1,169 +0,0 @@ -package com.glodblock.github.network; - -import java.util.LinkedList; -import java.util.List; - -import javax.annotation.Nullable; - -import net.minecraft.inventory.Container; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraftforge.fluids.FluidStack; - -import com.glodblock.github.client.gui.container.ContainerItemMonitor; -import com.glodblock.github.client.gui.container.base.FCContainerEncodeTerminal; -import com.glodblock.github.common.item.ItemFluidPacket; -import com.glodblock.github.nei.NEIUtils; -import com.glodblock.github.nei.object.OrderStack; - -import appeng.api.AEApi; -import appeng.api.storage.IMEMonitor; -import appeng.api.storage.data.IAEItemStack; -import appeng.api.storage.data.IItemList; -import cpw.mods.fml.common.network.ByteBufUtils; -import cpw.mods.fml.common.network.simpleimpl.IMessage; -import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; -import cpw.mods.fml.common.network.simpleimpl.MessageContext; -import io.netty.buffer.ByteBuf; - -public class CPacketTransferRecipe implements IMessage { - - private List> inputs; - private List> outputs; - private boolean isCraft; - private static final int MAX_INDEX = 81; - private static final int MAX_SLOTS_INDEX = 32; - private boolean shift; - - public CPacketTransferRecipe() {} - - public CPacketTransferRecipe(List> IN, List> OUT, boolean craft) { - this(IN, OUT, craft, false); - } - - public CPacketTransferRecipe(List> IN, List> OUT, boolean craft, boolean shift) { - this.inputs = IN; - this.outputs = OUT; - this.isCraft = craft; - this.shift = shift; - } - - // TODO: this should use GZIP to compress the message - // NBT to ByteBuf has a compress stream - @Override - public void toBytes(ByteBuf buf) { - buf.writeBoolean(isCraft); - buf.writeBoolean(shift); - NBTTagCompound nbt_m = new NBTTagCompound(); - NBTTagCompound nbt_i = new NBTTagCompound(); - NBTTagCompound nbt_o = new NBTTagCompound(); - for (OrderStack stack : inputs) { - stack.writeToNBT(nbt_i); - } - for (OrderStack stack : outputs) { - stack.writeToNBT(nbt_o); - } - nbt_m.setTag("i", nbt_i); - nbt_m.setTag("o", nbt_o); - ByteBufUtils.writeTag(buf, nbt_m); - } - - @Override - public void fromBytes(ByteBuf buf) { - isCraft = buf.readBoolean(); - shift = buf.readBoolean(); - inputs = new LinkedList<>(); - outputs = new LinkedList<>(); - NBTTagCompound nbt_m = ByteBufUtils.readTag(buf); - NBTTagCompound nbt_i = nbt_m.getCompoundTag("i"); - NBTTagCompound nbt_o = nbt_m.getCompoundTag("o"); - for (int i = 0; i < MAX_INDEX; i++) { - OrderStack tmp = OrderStack.readFromNBT(nbt_i, null, i); - if (tmp != null && inputs.size() < MAX_SLOTS_INDEX) inputs.add(tmp); - } - for (int i = 0; i < MAX_INDEX; i++) { - OrderStack tmp = OrderStack.readFromNBT(nbt_o, null, i); - if (tmp != null && inputs.size() < MAX_SLOTS_INDEX) outputs.add(tmp); - } - } - - public static class Handler implements IMessageHandler { - - @Nullable - @Override - @SuppressWarnings("unchecked") - public IMessage onMessage(CPacketTransferRecipe message, MessageContext ctx) { - Container c = ctx.getServerHandler().playerEntity.openContainer; - if (c instanceof ContainerItemMonitor) { - IMEMonitor monitor = ((ContainerItemMonitor) c).getMonitor(); - IItemList storageList = AEApi.instance().storage().createItemList(); - if (monitor != null) { - storageList = monitor.getStorageList(); - } - if (c instanceof FCContainerEncodeTerminal cf) { - // pattern terminal only - - boolean combine = cf.combine; - cf.getPatternTerminal().setCraftingRecipe(message.isCraft); - IInventory inputSlot = cf.getInventoryByName("crafting"); - IInventory outputSlot = cf.getInventoryByName("output"); - for (int i = 0; i < inputSlot.getSizeInventory(); i++) { - inputSlot.setInventorySlotContents(i, null); - } - for (int i = 0; i < outputSlot.getSizeInventory(); i++) { - outputSlot.setInventorySlotContents(i, null); - } - - if (!message.isCraft) { - if (combine) { - message.inputs = NEIUtils.compress(message.inputs); - message.outputs = NEIUtils.compress(message.outputs); - } - message.inputs = NEIUtils.clearNull(message.inputs); - message.outputs = NEIUtils.clearNull(message.outputs); - } - // using exists item to fill slot - if (message.shift && !storageList.isEmpty()) { - for (@SuppressWarnings("rawtypes") - OrderStack stack : message.inputs) { - if (stack.getStack() instanceof FluidStack || stack.getItems() == null) continue; - IAEItemStack iaeItemStack = AEApi.instance().storage() - .createItemStack((ItemStack) stack.getStack()); - if (storageList.findPrecise(iaeItemStack) == null) { - // try to replace item - for (ItemStack replaceItemStack : stack.getItems()) { - if (storageList.findPrecise( - AEApi.instance().storage().createItemStack(replaceItemStack)) != null) { - stack.putStack(replaceItemStack); - } - } - } - } - } - transferPack(message.inputs, inputSlot); - transferPack(message.outputs, outputSlot); - c.onCraftMatrixChanged(inputSlot); - c.onCraftMatrixChanged(outputSlot); - } - } - - return null; - } - - private void transferPack(List> packs, IInventory inv) { - for (OrderStack stack : packs) { - if (stack != null) { - int index = stack.getIndex(); - ItemStack stack1; - if (stack.getStack() instanceof ItemStack) { - stack1 = ((ItemStack) stack.getStack()).copy(); - } else if (stack.getStack() instanceof FluidStack) { - stack1 = ItemFluidPacket.newStack((FluidStack) stack.getStack()); - } else throw new UnsupportedOperationException("Trying to get an unsupported item!"); - if (index < inv.getSizeInventory()) inv.setInventorySlotContents(index, stack1); - } - } - } - } -} diff --git a/src/main/java/com/glodblock/github/network/CPacketValueConfig.java b/src/main/java/com/glodblock/github/network/CPacketValueConfig.java index fdc73ee6..f3a0720d 100644 --- a/src/main/java/com/glodblock/github/network/CPacketValueConfig.java +++ b/src/main/java/com/glodblock/github/network/CPacketValueConfig.java @@ -1,5 +1,7 @@ package com.glodblock.github.network; +import static com.glodblock.github.util.Util.toggleRestock; + import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.ContainerPlayer; @@ -9,15 +11,16 @@ import net.minecraft.util.StatCollector; import org.apache.commons.lang3.tuple.ImmutablePair; -import com.glodblock.github.client.gui.container.ContainerFluidLevelEmitter; -import com.glodblock.github.common.item.ItemBaseWirelessTerminal; -import com.glodblock.github.inventory.item.WirelessCraftingTerminalInventory; import com.glodblock.github.util.NameConst; import com.glodblock.github.util.Util; import appeng.api.AEApi; import appeng.api.config.Actionable; +import appeng.api.networking.IGrid; import appeng.api.networking.IGridNode; +import appeng.api.networking.security.PlayerSource; +import appeng.api.networking.storage.IStorageGrid; +import appeng.api.storage.IMEMonitor; import appeng.api.storage.data.IAEItemStack; import cpw.mods.fml.common.network.simpleimpl.IMessage; import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; @@ -55,15 +58,12 @@ public class CPacketValueConfig implements IMessage { EntityPlayer player = ctx.getServerHandler().playerEntity; Container container = player.openContainer; if (container != null) { - if (container instanceof ContainerFluidLevelEmitter) { - ((ContainerFluidLevelEmitter) container).setLevel(message.amount, player); - } else if (container instanceof ContainerPlayer) { + if (container instanceof ContainerPlayer) { ImmutablePair result = Util.getUltraWirelessTerm(player); if (result != null) { final ItemStack wirelessTerm = result.getRight(); if (message.valueIndex == 1) { - ItemBaseWirelessTerminal - .toggleRestockItemsMode(wirelessTerm, !Util.isRestock(wirelessTerm)); + toggleRestock(wirelessTerm); player.addChatMessage( new ChatComponentText( StatCollector.translateToLocal( @@ -85,25 +85,31 @@ public class CPacketValueConfig implements IMessage { @SuppressWarnings("unchecked") private void restockItems(ItemStack terminal, IGridNode gridNode, int slot, EntityPlayer player) { - WirelessCraftingTerminalInventory inv = new WirelessCraftingTerminalInventory( - terminal, - slot, - gridNode, - player); + IGrid targetGrid = gridNode.getGrid(); + IMEMonitor itemStorage = null; - for (int i = 0; i < 9; i++) { - ItemStack is = player.inventory.mainInventory[i]; - if (is != null) { - int maxSize = is.getMaxStackSize(); - if (is.stackSize < maxSize) { - int fillSize = maxSize - is.stackSize; - IAEItemStack ias = AEApi.instance().storage().createItemStack(is); - ias.setStackSize(fillSize); + if (targetGrid != null) { + IStorageGrid sg = targetGrid.getCache(IStorageGrid.class); + if (sg != null) { + itemStorage = sg.getItemInventory(); + } + } - IAEItemStack extractedItem = (IAEItemStack) inv - .extractItems(ias, Actionable.MODULATE, inv.getActionSource()); - if (extractedItem != null) { - player.inventory.addItemStackToInventory(extractedItem.getItemStack()); + if (itemStorage != null) { + for (int i = 0; i < 9; i++) { + ItemStack is = player.inventory.mainInventory[i]; + if (is != null) { + int maxSize = is.getMaxStackSize(); + if (is.stackSize < maxSize) { + int fillSize = maxSize - is.stackSize; + IAEItemStack ias = AEApi.instance().storage().createItemStack(is); + ias.setStackSize(fillSize); + + IAEItemStack extractedItem = itemStorage + .extractItems(ias, Actionable.MODULATE, new PlayerSource(player, null)); + if (extractedItem != null) { + player.inventory.addItemStackToInventory(extractedItem.getItemStack()); + } } } } diff --git a/src/main/java/com/glodblock/github/network/SPacketCustomButtonUpdate.java b/src/main/java/com/glodblock/github/network/SPacketCustomButtonUpdate.java new file mode 100644 index 00000000..04d0f632 --- /dev/null +++ b/src/main/java/com/glodblock/github/network/SPacketCustomButtonUpdate.java @@ -0,0 +1,46 @@ +package com.glodblock.github.network; + +import net.minecraft.client.Minecraft; + +import appeng.container.AEBaseContainer; +import appeng.helpers.ICustomButtonDataObject; +import appeng.helpers.ICustomButtonProvider; +import cpw.mods.fml.common.network.simpleimpl.IMessage; +import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; +import cpw.mods.fml.common.network.simpleimpl.MessageContext; +import io.netty.buffer.ByteBuf; + +public class SPacketCustomButtonUpdate implements IMessage { + + private ICustomButtonDataObject dataObject; + + private ByteBuf buf; + + public SPacketCustomButtonUpdate() {} + + public SPacketCustomButtonUpdate(ICustomButtonDataObject dataObject) { + this.dataObject = dataObject; + } + + @Override + public void fromBytes(ByteBuf buf) { + this.buf = buf; + } + + @Override + public void toBytes(ByteBuf buf) { + this.dataObject.writeByte(buf); + } + + public static class Handler implements IMessageHandler { + + @Override + public IMessage onMessage(SPacketCustomButtonUpdate message, MessageContext ctx) { + if (Minecraft.getMinecraft().thePlayer.openContainer instanceof AEBaseContainer abc + && abc.getTarget() instanceof ICustomButtonProvider icbp) { + icbp.getDataObject().readByte(message.buf); + } + return null; + } + } +} diff --git a/src/main/java/com/glodblock/github/network/SPacketFluidUpdate.java b/src/main/java/com/glodblock/github/network/SPacketFluidUpdate.java index 0ff0601b..bb0bd3a5 100644 --- a/src/main/java/com/glodblock/github/network/SPacketFluidUpdate.java +++ b/src/main/java/com/glodblock/github/network/SPacketFluidUpdate.java @@ -8,12 +8,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; import net.minecraft.item.ItemStack; -import com.glodblock.github.client.gui.GuiEssentiaTerminal; -import com.glodblock.github.client.gui.GuiFluidIO; import com.glodblock.github.client.gui.GuiFluidInterface; -import com.glodblock.github.client.gui.GuiFluidLevelEmitter; -import com.glodblock.github.client.gui.GuiFluidStorageBus; -import com.glodblock.github.client.gui.GuiFluidTerminal; import com.glodblock.github.client.gui.GuiIngredientBuffer; import com.glodblock.github.client.gui.GuiLargeIngredientBuffer; import com.glodblock.github.util.Util; @@ -90,33 +85,10 @@ public class SPacketFluidUpdate implements IMessage { for (Map.Entry e : message.list.entrySet()) { ((GuiLargeIngredientBuffer) gs).update(e.getKey(), e.getValue()); } - } else if (gs instanceof GuiFluidIO) { - for (Map.Entry e : message.list.entrySet()) { - ((GuiFluidIO) gs).update(e.getKey(), e.getValue()); - } } else if (gs instanceof GuiFluidInterface) { for (Map.Entry e : message.list.entrySet()) { ((GuiFluidInterface) gs).update(e.getKey(), e.getValue()); } - } else if (gs instanceof GuiFluidTerminal) { - if (message.itemStack != null) { - ((GuiFluidTerminal) gs).update(message.itemStack.getItemStack()); - } else { - ((GuiFluidTerminal) gs).update(null); - } - } else if (gs instanceof GuiEssentiaTerminal) { - if (message.itemStack != null) { - ((GuiEssentiaTerminal) gs).update(message.itemStack.getItemStack()); - } else { - ((GuiEssentiaTerminal) gs).update(null); - } - } else if (gs instanceof GuiFluidStorageBus) { - for (Map.Entry e : message.list.entrySet()) - ((GuiFluidStorageBus) gs).update(e.getKey(), e.getValue()); - } else if (gs instanceof GuiFluidLevelEmitter) { - for (Map.Entry e : message.list.entrySet()) { - ((GuiFluidLevelEmitter) gs).update(e.getKey(), e.getValue()); - } } return null; } diff --git a/src/main/java/com/glodblock/github/network/SPacketLevelMaintainerGuiUpdate.java b/src/main/java/com/glodblock/github/network/SPacketLevelMaintainerGuiUpdate.java index 4ca244d7..2d564e5d 100644 --- a/src/main/java/com/glodblock/github/network/SPacketLevelMaintainerGuiUpdate.java +++ b/src/main/java/com/glodblock/github/network/SPacketLevelMaintainerGuiUpdate.java @@ -6,9 +6,9 @@ import static com.glodblock.github.common.tile.TileLevelMaintainer.RequestInfo; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; -import com.glodblock.github.api.registries.LevelState; import com.glodblock.github.client.gui.GuiLevelMaintainer; +import appeng.api.features.LevelState; import cpw.mods.fml.common.network.simpleimpl.IMessage; import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; import cpw.mods.fml.common.network.simpleimpl.MessageContext; diff --git a/src/main/java/com/glodblock/github/network/SPacketLevelTerminalUpdate.java b/src/main/java/com/glodblock/github/network/SPacketLevelTerminalUpdate.java index 951715c5..b495aadf 100644 --- a/src/main/java/com/glodblock/github/network/SPacketLevelTerminalUpdate.java +++ b/src/main/java/com/glodblock/github/network/SPacketLevelTerminalUpdate.java @@ -1,19 +1,22 @@ package com.glodblock.github.network; +import static appeng.util.Platform.readStackByte; +import static appeng.util.Platform.writeStackByte; + import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; -import net.minecraft.item.ItemStack; import org.jetbrains.annotations.Nullable; -import com.glodblock.github.api.registries.LevelItemInfo; -import com.glodblock.github.api.registries.LevelState; import com.glodblock.github.client.gui.GuiLevelTerminal; +import appeng.api.features.LevelItemInfo; +import appeng.api.features.LevelState; +import appeng.api.storage.data.IAEStack; import appeng.core.AEConfig; import appeng.core.AELog; import appeng.core.features.AEFeature; @@ -176,7 +179,7 @@ public class SPacketLevelTerminalUpdate implements IMessage { infolist = new LevelItemInfo[infoSize]; for (int i = 0; i < infoSize; i++) { if (!buf.readBoolean()) continue; - ItemStack stack = ByteBufUtils.readItemStack(buf); + IAEStack stack = readStackByte(buf); long quantity = buf.readLong(); long batchSize = buf.readLong(); LevelState state = LevelState.values()[buf.readInt()]; @@ -206,7 +209,7 @@ public class SPacketLevelTerminalUpdate implements IMessage { buf.writeBoolean(info != null); if (info == null) continue; // System.out.println("Writing info: " + info.stack != null); - ByteBufUtils.writeItemStack(buf, info.stack); + writeStackByte(info.stack, buf); buf.writeLong(info.quantity); buf.writeLong(info.batchSize); buf.writeInt(info.state.ordinal()); @@ -293,7 +296,7 @@ public class SPacketLevelTerminalUpdate implements IMessage { this.index = buf.readInt(); if (buf.readBoolean()) { this.info = new LevelItemInfo( - ByteBufUtils.readItemStack(buf), + readStackByte(buf), buf.readLong(), buf.readLong(), LevelState.values()[buf.readInt()]); @@ -312,7 +315,7 @@ public class SPacketLevelTerminalUpdate implements IMessage { super.write(buf); buf.writeInt(index); buf.writeBoolean(info != null); - ByteBufUtils.writeItemStack(buf, info.stack); + writeStackByte(info.stack, buf); buf.writeLong(info.quantity); buf.writeLong(info.batchSize); buf.writeInt(info.state.ordinal()); @@ -334,7 +337,7 @@ public class SPacketLevelTerminalUpdate implements IMessage { this.infoList = new LevelItemInfo[infoSize]; for (int i = 0; i < infoSize; i++) { if (!buf.readBoolean()) continue; - ItemStack stack = ByteBufUtils.readItemStack(buf); + IAEStack stack = readStackByte(buf); long quantity = buf.readLong(); long batchSize = buf.readLong(); LevelState state = LevelState.values()[buf.readInt()]; @@ -356,7 +359,7 @@ public class SPacketLevelTerminalUpdate implements IMessage { buf.writeBoolean(info != null); if (info == null) continue; buf.writeInt(i); - ByteBufUtils.writeItemStack(buf, info.stack); + writeStackByte(info.stack, buf); buf.writeLong(info.quantity); buf.writeLong(info.batchSize); buf.writeInt(info.state.ordinal()); diff --git a/src/main/java/com/glodblock/github/network/SPacketMEFluidInvUpdate.java b/src/main/java/com/glodblock/github/network/SPacketMEFluidInvUpdate.java deleted file mode 100644 index caef56ea..00000000 --- a/src/main/java/com/glodblock/github/network/SPacketMEFluidInvUpdate.java +++ /dev/null @@ -1,104 +0,0 @@ -package com.glodblock.github.network; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiScreen; - -import com.glodblock.github.client.gui.GuiFluidCraftConfirm; -import com.glodblock.github.client.gui.GuiFluidMonitor; - -import appeng.api.storage.data.IAEFluidStack; -import appeng.util.item.AEFluidStack; -import cpw.mods.fml.common.network.simpleimpl.IMessage; -import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; -import cpw.mods.fml.common.network.simpleimpl.MessageContext; -import io.netty.buffer.ByteBuf; - -/** - * Dedicated packet for fluid updates. - */ -public class SPacketMEFluidInvUpdate implements IMessage { - - private List list = new ArrayList<>(); - private byte ref = (byte) 0; - private boolean resort = true; - - public SPacketMEFluidInvUpdate() {} - - /** - * Used for the GUI to confirm crafting. 0 = available 1 = pending 2 = missing - */ - public SPacketMEFluidInvUpdate(byte b) { - ref = b; - } - - /** - * If resort, call "updateView()". Used when multiple packets are sent to open an inventory; only the last packet - * should resort - * - * @param resort whether this packet should resort the term or not - */ - public SPacketMEFluidInvUpdate(boolean resort) { - this.resort = resort; - } - - @Override - public void fromBytes(ByteBuf buf) { - ref = buf.readByte(); - resort = buf.readBoolean(); - int amount = buf.readInt(); - list = new ArrayList<>(amount); - try { - for (int i = 0; i < amount; i++) { - list.add(AEFluidStack.loadFluidStackFromPacket(buf)); - } - } catch (Exception io) { - System.out.println("Error handling payload w/ " + amount + " items."); - io.printStackTrace(); - } - } - - @Override - public void toBytes(ByteBuf buf) { - buf.writeByte(ref); - buf.writeBoolean(resort); - buf.writeInt(list.size()); - try { - for (IAEFluidStack is : list) { - is.writeToPacket(buf); - } - } catch (IOException io) { - io.printStackTrace(); - } - } - - public void setResort(boolean resort) { - this.resort = resort; - } - - public void appendFluid(final IAEFluidStack is) { - list.add(is); - } - - public boolean isEmpty() { - return this.list.isEmpty(); - } - - public static class Handler implements IMessageHandler { - - @Override - @SuppressWarnings({ "unchecked", "rawtypes" }) - public IMessage onMessage(SPacketMEFluidInvUpdate message, MessageContext ctx) { - final GuiScreen gs = Minecraft.getMinecraft().currentScreen; - if (gs instanceof GuiFluidMonitor) { - ((GuiFluidMonitor) gs).postUpdate(message.list, message.resort); - } else if (gs instanceof GuiFluidCraftConfirm) { - ((GuiFluidCraftConfirm) gs).postUpdate((List) message.list, message.ref); - } - return null; - } - } -} diff --git a/src/main/java/com/glodblock/github/network/SPacketMEItemInvUpdate.java b/src/main/java/com/glodblock/github/network/SPacketMEItemInvUpdate.java deleted file mode 100644 index 0ebb1aa0..00000000 --- a/src/main/java/com/glodblock/github/network/SPacketMEItemInvUpdate.java +++ /dev/null @@ -1,103 +0,0 @@ -package com.glodblock.github.network; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiScreen; - -import com.glodblock.github.client.gui.GuiFluidCraftConfirm; -import com.glodblock.github.client.gui.GuiItemMonitor; - -import appeng.api.storage.data.IAEItemStack; -import appeng.util.item.AEItemStack; -import cpw.mods.fml.common.network.simpleimpl.IMessage; -import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; -import cpw.mods.fml.common.network.simpleimpl.MessageContext; -import io.netty.buffer.ByteBuf; - -/** - * Packet dedicated to item inventory update. - */ -public class SPacketMEItemInvUpdate implements IMessage { - - private List list = new ArrayList<>(); - private byte ref = (byte) 0; - private boolean resort = true; - - public SPacketMEItemInvUpdate() {} - - /** - * Used for the GUI to confirm crafting. 0 = available 1 = pending 2 = missing - */ - public SPacketMEItemInvUpdate(byte b) { - ref = b; - } - - /** - * If resort, call "updateView()". Used when multiple packets are sent to open an inventory; only the last packet - * should resort. - * - * @param resort whether this packet should resort the term or not - */ - public SPacketMEItemInvUpdate(boolean resort) { - this.resort = resort; - } - - @Override - public void fromBytes(ByteBuf buf) { - ref = buf.readByte(); - resort = buf.readBoolean(); - int amount = buf.readInt(); - list = new ArrayList<>(amount); - try { - for (int i = 0; i < amount; i++) { - list.add(AEItemStack.loadItemStackFromPacket(buf)); - } - } catch (Exception io) { - System.out.println("Error handling payload w/ " + amount + " items."); - io.printStackTrace(); - } - } - - @Override - public void toBytes(ByteBuf buf) { - buf.writeByte(ref); - buf.writeBoolean(resort); - buf.writeInt(list.size()); - try { - for (IAEItemStack is : list) { - is.writeToPacket(buf); - } - } catch (IOException io) { - io.printStackTrace(); - } - } - - public void setResort(boolean resort) { - this.resort = resort; - } - - public void appendItem(final IAEItemStack is) { - list.add(is); - } - - public boolean isEmpty() { - return this.list.isEmpty(); - } - - public static class Handler implements IMessageHandler { - - @Override - public IMessage onMessage(SPacketMEItemInvUpdate message, MessageContext ctx) { - final GuiScreen gs = Minecraft.getMinecraft().currentScreen; - if (gs instanceof GuiItemMonitor) { - ((GuiItemMonitor) gs).postUpdate(message.list, message.resort); - } else if (gs instanceof GuiFluidCraftConfirm) { - ((GuiFluidCraftConfirm) gs).postUpdate(message.list, message.ref); - } - return null; - } - } -} diff --git a/src/main/java/com/glodblock/github/network/SPacketMEUpdateBuffer.java b/src/main/java/com/glodblock/github/network/SPacketMEUpdateBuffer.java deleted file mode 100644 index fc10f710..00000000 --- a/src/main/java/com/glodblock/github/network/SPacketMEUpdateBuffer.java +++ /dev/null @@ -1,148 +0,0 @@ -package com.glodblock.github.network; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ScheduledFuture; -import java.util.concurrent.TimeUnit; - -import net.minecraft.entity.player.EntityPlayerMP; - -import com.glodblock.github.FluidCraft; -import com.glodblock.github.common.Config; - -import appeng.api.storage.data.IAEFluidStack; -import appeng.api.storage.data.IAEItemStack; -import cpw.mods.fml.common.eventhandler.SubscribeEvent; -import cpw.mods.fml.common.gameevent.PlayerEvent; - -/** - * Only should exist on the server side! Schedules packets to be sent every `packetRate` ms. - */ -public class SPacketMEUpdateBuffer { - - private static ScheduledExecutorService executor; - private static ScheduledFuture task; - - private static final Map> itemBuffer = new HashMap<>(); - private static final Map> fluidBuffer = new HashMap<>(); - - public static void start() { - executor = Executors.newSingleThreadScheduledExecutor(r -> { - Thread thread = new Thread(r); - thread.setName("AE2FC Network worker"); - thread.setDaemon(true); - thread.setPriority(6); - return thread; - }); - task = executor - .scheduleAtFixedRate(SPacketMEUpdateBuffer::sendBuffer, 0, Config.packetRate, TimeUnit.MILLISECONDS); - } - - public static void stop() { - if (task != null) { - task.cancel(false); - } - if (executor != null) { - executor.shutdown(); - } - executor = null; - task = null; - synchronized (itemBuffer) { - itemBuffer.clear(); - } - synchronized (fluidBuffer) { - fluidBuffer.clear(); - } - } - - public static void scheduleItemUpdate(EntityPlayerMP player, List stacks) { - synchronized (itemBuffer) { - if (!itemBuffer.containsKey(player)) { - itemBuffer.put(player, new LinkedHashSet<>(1024)); - } - LinkedHashSet buffer = itemBuffer.get(player); - stacks.forEach(s -> buffer.add(s.copy())); - } - } - - public static void scheduleFluidUpdate(EntityPlayerMP player, List stacks) { - synchronized (fluidBuffer) { - if (!fluidBuffer.containsKey(player)) { - fluidBuffer.put(player, new LinkedHashSet<>(1024)); - } - LinkedHashSet buffer = fluidBuffer.get(player); - stacks.forEach(s -> buffer.add(s.copy())); - } - } - - public static void sendBuffer() { - synchronized (itemBuffer) { - itemBuffer.forEach((player, updates) -> { - if (updates.isEmpty()) return; - int i = 0; - SPacketMEItemInvUpdate packet = new SPacketMEItemInvUpdate(false); - Iterator it = updates.iterator(); - while (it.hasNext()) { - if (i < Config.packetSize) { - packet.appendItem(it.next()); - it.remove(); - i++; - } else { - FluidCraft.proxy.netHandler.sendTo(packet, player); - packet = new SPacketMEItemInvUpdate(false); - i = 0; - } - } - packet.setResort(true); - FluidCraft.proxy.netHandler.sendTo(packet, player); - }); - } - synchronized (fluidBuffer) { - fluidBuffer.forEach((player, updates) -> { - if (updates.isEmpty()) return; - int i = 0; - SPacketMEFluidInvUpdate packet = new SPacketMEFluidInvUpdate(false); - Iterator it = updates.iterator(); - while (it.hasNext()) { - if (i < Config.packetSize) { - packet.appendFluid(it.next()); - it.remove(); - i++; - } else { - FluidCraft.proxy.netHandler.sendTo(packet, player); - packet = new SPacketMEFluidInvUpdate(false); - i = 0; - } - } - packet.setResort(true); - FluidCraft.proxy.netHandler.sendTo(packet, player); - }); - - } - } - - public static void clear(EntityPlayerMP player) { - synchronized (itemBuffer) { - if (itemBuffer.containsKey(player)) { - itemBuffer.get(player).clear(); - } - } - synchronized (fluidBuffer) { - if (fluidBuffer.containsKey(player)) { - fluidBuffer.get(player).clear(); - } - } - } - - @SubscribeEvent - public void onPlayerLeave(PlayerEvent.PlayerLoggedOutEvent event) { - if (event.player instanceof EntityPlayerMP) { - clear((EntityPlayerMP) event.player); - } - } -} diff --git a/src/main/java/com/glodblock/github/network/SPacketPatternItemRenamer.java b/src/main/java/com/glodblock/github/network/SPacketPatternItemRenamer.java deleted file mode 100644 index d222cfe5..00000000 --- a/src/main/java/com/glodblock/github/network/SPacketPatternItemRenamer.java +++ /dev/null @@ -1,106 +0,0 @@ -package com.glodblock.github.network; - -import java.util.Objects; - -import javax.annotation.Nullable; - -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; - -import com.glodblock.github.client.gui.container.base.FCContainerEncodeTerminal; -import com.glodblock.github.inventory.InventoryHandler; -import com.glodblock.github.inventory.gui.GuiType; -import com.glodblock.github.inventory.item.IWirelessTerminal; -import com.glodblock.github.util.BlockPos; -import com.glodblock.github.util.Util; - -import appeng.container.ContainerOpenContext; -import appeng.container.implementations.ContainerPatternItemRenamer; -import cpw.mods.fml.common.network.simpleimpl.IMessage; -import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; -import cpw.mods.fml.common.network.simpleimpl.MessageContext; -import io.netty.buffer.ByteBuf; - -public class SPacketPatternItemRenamer implements IMessage { - - private GuiType guiType; - private String name = ""; - private int valueIndex; - - public SPacketPatternItemRenamer() {} - - public SPacketPatternItemRenamer(GuiType guiType, String text, int valIndex) { - this.guiType = guiType; - name = text; - valueIndex = valIndex; - } - - @Override - public void toBytes(ByteBuf buf) { - buf.writeByte(guiType != null ? guiType.ordinal() : 0); - buf.writeInt(valueIndex); - - buf.writeInt(name.length()); - for (int i = 0; i < name.length(); i++) { - buf.writeChar(name.charAt(i)); - } - } - - @Override - public void fromBytes(ByteBuf buf) { - guiType = GuiType.getByOrdinal(buf.readByte()); - valueIndex = buf.readInt(); - - int leName = buf.readInt(); - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < leName; i++) { - sb.append(buf.readChar()); - } - name = sb.toString(); - } - - public static class Handler implements IMessageHandler { - - @Nullable - @Override - public IMessage onMessage(SPacketPatternItemRenamer message, MessageContext ctx) { - EntityPlayerMP player = ctx.getServerHandler().playerEntity; - if (player.openContainer instanceof ContainerPatternItemRenamer cpv) { - ContainerOpenContext context = cpv.getOpenContext(); - if (context == null) { - return null; - } - TileEntity te = context.getTile(); - if (te != null) { - InventoryHandler.openGui( - player, - player.worldObj, - new BlockPos(te), - Objects.requireNonNull(context.getSide()), - message.guiType); - } else if (cpv.getTarget() instanceof IWirelessTerminal iwt) { - InventoryHandler.openGui( - player, - player.worldObj, - new BlockPos( - iwt.getInventorySlot(), - Util.GuiHelper.encodeType(0, Util.GuiHelper.GuiType.ITEM), - 0), - Objects.requireNonNull(context.getSide()), - message.guiType); - } - if (player.openContainer instanceof FCContainerEncodeTerminal) { - Slot slot = player.openContainer.getSlot(message.valueIndex); - if (slot != null && slot.getHasStack()) { - ItemStack nextStack = slot.getStack().copy(); - nextStack.setStackDisplayName(message.name); - slot.putStack(nextStack); - } - } - } - return null; - } - } -} diff --git a/src/main/java/com/glodblock/github/network/SPacketSetItemAmount.java b/src/main/java/com/glodblock/github/network/SPacketSetItemAmount.java deleted file mode 100644 index 53c18234..00000000 --- a/src/main/java/com/glodblock/github/network/SPacketSetItemAmount.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.glodblock.github.network; - -import javax.annotation.Nullable; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiScreen; - -import com.glodblock.github.client.gui.GuiPatternValueAmount; - -import cpw.mods.fml.common.network.simpleimpl.IMessage; -import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; -import cpw.mods.fml.common.network.simpleimpl.MessageContext; -import io.netty.buffer.ByteBuf; - -public class SPacketSetItemAmount implements IMessage { - - private int amount; - - public SPacketSetItemAmount() { - // NO-OP - } - - public SPacketSetItemAmount(int amount) { - this.amount = amount; - } - - @Override - public void fromBytes(ByteBuf buf) { - amount = buf.readInt(); - } - - @Override - public void toBytes(ByteBuf buf) { - buf.writeInt(amount); - } - - public static class Handler implements IMessageHandler { - - @Nullable - @Override - public IMessage onMessage(SPacketSetItemAmount message, MessageContext ctx) { - final GuiScreen gs = Minecraft.getMinecraft().currentScreen; - if (gs instanceof GuiPatternValueAmount) { - ((GuiPatternValueAmount) gs).setAmount(message.amount); - } - return null; - } - } -} diff --git a/src/main/java/com/glodblock/github/network/SPacketStringUpdate.java b/src/main/java/com/glodblock/github/network/SPacketStringUpdate.java deleted file mode 100644 index 30698892..00000000 --- a/src/main/java/com/glodblock/github/network/SPacketStringUpdate.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.glodblock.github.network; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiScreen; - -import com.glodblock.github.client.gui.GuiRenamer; - -import cpw.mods.fml.common.network.simpleimpl.IMessage; -import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; -import cpw.mods.fml.common.network.simpleimpl.MessageContext; -import io.netty.buffer.ByteBuf; - -public class SPacketStringUpdate implements IMessage { - - private String text; - private int slot; - - public SPacketStringUpdate() {} - - public SPacketStringUpdate(String text, int slot) { - this.text = text; - this.slot = slot; - } - - public SPacketStringUpdate(String text) { - this.text = text; - this.slot = 0; - } - - @Override - public void fromBytes(ByteBuf buf) { - this.slot = buf.readInt(); - int leName = buf.readInt(); - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < leName; i++) { - sb.append(buf.readChar()); - } - this.text = sb.toString(); - } - - @Override - public void toBytes(ByteBuf buf) { - buf.writeInt(this.slot); - buf.writeInt(this.text.length()); - for (int i = 0; i < this.text.length(); i++) { - buf.writeChar(this.text.charAt(i)); - } - } - - public static class Handler implements IMessageHandler { - - @Override - public IMessage onMessage(SPacketStringUpdate message, MessageContext ctx) { - final GuiScreen gs = Minecraft.getMinecraft().currentScreen; - if (gs instanceof GuiRenamer) { - ((GuiRenamer) gs).postUpdate(message.text); - } - return null; - } - } -} diff --git a/src/main/java/com/glodblock/github/network/SPacketSwitchBack.java b/src/main/java/com/glodblock/github/network/SPacketSwitchBack.java deleted file mode 100644 index 8cb61a01..00000000 --- a/src/main/java/com/glodblock/github/network/SPacketSwitchBack.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.glodblock.github.network; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiScreen; - -import com.glodblock.github.client.gui.GuiRenamer; - -import cpw.mods.fml.common.network.simpleimpl.IMessage; -import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; -import cpw.mods.fml.common.network.simpleimpl.MessageContext; -import io.netty.buffer.ByteBuf; - -public class SPacketSwitchBack implements IMessage { - - public SPacketSwitchBack() {} - - @Override - public void fromBytes(ByteBuf buf) {} - - @Override - public void toBytes(ByteBuf buf) {} - - public static class Handler implements IMessageHandler { - - @Override - public IMessage onMessage(SPacketSwitchBack message, MessageContext ctx) { - final GuiScreen gs = Minecraft.getMinecraft().currentScreen; - if (gs instanceof GuiRenamer) { - ((GuiRenamer) gs).switchGui(); - } - return null; - } - } -} diff --git a/src/main/java/com/glodblock/github/proxy/CommonProxy.java b/src/main/java/com/glodblock/github/proxy/CommonProxy.java index 2e859460..88e0e510 100644 --- a/src/main/java/com/glodblock/github/proxy/CommonProxy.java +++ b/src/main/java/com/glodblock/github/proxy/CommonProxy.java @@ -15,7 +15,6 @@ import com.glodblock.github.common.parts.PartFluidInterface; import com.glodblock.github.common.parts.PartFluidP2PInterface; import com.glodblock.github.common.tile.TileFluidInterface; import com.glodblock.github.common.tile.TileWalrus; -import com.glodblock.github.crossmod.extracells.EC2Replacer; import com.glodblock.github.crossmod.thaumcraft.AspectUtil; import com.glodblock.github.crossmod.thaumcraft.ThaumicEnergisticsCrafting; import com.glodblock.github.inventory.external.AEFluidInterfaceHandler; @@ -23,7 +22,6 @@ import com.glodblock.github.inventory.item.WirelessMagnet; import com.glodblock.github.inventory.item.WirelessMagnetCardFilterInventory; import com.glodblock.github.inventory.item.WirelessMagnetCardFilterInventory.FilterCache; import com.glodblock.github.loader.ItemAndBlockHolder; -import com.glodblock.github.network.SPacketMEUpdateBuffer; import com.glodblock.github.network.wrapper.FCNetworkWrapper; import com.glodblock.github.util.ModAndClassUtil; import com.glodblock.github.util.Util; @@ -91,16 +89,12 @@ public class CommonProxy { public void init(FMLInitializationEvent event) { this.registerMovables(); - FMLCommonHandler.instance().bus().register(new SPacketMEUpdateBuffer()); if (ModAndClassUtil.ThE) { AspectUtil.init(); } } public void postInit(FMLPostInitializationEvent event) { - if (!ModAndClassUtil.EC2 && Config.replaceEC2) { - EC2Replacer.initReplacer(); - } if (ModAndClassUtil.ThE) { ThaumicEnergisticsCrafting.postInit(); } diff --git a/src/main/java/com/glodblock/github/util/FluidPrimaryGui.java b/src/main/java/com/glodblock/github/util/FluidPrimaryGui.java new file mode 100644 index 00000000..f326f907 --- /dev/null +++ b/src/main/java/com/glodblock/github/util/FluidPrimaryGui.java @@ -0,0 +1,39 @@ +package com.glodblock.github.util; + +import java.util.Objects; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; + +import com.glodblock.github.inventory.InventoryHandler; +import com.glodblock.github.inventory.gui.GuiType; + +import appeng.container.PrimaryGui; + +public class FluidPrimaryGui extends PrimaryGui { + + public FluidPrimaryGui(Object gui, ItemStack guiIcon, TileEntity te, ForgeDirection side) { + super(gui, guiIcon, te, side); + } + + @Override + public void open(EntityPlayer p) { + if (gui instanceof GuiType gt) { + if (te != null) { + InventoryHandler.openGui(p, te.getWorldObj(), new BlockPos(te), Objects.requireNonNull(side), gt); + } else { + InventoryHandler.openGui( + p, + p.worldObj, + new BlockPos( + this.slotIndex == Integer.MIN_VALUE ? p.inventory.currentItem : this.slotIndex, + Util.GuiHelper.encodeType(0, Util.GuiHelper.GuiType.ITEM), + 0), + Objects.requireNonNull(side), + gt); + } + } + } +} diff --git a/src/main/java/com/glodblock/github/util/ModAndClassUtil.java b/src/main/java/com/glodblock/github/util/ModAndClassUtil.java index 6cdded95..7a1e3863 100644 --- a/src/main/java/com/glodblock/github/util/ModAndClassUtil.java +++ b/src/main/java/com/glodblock/github/util/ModAndClassUtil.java @@ -37,7 +37,6 @@ public final class ModAndClassUtil { public static boolean NEW_HORIZONS_CORE_MOD = false; public static boolean isV2; - public static boolean isTypeFilter; public static boolean isDoubleButton; public static boolean isSaveText; public static boolean isSearchStringTooltip; @@ -120,12 +119,6 @@ public final class ModAndClassUtil { } catch (ClassNotFoundException e) { isV2 = false; } - try { - Class filter = Class.forName("appeng.core.features.registries.ItemDisplayRegistry"); - isTypeFilter = true; - } catch (ClassNotFoundException e) { - isTypeFilter = false; - } if (Loader.isModLoaded("gregtech") && !Loader.isModLoaded("gregapi")) { try { diff --git a/src/main/java/com/glodblock/github/util/UltraTerminalModes.java b/src/main/java/com/glodblock/github/util/UltraTerminalModes.java new file mode 100644 index 00000000..d2581ed8 --- /dev/null +++ b/src/main/java/com/glodblock/github/util/UltraTerminalModes.java @@ -0,0 +1,9 @@ +package com.glodblock.github.util; + +public enum UltraTerminalModes { + CRAFTING, + PATTERN, + PATTERN_EX, + INTERFACE, + LEVEL +} diff --git a/src/main/java/com/glodblock/github/util/Util.java b/src/main/java/com/glodblock/github/util/Util.java index aa69e5bf..118a94a7 100644 --- a/src/main/java/com/glodblock/github/util/Util.java +++ b/src/main/java/com/glodblock/github/util/Util.java @@ -1,8 +1,8 @@ package com.glodblock.github.util; +import static com.glodblock.github.client.UltraTerminalButtons.restockItems; import static com.glodblock.github.common.item.ItemBaseWirelessTerminal.infinityBoosterCard; import static com.glodblock.github.common.item.ItemBaseWirelessTerminal.infinityEnergyCard; -import static com.glodblock.github.common.item.ItemBaseWirelessTerminal.restockItems; import static com.glodblock.github.util.Util.DimensionalCoordSide.hasEnergyCard; import static net.minecraft.init.Items.glass_bottle; @@ -144,6 +144,13 @@ public final class Util { return false; } + public static void toggleRestock(ItemStack is) { + if (is.getItem() instanceof ItemWirelessUltraTerminal) { + NBTTagCompound data = Platform.openNbtData(is); + data.setBoolean(restockItems, !data.getBoolean(restockItems)); + } + } + public static boolean hasInfinityBoosterCard(ItemStack is) { if (is.getItem() instanceof ItemBaseWirelessTerminal) { NBTTagCompound data = Platform.openNbtData(is); diff --git a/src/main/resources/assets/ae2fc/lang/de_DE.lang b/src/main/resources/assets/ae2fc/lang/de_DE.lang index ca0301d0..bb9d377a 100644 --- a/src/main/resources/assets/ae2fc/lang/de_DE.lang +++ b/src/main/resources/assets/ae2fc/lang/de_DE.lang @@ -18,13 +18,11 @@ item.wireless_level_terminal.name=Füllstands-Handkonsole item.wireless_fluid_pattern_terminal.name=Flüssigkeitsschablonen-Handkonsole item.wireless_interface_terminal.name=Schnittstellen-Handkonsole item.wireless_ultra_terminal.name=Universelle Handkonsole -item.wireless_ultra_terminal.WIRELESS_CRAFTING_TERMINAL.name=Universelle Handkonsole - Fertigung -item.wireless_ultra_terminal.WIRELESS_FLUID_PATTERN_TERMINAL.name=Universelle Handkonsole - Schablonen -item.wireless_ultra_terminal.WIRELESS_FLUID_TERMINAL.name=Universelle Handkonsole - Flüssigkeiten -item.wireless_ultra_terminal.WIRELESS_LEVEL_TERMINAL.name=Universelle Handkonsole - Füllstände -item.wireless_ultra_terminal.WIRELESS_ESSENTIA_TERMINAL.name=Universelle Handkonsole - Essentia -item.wireless_ultra_terminal.WIRELESS_INTERFACE_TERMINAL.name=Universelle Handkonsole - Schnittstelle -item.wireless_ultra_terminal.WIRELESS_FLUID_PATTERN_TERMINAL_EX.name=Universelle Handkonsole - Fertigungsschablone +item.wireless_ultra_terminal.CRAFTING.name=Universelle Handkonsole - Fertigung +item.wireless_ultra_terminal.PATTERN.name=Universelle Handkonsole - Schablonen +item.wireless_ultra_terminal.PATTERN_EX.name=Universelle Handkonsole - Fertigungsschablone +item.wireless_ultra_terminal.LEVEL.name=Universelle Handkonsole - Füllstände +item.wireless_ultra_terminal.INTERFACE.name=Universelle Handkonsole - Schnittstelle item.fluid_packet.name=Flüssigkeitspaket item.quantum_bridge_card.name=Quantenbrücken-Karte item.energy_card.name=Energiekarte diff --git a/src/main/resources/assets/ae2fc/lang/en_US.lang b/src/main/resources/assets/ae2fc/lang/en_US.lang index 0ffd9846..e86b999f 100644 --- a/src/main/resources/assets/ae2fc/lang/en_US.lang +++ b/src/main/resources/assets/ae2fc/lang/en_US.lang @@ -18,13 +18,11 @@ item.wireless_level_terminal.name=Wireless Level Terminal item.wireless_fluid_pattern_terminal.name=Wireless Fluid Pattern Terminal item.wireless_interface_terminal.name=Wireless Interface Terminal item.wireless_ultra_terminal.name=Universal Wireless Terminal -item.wireless_ultra_terminal.WIRELESS_CRAFTING_TERMINAL.name=Universal Wireless Terminal - Crafting -item.wireless_ultra_terminal.WIRELESS_FLUID_PATTERN_TERMINAL.name=Universal Wireless Terminal - Pattern -item.wireless_ultra_terminal.WIRELESS_FLUID_TERMINAL.name=Universal Wireless Terminal - Fluid -item.wireless_ultra_terminal.WIRELESS_LEVEL_TERMINAL.name=Universal Wireless Terminal - Level -item.wireless_ultra_terminal.WIRELESS_ESSENTIA_TERMINAL.name=Universal Wireless Terminal - Essentia -item.wireless_ultra_terminal.WIRELESS_INTERFACE_TERMINAL.name=Universal Wireless Terminal - Interface -item.wireless_ultra_terminal.WIRELESS_FLUID_PATTERN_TERMINAL_EX.name=Universal Wireless Terminal - Processing Pattern +item.wireless_ultra_terminal.CRAFTING.name=Universal Wireless Terminal - Crafting +item.wireless_ultra_terminal.PATTERN.name=Universal Wireless Terminal - Pattern +item.wireless_ultra_terminal.PATTERN_EX.name=Universal Wireless Terminal - Processing Pattern +item.wireless_ultra_terminal.LEVEL.name=Universal Wireless Terminal - Level +item.wireless_ultra_terminal.INTERFACE.name=Universal Wireless Terminal - Interface item.fluid_packet.name=Fluid Packet item.quantum_bridge_card.name=Quantum Bridge Card item.energy_card.name=Energy Card diff --git a/src/main/resources/assets/ae2fc/lang/ru_RU.lang b/src/main/resources/assets/ae2fc/lang/ru_RU.lang index 96a225bf..56d9d295 100644 --- a/src/main/resources/assets/ae2fc/lang/ru_RU.lang +++ b/src/main/resources/assets/ae2fc/lang/ru_RU.lang @@ -18,13 +18,11 @@ item.wireless_level_terminal.name=Беспроводной терминал ур item.wireless_fluid_pattern_terminal.name=Беспроводной жидкостный терминал шаблонов item.wireless_interface_terminal.name=Беспроводной терминал интерфейсов item.wireless_ultra_terminal.name=Беспроводной универсальный терминал -item.wireless_ultra_terminal.WIRELESS_CRAFTING_TERMINAL.name=Беспроводной универсальный терминал - Создание -item.wireless_ultra_terminal.WIRELESS_FLUID_PATTERN_TERMINAL.name=Беспроводной универсальный терминал - Шаблон -item.wireless_ultra_terminal.WIRELESS_FLUID_TERMINAL.name=Беспроводной универсальный терминал - Жидкость -item.wireless_ultra_terminal.WIRELESS_LEVEL_TERMINAL.name=Беспроводной универсальный терминал - Уровень -item.wireless_ultra_terminal.WIRELESS_ESSENTIA_TERMINAL.name=Беспроводной универсальный терминал - Эссенция -item.wireless_ultra_terminal.WIRELESS_INTERFACE_TERMINAL.name=Беспроводной универсальный терминал - Интерфейс -item.wireless_ultra_terminal.WIRELESS_FLUID_PATTERN_TERMINAL_EX.name=Беспроводной универсальный терминал - Шаблон обработки +item.wireless_ultra_terminal.CRAFTING.name=Беспроводной универсальный терминал - Создание +item.wireless_ultra_terminal.PATTERN.name=Беспроводной универсальный терминал - Шаблон +item.wireless_ultra_terminal.PATTERN_EX.name=Беспроводной универсальный терминал - Шаблон обработки +item.wireless_ultra_terminal.LEVEL.name=Беспроводной универсальный терминал - Уровень +item.wireless_ultra_terminal.INTERFACE.name=Беспроводной универсальный терминал - Интерфейс item.fluid_packet.name=Жидкостный пакет item.quantum_bridge_card.name=Карта квантового моста item.energy_card.name=Карта бесконечной энергии @@ -94,7 +92,7 @@ ae2fc.tooltip.fluid_auto_filler=Автоматически создаёт шаб ae2fc.tooltip.level_maintainer.Who_Am_I=Кто я? ae2fc.tooltip.level_maintainer.title=§6Статус запроса§r ae2fc.tooltip.level_maintainer.desc=Автоматически поддерживает заданное количество предметов и жидкостей в хранилище, запрашивая новые при необходимости. Должен быть подключен к МЭ сети. -ae2fc.tooltip.level_maintainer.current=Текущее состояние: +ae2fc.tooltip.level_maintainer.current=Текущее состояние: ae2fc.tooltip.level_maintainer.none=Запрос не настроен. ae2fc.tooltip.level_maintainer.idle=§aБездействие§r ae2fc.tooltip.level_maintainer.idle_desc=Поддерживатель бездействует, когда запрошенное количество уже достигнуто или если нет доступного ЦП. @@ -238,4 +236,4 @@ item.ec2placeholder.storage.physical.advanced.singularity.name=[EC2 ЗАПОЛН item.ec2placeholder.storage.physical.name=[EC2 ЗАПОЛНИТЕЛЬ] МЭ ячейка хранения item.ec2placeholder.storage.physical.void.name=[EC2 ЗАПОЛНИТЕЛЬ] МЭ пустотная ячейка хранения item.ec2placeholder.terminal.fluid.wireless.name=[EC2 ЗАПОЛНИТЕЛЬ] Беспроводной жидкостный терминал -item.ec2placeholder.terminal.universal.wireless.name=[EC2 ЗАПОЛНИТЕЛЬ] Беспроводной универсальный терминал \ No newline at end of file +item.ec2placeholder.terminal.universal.wireless.name=[EC2 ЗАПОЛНИТЕЛЬ] Беспроводной универсальный терминал diff --git a/src/main/resources/assets/ae2fc/lang/zh_CN.lang b/src/main/resources/assets/ae2fc/lang/zh_CN.lang index 9cff88b3..9f44bd22 100644 --- a/src/main/resources/assets/ae2fc/lang/zh_CN.lang +++ b/src/main/resources/assets/ae2fc/lang/zh_CN.lang @@ -15,12 +15,10 @@ item.portable_fluid_cell.name=便携流体单元 item.wireless_fluid_terminal.name=无线流体终端 item.wireless_fluid_pattern_terminal.name=无线样板终端 item.wireless_interface_terminal.name=无线接口终端 -item.wireless_ultra_terminal.WIRELESS_CRAFTING_TERMINAL.name=无线ME通用终端 - 合成 -item.wireless_ultra_terminal.WIRELESS_FLUID_PATTERN_TERMINAL.name=无线ME通用终端 - 样板 -item.wireless_ultra_terminal.WIRELESS_FLUID_TERMINAL.name=无线ME通用终端 - 流体 -item.wireless_ultra_terminal.WIRELESS_ESSENTIA_TERMINAL.name=无线ME通用终端 - 源质 -item.wireless_ultra_terminal.WIRELESS_INTERFACE_TERMINAL.name=无线ME通用终端 - 接口 -item.wireless_ultra_terminal.WIRELESS_FLUID_PATTERN_TERMINAL_EX.name=无线ME通用终端 - 增广样板 +item.wireless_ultra_terminal.CRAFTING.name=无线ME通用终端 - 合成 +item.wireless_ultra_terminal.PATTERN.name=无线ME通用终端 - 样板 +item.wireless_ultra_terminal.PATTERN_EX.name=无线ME通用终端 - 增广样板 +item.wireless_ultra_terminal.INTERFACE.name=无线ME通用终端 - 接口 item.fluid_packet.name=流体封包 item.creative_fluid_storage.name=创造ME流体存储元件 item.fluid_storage.1.name=%s1k%s-ME流体存储元件