diff --git a/src/main/java/appeng/client/gui/implementations/GuiMEMonitorable.java b/src/main/java/appeng/client/gui/implementations/GuiMEMonitorable.java index 2567cac39..92483b728 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiMEMonitorable.java +++ b/src/main/java/appeng/client/gui/implementations/GuiMEMonitorable.java @@ -442,7 +442,7 @@ public class GuiMEMonitorable extends AEBaseMEGui implements ISortSource, IConfi return this.repo.hasPower(); } - int getMaxRows() { + protected int getMaxRows() { return AEConfig.instance().getConfigManager().getSetting(Settings.TERMINAL_STYLE) == TerminalStyle.SMALL ? 6 : Integer.MAX_VALUE; } diff --git a/src/main/java/appeng/client/gui/implementations/GuiMEPortableCell.java b/src/main/java/appeng/client/gui/implementations/GuiMEPortableCell.java index 697a7e80b..14346c274 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiMEPortableCell.java +++ b/src/main/java/appeng/client/gui/implementations/GuiMEPortableCell.java @@ -35,7 +35,7 @@ public class GuiMEPortableCell extends GuiMEMonitorable { } @Override - int getMaxRows() { + protected int getMaxRows() { return 3; } } diff --git a/src/main/java/appeng/client/gui/implementations/GuiWirelessTerm.java b/src/main/java/appeng/client/gui/implementations/GuiWirelessTerm.java index c9a9b968b..a0bd8813c 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiWirelessTerm.java +++ b/src/main/java/appeng/client/gui/implementations/GuiWirelessTerm.java @@ -30,7 +30,7 @@ public class GuiWirelessTerm extends GuiMEPortableCell { } @Override - int getMaxRows() { + protected int getMaxRows() { return this.defaultGetMaxRows(); } } diff --git a/src/main/java/appeng/core/sync/packets/PacketMEFluidInventoryUpdate.java b/src/main/java/appeng/core/sync/packets/PacketMEFluidInventoryUpdate.java index 8b2110fff..330935658 100644 --- a/src/main/java/appeng/core/sync/packets/PacketMEFluidInventoryUpdate.java +++ b/src/main/java/appeng/core/sync/packets/PacketMEFluidInventoryUpdate.java @@ -24,6 +24,7 @@ import appeng.core.AELog; import appeng.core.sync.AppEngPacket; import appeng.core.sync.network.INetworkInfo; import appeng.fluids.client.gui.GuiFluidTerminal; +import appeng.fluids.client.gui.GuiWirelessFluidTerminal; import appeng.fluids.util.AEFluidStack; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; @@ -138,6 +139,8 @@ public class PacketMEFluidInventoryUpdate extends AppEngPacket { if (gs instanceof GuiFluidTerminal) { ((GuiFluidTerminal) gs).postUpdate(this.list); + } else if (gs instanceof GuiWirelessFluidTerminal) { + ((GuiWirelessFluidTerminal)gs).postUpdate(this.list); } } diff --git a/src/main/java/appeng/core/sync/packets/PacketTargetFluidStack.java b/src/main/java/appeng/core/sync/packets/PacketTargetFluidStack.java index 35d888226..94b7476ef 100644 --- a/src/main/java/appeng/core/sync/packets/PacketTargetFluidStack.java +++ b/src/main/java/appeng/core/sync/packets/PacketTargetFluidStack.java @@ -25,6 +25,7 @@ import appeng.core.sync.AppEngPacket; import appeng.core.sync.network.INetworkInfo; import appeng.fluids.container.ContainerFluidInterface; import appeng.fluids.container.ContainerFluidTerminal; +import appeng.fluids.container.ContainerWirelessFluidTerminal; import appeng.fluids.util.AEFluidStack; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; @@ -74,6 +75,8 @@ public class PacketTargetFluidStack extends AppEngPacket { public void serverPacketData(final INetworkInfo manager, final AppEngPacket packet, final EntityPlayer player) { if (player.openContainer instanceof ContainerFluidTerminal) { ((ContainerFluidTerminal) player.openContainer).setTargetStack(this.stack); + } else if (player.openContainer instanceof ContainerWirelessFluidTerminal) { + ((ContainerWirelessFluidTerminal) player.openContainer).setTargetStack(this.stack); } else if (player.openContainer instanceof ContainerFluidInterface) { ((ContainerFluidInterface) player.openContainer).setTargetStack(this.stack); } else if (player.openContainer instanceof ContainerFluidInterfaceConfigurationTerminal) { diff --git a/src/main/java/appeng/fluids/client/gui/GuiMEPortableFluidCell.java b/src/main/java/appeng/fluids/client/gui/GuiMEPortableFluidCell.java new file mode 100644 index 000000000..3660f1f42 --- /dev/null +++ b/src/main/java/appeng/fluids/client/gui/GuiMEPortableFluidCell.java @@ -0,0 +1,311 @@ +/* + * 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 appeng.fluids.client.gui; + + +import appeng.api.config.Settings; +import appeng.api.storage.ITerminalHost; +import appeng.api.storage.data.IAEFluidStack; +import appeng.api.util.IConfigManager; +import appeng.api.util.IConfigurableObject; +import appeng.client.gui.AEBaseMEGui; +import appeng.client.gui.widgets.GuiImgButton; +import appeng.client.gui.widgets.GuiScrollbar; +import appeng.client.gui.widgets.ISortSource; +import appeng.client.gui.widgets.MEGuiTextField; +import appeng.client.me.FluidRepo; +import appeng.client.me.InternalFluidSlotME; +import appeng.client.me.SlotFluidME; +import appeng.core.AELog; +import appeng.core.localization.GuiText; +import appeng.core.sync.network.NetworkHandler; +import appeng.core.sync.packets.PacketInventoryAction; +import appeng.core.sync.packets.PacketValueConfig; +import appeng.fluids.container.ContainerMEPortableFluidCell; +import appeng.fluids.container.ContainerWirelessFluidTerminal; +import appeng.fluids.container.slots.IMEFluidSlot; +import appeng.helpers.InventoryAction; +import appeng.helpers.WirelessTerminalGuiObject; +import appeng.util.IConfigManagerHost; +import appeng.util.Platform; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.ClickType; +import net.minecraft.inventory.Slot; +import net.minecraft.util.text.TextFormatting; +import net.minecraftforge.fml.common.Loader; +import org.lwjgl.input.Mouse; + +import javax.annotation.Nonnull; +import java.io.IOException; +import java.text.NumberFormat; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Locale; + + +public class GuiMEPortableFluidCell extends AEBaseMEGui implements ISortSource, IConfigManagerHost { + private final List meFluidSlots = new LinkedList<>(); + private final FluidRepo repo; + private final IConfigManager configSrc; + private final ContainerMEPortableFluidCell container; + private final int offsetX = 9; + private final int rows = 6; + private final int perRow = 9; + + protected ITerminalHost terminal; + + private MEGuiTextField searchField; + private GuiImgButton sortByBox; + private GuiImgButton sortDirBox; + + public GuiMEPortableFluidCell(InventoryPlayer inventoryPlayer, final WirelessTerminalGuiObject te, final ContainerWirelessFluidTerminal c) { + super(c); + this.terminal = te; + this.xSize = 185; + this.ySize = 222; + final GuiScrollbar scrollbar = new GuiScrollbar(); + this.setScrollBar(scrollbar); + this.repo = new FluidRepo(scrollbar, this); + this.configSrc = ((IConfigurableObject) this.inventorySlots).getConfigManager(); + (this.container = (ContainerMEPortableFluidCell) this.inventorySlots).setGui(this); + } + + @Override + public void initGui() { + this.mc.player.openContainer = this.inventorySlots; + this.guiLeft = (this.width - this.xSize) / 2; + this.guiTop = (this.height - this.ySize) / 2; + + this.searchField = new MEGuiTextField(this.fontRenderer, this.guiLeft + Math.max(80, this.offsetX), this.guiTop + 4, 90, 12); + this.searchField.setEnableBackgroundDrawing(false); + this.searchField.setMaxStringLength(25); + this.searchField.setTextColor(0xFFFFFF); + this.searchField.setSelectionColor(0xFF99FF99); + this.searchField.setVisible(true); + + int offset = this.guiTop; + + this.buttonList.add(this.sortByBox = new GuiImgButton(this.guiLeft - 18, offset, Settings.SORT_BY, this.configSrc.getSetting(Settings.SORT_BY))); + offset += 20; + + this.buttonList.add(this.sortDirBox = new GuiImgButton(this.guiLeft - 18, offset, Settings.SORT_DIRECTION, this.configSrc + .getSetting(Settings.SORT_DIRECTION))); + + for (int y = 0; y < this.rows; y++) { + for (int x = 0; x < this.perRow; x++) { + SlotFluidME slot = new SlotFluidME(new InternalFluidSlotME(this.repo, x + y * this.perRow, this.offsetX + x * 18, 18 + y * 18)); + this.getMeFluidSlots().add(slot); + this.inventorySlots.inventorySlots.add(slot); + } + } + this.setScrollBar(); + } + + @Override + public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) { + this.fontRenderer.drawString(this.getGuiDisplayName("Fluid Terminal"), 8, 6, 4210752); + this.fontRenderer.drawString(GuiText.inventory.getLocal(), 8, this.ySize - 96 + 3, 4210752); + } + + @Override + public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) { + this.bindTexture(this.getBackground()); + final int x_width = 197; + this.drawTexturedModalRect(offsetX, offsetY, 0, 0, x_width, 18); + + for (int x = 0; x < 6; x++) { + this.drawTexturedModalRect(offsetX, offsetY + 18 + x * 18, 0, 18, x_width, 18); + } + + this.drawTexturedModalRect(offsetX, offsetY + 16 + 6 * 18, 0, 106 - 18 - 18, x_width, 99 + 77); + + if (this.searchField != null) { + this.searchField.drawTextBox(); + } + } + + @Override + public void updateScreen() { + this.repo.setPower(this.container.isPowered()); + super.updateScreen(); + } + + @Override + protected void renderHoveredToolTip(int mouseX, int mouseY) { + final Slot slot = this.getSlot(mouseX, mouseY); + + if (slot != null && slot instanceof IMEFluidSlot && slot.isEnabled()) { + final IMEFluidSlot fluidSlot = (IMEFluidSlot) slot; + + if (fluidSlot.getAEFluidStack() != null && fluidSlot.shouldRenderAsFluid()) { + final IAEFluidStack fluidStack = fluidSlot.getAEFluidStack(); + final String formattedAmount = NumberFormat.getNumberInstance(Locale.US).format(fluidStack.getStackSize() / 1000.0) + " B"; + + final String modName = "" + TextFormatting.BLUE + TextFormatting.ITALIC + Loader.instance() + .getIndexedModList() + .get(Platform.getModId(fluidStack)) + .getName(); + + final List list = new ArrayList<>(); + + list.add(fluidStack.getFluidStack().getLocalizedName()); + list.add(formattedAmount); + list.add(modName); + + this.drawHoveringText(list, mouseX, mouseY); + + return; + } + } + super.renderHoveredToolTip(mouseX, mouseY); + } + + @Override + protected void actionPerformed(GuiButton btn) throws IOException { + if (btn instanceof GuiImgButton) { + final boolean backwards = Mouse.isButtonDown(1); + final GuiImgButton iBtn = (GuiImgButton) btn; + + if (iBtn.getSetting() != Settings.ACTIONS) { + final Enum cv = iBtn.getCurrentValue(); + final Enum next = Platform.rotateEnum(cv, backwards, iBtn.getSetting().getPossibleValues()); + + try { + NetworkHandler.instance().sendToServer(new PacketValueConfig(iBtn.getSetting().name(), next.name())); + } catch (final IOException e) { + AELog.debug(e); + } + + iBtn.set(next); + } + } + } + + @Override + protected void handleMouseClick(Slot slot, int slotIdx, int mouseButton, ClickType clickType) { + if (slot instanceof SlotFluidME) { + final SlotFluidME meSlot = (SlotFluidME) slot; + + if (clickType == ClickType.PICKUP) { + // TODO: Allow more options + if (mouseButton == 0 && meSlot.getHasStack()) { + this.container.setTargetStack(meSlot.getAEFluidStack()); + AELog.debug("mouse0 GUI STACK SIZE %s", meSlot.getAEFluidStack().getStackSize()); + NetworkHandler.instance().sendToServer(new PacketInventoryAction(InventoryAction.FILL_ITEM, slot.slotNumber, 0)); + } else { + this.container.setTargetStack(meSlot.getAEFluidStack()); + if (meSlot.getAEFluidStack() != null) { + AELog.debug("mouse1 GUI STACK SIZE %s", meSlot.getAEFluidStack().getStackSize()); + } + NetworkHandler.instance().sendToServer(new PacketInventoryAction(InventoryAction.EMPTY_ITEM, slot.slotNumber, 0)); + } + } + return; + } + super.handleMouseClick(slot, slotIdx, mouseButton, clickType); + } + + @Override + protected void keyTyped(final char character, final int key) throws IOException { + if (!this.checkHotbarKeys(key)) { + if (character == ' ' && this.searchField.getText().isEmpty()) { + return; + } + + if (this.searchField.textboxKeyTyped(character, key)) { + this.repo.setSearchString(this.searchField.getText()); + this.repo.updateView(); + this.setScrollBar(); + } else { + super.keyTyped(character, key); + } + } + } + + @Override + protected void mouseClicked(final int xCoord, final int yCoord, final int btn) throws IOException { + this.searchField.mouseClicked(xCoord, yCoord, btn); + + if (btn == 1 && this.searchField.isMouseIn(xCoord, yCoord)) { + this.searchField.setText(""); + this.repo.setSearchString(""); + this.repo.updateView(); + this.setScrollBar(); + } + + super.mouseClicked(xCoord, yCoord, btn); + } + + public void postUpdate(final List list) { + for (final IAEFluidStack is : list) { + this.repo.postUpdate(is); + } + + this.repo.updateView(); + this.setScrollBar(); + } + + private void setScrollBar() { + this.getScrollBar().setTop(18).setLeft(175).setHeight(this.rows * 18 - 2); + this.getScrollBar().setRange(0, (this.repo.size() + this.perRow - 1) / this.perRow - this.rows, Math.max(1, this.rows / 6)); + } + + @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 void updateSetting(IConfigManager manager, Enum settingName, 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)); + } + + this.repo.updateView(); + } + + protected List getMeFluidSlots() { + return this.meFluidSlots; + } + + @Override + protected boolean isPowered() { + return this.repo.hasPower(); + } + + protected String getBackground() { + return "guis/terminal.png"; + } +} diff --git a/src/main/java/appeng/client/gui/implementations/GuiWirelessFluidTerminal.java b/src/main/java/appeng/fluids/client/gui/GuiWirelessFluidTerminal.java similarity index 73% rename from src/main/java/appeng/client/gui/implementations/GuiWirelessFluidTerminal.java rename to src/main/java/appeng/fluids/client/gui/GuiWirelessFluidTerminal.java index 2c2641eec..bd3dc0882 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiWirelessFluidTerminal.java +++ b/src/main/java/appeng/fluids/client/gui/GuiWirelessFluidTerminal.java @@ -16,21 +16,18 @@ * along with Applied Energistics 2. If not, see . */ -package appeng.client.gui.implementations; +package appeng.fluids.client.gui; import appeng.api.implementations.guiobjects.IPortableCell; +import appeng.fluids.container.ContainerWirelessFluidTerminal; +import appeng.helpers.WirelessTerminalGuiObject; import net.minecraft.entity.player.InventoryPlayer; -public class GuiWirelessFluidTerminal extends GuiMEPortableCell { +public class GuiWirelessFluidTerminal extends GuiMEPortableFluidCell { - public GuiWirelessFluidTerminal(final InventoryPlayer inventoryPlayer, final IPortableCell te) { - super(inventoryPlayer, te); - } - - @Override - int getMaxRows() { - return this.defaultGetMaxRows(); + public GuiWirelessFluidTerminal(final InventoryPlayer inventoryPlayer, final WirelessTerminalGuiObject te) { + super(inventoryPlayer, te, new ContainerWirelessFluidTerminal(inventoryPlayer, te)); } } diff --git a/src/main/java/appeng/fluids/container/ContainerMEPortableFluidCell.java b/src/main/java/appeng/fluids/container/ContainerMEPortableFluidCell.java new file mode 100644 index 000000000..840ff03a1 --- /dev/null +++ b/src/main/java/appeng/fluids/container/ContainerMEPortableFluidCell.java @@ -0,0 +1,518 @@ +package appeng.fluids.container; + +import appeng.api.AEApi; +import appeng.api.config.*; +import appeng.api.implementations.guiobjects.IPortableCell; +import appeng.api.networking.IGridHost; +import appeng.api.networking.IGridNode; +import appeng.api.networking.energy.IEnergySource; +import appeng.api.networking.security.IActionHost; +import appeng.api.networking.security.IActionSource; +import appeng.api.networking.storage.IBaseMonitor; +import appeng.api.storage.IMEMonitor; +import appeng.api.storage.IMEMonitorHandlerReceiver; +import appeng.api.storage.ITerminalHost; +import appeng.api.storage.channels.IFluidStorageChannel; +import appeng.api.storage.data.IAEFluidStack; +import appeng.api.storage.data.IItemList; +import appeng.api.util.AEPartLocation; +import appeng.api.util.IConfigManager; +import appeng.api.util.IConfigurableObject; +import appeng.container.AEBaseContainer; +import appeng.container.guisync.GuiSync; +import appeng.container.interfaces.IInventorySlotAware; +import appeng.container.slot.AppEngSlot; +import appeng.container.slot.SlotPlayerHotBar; +import appeng.container.slot.SlotPlayerInv; +import appeng.core.AEConfig; +import appeng.core.AELog; +import appeng.core.localization.PlayerMessages; +import appeng.core.sync.network.NetworkHandler; +import appeng.core.sync.packets.PacketMEFluidInventoryUpdate; +import appeng.core.sync.packets.PacketTargetFluidStack; +import appeng.core.sync.packets.PacketValueConfig; +import appeng.fluids.util.AEFluidStack; +import appeng.helpers.InventoryAction; +import appeng.helpers.WirelessTerminalGuiObject; +import appeng.util.ConfigManager; +import appeng.util.IConfigManagerHost; +import appeng.util.Platform; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.IContainerListener; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidUtil; +import net.minecraftforge.fluids.capability.IFluidHandlerItem; + +import javax.annotation.Nonnull; +import java.io.IOException; +import java.nio.BufferOverflowException; + +public class ContainerMEPortableFluidCell extends AEBaseContainer implements IConfigManagerHost, IConfigurableObject, IMEMonitorHandlerReceiver { + + private final WirelessTerminalGuiObject wirelessTerminalGUIObject; + + private final IConfigManager clientCM; + private final IMEMonitor monitor; + private final IItemList fluids = AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class).createList(); + @GuiSync(99) + public boolean hasPower = false; + private final ITerminalHost terminal; + private IConfigManager serverCM; + private IConfigManagerHost gui; + private IGridNode networkNode; + // Holds the fluid the client wishes to extract, or null for insert + private IAEFluidStack clientRequestedTargetFluid = null; + private double powerMultiplier = 0.5; + + protected final IPortableCell civ; + private int ticks = 0; + private final int slot; + + public ContainerMEPortableFluidCell(final InventoryPlayer ip, final IPortableCell monitorable) { + this(ip, monitorable, null, true); + } + + public ContainerMEPortableFluidCell(final InventoryPlayer ip, final IPortableCell monitorable, WirelessTerminalGuiObject iGuiItemObject) { + this(ip, monitorable, iGuiItemObject, true); + } + + public ContainerMEPortableFluidCell(InventoryPlayer ip, IPortableCell monitorable, WirelessTerminalGuiObject iGuiItemObject, boolean bindInventory) { + super(ip, monitorable); + + this.terminal = monitorable; + this.wirelessTerminalGUIObject = (WirelessTerminalGuiObject) monitorable; + + this.clientCM = new ConfigManager(this); + + this.clientCM.registerSetting(Settings.SORT_BY, SortOrder.NAME); + this.clientCM.registerSetting(Settings.SORT_DIRECTION, SortDir.ASCENDING); + this.clientCM.registerSetting(Settings.VIEW_MODE, ViewItems.ALL); + if (Platform.isServer()) { + this.serverCM = terminal.getConfigManager(); + this.monitor = terminal.getInventory(AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class)); + + if (this.monitor != null) { + this.monitor.addListener(this, null); + + this.setPowerSource((IEnergySource) terminal); + if (terminal instanceof IGridHost || terminal instanceof IActionHost) { + final IGridNode node; + if (terminal instanceof IGridHost) { + node = ((IGridHost) terminal).getGridNode(AEPartLocation.INTERNAL); + } else { + node = ((IActionHost) terminal).getActionableNode(); + } + + if (node != null) { + this.networkNode = node; + } + } + } + } else { + this.monitor = null; + } + + if (monitorable instanceof IInventorySlotAware) { + final int slotIndex = ((IInventorySlotAware) monitorable).getInventorySlot(); + this.lockPlayerInventorySlot(slotIndex); + this.slot = slotIndex; + } else { + this.slot = -1; + this.lockPlayerInventorySlot(ip.currentItem); + } + this.civ = monitorable; + if (bindInventory) { + this.bindPlayerInventory(ip, 0, 140); + } + hasPower = this.civ.extractAEPower(this.getPowerMultiplier(), Actionable.SIMULATE, PowerMultiplier.CONFIG) > 0.001; + + } + + @Override + public void detectAndSendChanges() { + final ItemStack currentItem = this.slot < 0 ? this.getPlayerInv().getCurrentItem() : this.getPlayerInv().getStackInSlot(this.slot); + + if (this.civ == null || currentItem.isEmpty()) { + this.setValidContainer(false); + } else if (this.civ != null && !this.civ.getItemStack().isEmpty() && currentItem != this.civ.getItemStack()) { + if (ItemStack.areItemsEqual(this.civ.getItemStack(), currentItem)) { + this.getPlayerInv().setInventorySlotContents(this.getPlayerInv().currentItem, this.civ.getItemStack()); + } else { + this.setValidContainer(false); + } + } + + // drain 1 ae t + this.ticks++; + if (this.ticks > 10) { + double power = this.civ.extractAEPower(this.getPowerMultiplier() * this.ticks, Actionable.MODULATE, PowerMultiplier.CONFIG); + this.ticks = 0; + this.hasPower = power > 0.001; + } + + if (!this.wirelessTerminalGUIObject.rangeCheck()) { + if (Platform.isServer() && this.isValidContainer()) { + this.getPlayerInv().player.sendMessage(PlayerMessages.OutOfRange.get()); + } + + this.setValidContainer(false); + } else { + this.setPowerMultiplier(AEConfig.instance().wireless_getDrainRate(this.wirelessTerminalGUIObject.getRange())); + } + if (Platform.isServer()) { + if (this.monitor != this.terminal.getInventory(AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class))) { + this.setValidContainer(false); + } + + 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 IContainerListener crafter : this.listeners) { + if (crafter instanceof EntityPlayerMP) { + try { + NetworkHandler.instance().sendTo(new PacketValueConfig(set.name(), sideLocal.name()), (EntityPlayerMP) crafter); + } catch (final IOException e) { + AELog.debug(e); + } + } + } + } + } + + if (!this.fluids.isEmpty()) { + try { + final IItemList monitorCache = this.monitor.getStorageList(); + + final PacketMEFluidInventoryUpdate piu = new PacketMEFluidInventoryUpdate(); + + for (final IAEFluidStack is : this.fluids) { + final IAEFluidStack send = monitorCache.findPrecise(is); + if (send == null) { + is.setStackSize(0); + piu.appendFluid(is); + } else { + piu.appendFluid(send); + } + } + + if (!piu.isEmpty()) { + this.fluids.resetStatus(); + + for (final Object c : this.listeners) { + if (c instanceof EntityPlayer) { + NetworkHandler.instance().sendTo(piu, (EntityPlayerMP) c); + } + } + } + } catch (final IOException e) { + AELog.debug(e); + } + } + //this.updatePowerStatus(); + + } + super.detectAndSendChanges(); + } + + @Override + public ItemStack transferStackInSlot(final EntityPlayer p, final int idx) { + if (Platform.isClient()) { + return ItemStack.EMPTY; + } + EntityPlayerMP player = (EntityPlayerMP) p; + if (this.inventorySlots.get(idx) instanceof SlotPlayerInv || this.inventorySlots.get(idx) instanceof SlotPlayerHotBar) { + final AppEngSlot clickSlot = (AppEngSlot) this.inventorySlots.get(idx); // require AE SLots! + ItemStack itemStack = clickSlot.getStack(); + + ItemStack copy = itemStack.copy(); + copy.setCount(1); + IFluidHandlerItem fh = FluidUtil.getFluidHandler(copy); + if (fh == null) { + // only fluid handlers items + return ItemStack.EMPTY; + } + + int heldAmount = itemStack.getCount(); + for (int i = 0; i < heldAmount; i++) { + copy = itemStack.copy(); + copy.setCount(1); + fh = FluidUtil.getFluidHandler(copy); + + final FluidStack extract = fh.drain(Integer.MAX_VALUE, false); + if (extract == null || extract.amount < 1) { + return ItemStack.EMPTY; + } + + // Check if we can push into the system + final IAEFluidStack notStorable = Platform.poweredInsert(this.getPowerSource(), this.monitor, AEFluidStack.fromFluidStack(extract), this.getActionSource(), Actionable.SIMULATE); + + if (notStorable != null && notStorable.getStackSize() > 0) { + final int toStore = (int) (extract.amount - notStorable.getStackSize()); + final FluidStack storable = fh.drain(toStore, false); + + if (storable == null || storable.amount == 0) { + return ItemStack.EMPTY; + } else { + extract.amount = storable.amount; + } + } + + // Actually drain + final FluidStack drained = fh.drain(extract, true); + extract.amount = drained.amount; + + final IAEFluidStack notInserted = Platform.poweredInsert(this.getPowerSource(), this.monitor, AEFluidStack.fromFluidStack(extract), this.getActionSource()); + + if (notInserted != null && notInserted.getStackSize() > 0) { + IAEFluidStack spill = this.monitor.injectItems(notInserted, Actionable.MODULATE, this.getActionSource()); + if (spill != null && spill.getStackSize() > 0) { + fh.fill(spill.getFluidStack(), true); + } + } + + if (notInserted == null || notInserted.getStackSize() == 0) { + if (!player.inventory.addItemStackToInventory(fh.getContainer())) { + player.dropItem(fh.getContainer(), false); + } + clickSlot.decrStackSize(1); + } + } + this.detectAndSendChanges(); + return ItemStack.EMPTY; + } + return super.transferStackInSlot(p, idx); + } + + @Override + public void doAction(EntityPlayerMP player, InventoryAction action, int slot, long id) { + if (action != InventoryAction.FILL_ITEM && action != InventoryAction.EMPTY_ITEM) { + super.doAction(player, action, slot, id); + return; + } + + final ItemStack held = player.inventory.getItemStack(); + ItemStack heldCopy = held.copy(); + heldCopy.setCount(1); + IFluidHandlerItem fh = FluidUtil.getFluidHandler(heldCopy); + if (fh == null) { + // only fluid handlers items + return; + } + + if (action == InventoryAction.FILL_ITEM && this.clientRequestedTargetFluid != null) { + final IAEFluidStack stack = this.clientRequestedTargetFluid.copy(); + + // Check how much we can store in the item + stack.setStackSize(Integer.MAX_VALUE); + int amountAllowed = fh.fill(stack.getFluidStack(), false); + int heldAmount = held.getCount(); + for (int i = 0; i < heldAmount; i++) { + ItemStack copiedFluidContainer = held.copy(); + copiedFluidContainer.setCount(1); + fh = FluidUtil.getFluidHandler(copiedFluidContainer); + + // Check if we can pull out of the system + final IAEFluidStack canPull = Platform.poweredExtraction(this.getPowerSource(), this.monitor, stack.setStackSize(amountAllowed), this.getActionSource(), Actionable.SIMULATE); + if (canPull == null || canPull.getStackSize() < 1) { + return; + } + + // How much could fit into the container + final int canFill = fh.fill(canPull.getFluidStack(), false); + if (canFill == 0) { + return; + } + + // Now actually pull out of the system + final IAEFluidStack pulled = Platform.poweredExtraction(this.getPowerSource(), this.monitor, stack.setStackSize(canFill), this.getActionSource()); + if (pulled == null || pulled.getStackSize() < 1) { + // Something went wrong + AELog.error("Unable to pull fluid out of the ME system even though the simulation said yes "); + return; + } + + // Actually fill + final int used = fh.fill(pulled.getFluidStack(), true); + + if (used != canFill) { + AELog.error("Fluid item [%s] reported a different possible amount than it actually accepted.", held.getDisplayName()); + } + + if (held.getCount() == 1) { + player.inventory.setItemStack(fh.getContainer()); + } else { + player.inventory.getItemStack().shrink(1); + if (!player.inventory.addItemStackToInventory(fh.getContainer())) { + player.dropItem(fh.getContainer(), false); + } + } + } + this.updateHeld(player); + + } else if (action == InventoryAction.EMPTY_ITEM) { + int heldAmount = held.getCount(); + for (int i = 0; i < heldAmount; i++) { + ItemStack copiedFluidContainer = held.copy(); + copiedFluidContainer.setCount(1); + fh = FluidUtil.getFluidHandler(copiedFluidContainer); + + // See how much we can drain from the item + final FluidStack extract = fh.drain(Integer.MAX_VALUE, false); + if (extract == null || extract.amount < 1) { + return; + } + + // Check if we can push into the system + final IAEFluidStack notStorable = Platform.poweredInsert(this.getPowerSource(), this.monitor, AEFluidStack.fromFluidStack(extract), this.getActionSource(), Actionable.SIMULATE); + + if (notStorable != null && notStorable.getStackSize() > 0) { + final int toStore = (int) (extract.amount - notStorable.getStackSize()); + final FluidStack storable = fh.drain(toStore, false); + + if (storable == null || storable.amount == 0) { + return; + } else { + extract.amount = storable.amount; + } + } + + // Actually drain + final FluidStack drained = fh.drain(extract, true); + extract.amount = drained.amount; + + final IAEFluidStack notInserted = Platform.poweredInsert(this.getPowerSource(), this.monitor, AEFluidStack.fromFluidStack(extract), this.getActionSource()); + + if (notInserted != null && notInserted.getStackSize() > 0) { + IAEFluidStack spill = this.monitor.injectItems(notInserted, Actionable.MODULATE, this.getActionSource()); + if (spill != null && spill.getStackSize() > 0) { + fh.fill(spill.getFluidStack(), true); + } + } + + if (held.getCount() == 1) { + player.inventory.setItemStack(fh.getContainer()); + } else { + player.inventory.getItemStack().shrink(1); + if (!player.inventory.addItemStackToInventory(fh.getContainer())) { + player.dropItem(fh.getContainer(), false); + } + } + } + this.updateHeld(player); + } + } + + private double getPowerMultiplier() { + return this.powerMultiplier; + } + + void setPowerMultiplier(final double powerMultiplier) { + this.powerMultiplier = powerMultiplier; + } + + public boolean isValid(Object verificationToken) { + return true; + } + + + @Override + public void postChange(IBaseMonitor monitor, Iterable change, IActionSource actionSource) { + for (final IAEFluidStack is : change) { + this.fluids.add(is); + } + } + + @Override + public void onListUpdate() { + for (final IContainerListener c : this.listeners) { + this.queueInventory(c); + } + } + + @Override + public void addListener(IContainerListener listener) { + super.addListener(listener); + + this.queueInventory(listener); + } + + @Override + public void onContainerClosed(final EntityPlayer player) { + super.onContainerClosed(player); + if (this.monitor != null) { + this.monitor.removeListener(this); + } + } + + private void queueInventory(final IContainerListener c) { + if (Platform.isServer() && c instanceof EntityPlayer && this.monitor != null) { + try { + PacketMEFluidInventoryUpdate piu = new PacketMEFluidInventoryUpdate(); + final IItemList monitorCache = this.monitor.getStorageList(); + + for (final IAEFluidStack send : monitorCache) { + try { + piu.appendFluid(send); + } catch (final BufferOverflowException boe) { + NetworkHandler.instance().sendTo(piu, (EntityPlayerMP) c); + + piu = new PacketMEFluidInventoryUpdate(); + piu.appendFluid(send); + } + } + + NetworkHandler.instance().sendTo(piu, (EntityPlayerMP) c); + } catch (final IOException e) { + AELog.debug(e); + } + } + } + + @Override + public IConfigManager getConfigManager() { + if (Platform.isServer()) { + return this.serverCM; + } + return this.clientCM; + } + + @Override + public void updateSetting(IConfigManager manager, Enum settingName, Enum newValue) { + if (this.getGui() != null) { + this.getGui().updateSetting(manager, settingName, newValue); + } + } + + public void setTargetStack(final IAEFluidStack stack) { + if (Platform.isClient()) { + if (stack == null && this.clientRequestedTargetFluid == null) { + return; + } + if (stack != null && this.clientRequestedTargetFluid != null && stack.getFluidStack() + .isFluidEqual(this.clientRequestedTargetFluid.getFluidStack())) { + return; + } + NetworkHandler.instance().sendToServer(new PacketTargetFluidStack((AEFluidStack) stack)); + } + + this.clientRequestedTargetFluid = stack == null ? null : stack.copy(); + } + + private IConfigManagerHost getGui() { + return this.gui; + } + + public boolean isPowered() { + return this.hasPower; + } + + public void setGui(@Nonnull final IConfigManagerHost gui) { + this.gui = gui; + } +} diff --git a/src/main/java/appeng/container/implementations/ContainerWirelessFluidTerminal.java b/src/main/java/appeng/fluids/container/ContainerWirelessFluidTerminal.java similarity index 94% rename from src/main/java/appeng/container/implementations/ContainerWirelessFluidTerminal.java rename to src/main/java/appeng/fluids/container/ContainerWirelessFluidTerminal.java index 96acd8d42..26f5497fb 100644 --- a/src/main/java/appeng/container/implementations/ContainerWirelessFluidTerminal.java +++ b/src/main/java/appeng/fluids/container/ContainerWirelessFluidTerminal.java @@ -16,9 +16,10 @@ * along with Applied Energistics 2. If not, see . */ -package appeng.container.implementations; +package appeng.fluids.container; +import appeng.container.implementations.ContainerMEPortableCell; import appeng.core.AEConfig; import appeng.core.localization.PlayerMessages; import appeng.helpers.WirelessTerminalGuiObject; @@ -26,7 +27,7 @@ import appeng.util.Platform; import net.minecraft.entity.player.InventoryPlayer; -public class ContainerWirelessFluidTerminal extends ContainerMEPortableCell { +public class ContainerWirelessFluidTerminal extends ContainerMEPortableFluidCell { private final WirelessTerminalGuiObject wirelessTerminalGUIObject;