diff --git a/gradle.properties b/gradle.properties index b0e75cb38..71564ca34 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ aechannel=stable aebuild=7 aegroup=appeng aebasename=appliedenergistics2 -trousers=omni-fixes-v45n +trousers=omni-fixes-v46 ######################################################### # Versions # diff --git a/src/main/java/appeng/client/gui/widgets/GuiCustomSlot.java b/src/main/java/appeng/client/gui/widgets/GuiCustomSlot.java index c8b2fa392..5c24b5c6b 100644 --- a/src/main/java/appeng/client/gui/widgets/GuiCustomSlot.java +++ b/src/main/java/appeng/client/gui/widgets/GuiCustomSlot.java @@ -10,9 +10,9 @@ import net.minecraft.item.ItemStack; public abstract class GuiCustomSlot extends Gui implements ITooltip { - private final int x; - private final int y; - private final int id; + protected final int x; + protected final int y; + protected final int id; public GuiCustomSlot( final int id, final int x, final int y ) { diff --git a/src/main/java/appeng/core/sync/packets/PacketTargetFluidStack.java b/src/main/java/appeng/core/sync/packets/PacketTargetFluidStack.java index 017e18338..a2477a1fc 100644 --- a/src/main/java/appeng/core/sync/packets/PacketTargetFluidStack.java +++ b/src/main/java/appeng/core/sync/packets/PacketTargetFluidStack.java @@ -19,6 +19,7 @@ package appeng.core.sync.packets; +import appeng.fluids.container.ContainerFluidInterface; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; @@ -90,5 +91,9 @@ public class PacketTargetFluidStack extends AppEngPacket { ( (ContainerFluidTerminal) player.openContainer ).setTargetStack( this.stack ); } + else if( player.openContainer instanceof ContainerFluidInterface ) + { + ( (ContainerFluidInterface) player.openContainer ).setTargetStack( this.stack ); + } } } diff --git a/src/main/java/appeng/fluids/client/gui/GuiFluidInterface.java b/src/main/java/appeng/fluids/client/gui/GuiFluidInterface.java index 14fd8742a..460dfd19a 100644 --- a/src/main/java/appeng/fluids/client/gui/GuiFluidInterface.java +++ b/src/main/java/appeng/fluids/client/gui/GuiFluidInterface.java @@ -21,6 +21,9 @@ package appeng.fluids.client.gui; import java.io.IOException; +import appeng.api.util.IConfigManager; +import appeng.client.gui.widgets.GuiCustomSlot; +import appeng.util.IConfigManagerHost; import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.player.InventoryPlayer; @@ -38,11 +41,12 @@ import appeng.fluids.helper.IFluidInterfaceHost; import appeng.fluids.util.IAEFluidTank; -public class GuiFluidInterface extends GuiUpgradeable +public class GuiFluidInterface extends GuiUpgradeable implements IConfigManagerHost { public final static int ID_BUTTON_TANK = 222; private final IFluidInterfaceHost host; + private final ContainerFluidInterface container; private GuiTabButton priority; public GuiFluidInterface( final InventoryPlayer ip, final IFluidInterfaceHost te ) @@ -50,6 +54,8 @@ public class GuiFluidInterface extends GuiUpgradeable super( new ContainerFluidInterface( ip, te ) ); this.ySize = 231; this.host = te; + ( this.container = (ContainerFluidInterface) this.inventorySlots ).setGui( this ); + } @Override @@ -62,9 +68,7 @@ public class GuiFluidInterface extends GuiUpgradeable for( int i = 0; i < DualityFluidInterface.NUMBER_OF_TANKS; ++i ) { - final GuiFluidTank guiTank = new GuiFluidTank( fluidTank, i, DualityFluidInterface.NUMBER_OF_TANKS + i, this.getGuiLeft() + 35 + 18 * i, this - .getGuiTop() + 53, 16, 68 ); - this.buttonList.add( guiTank ); + this.guiSlots.add( new GuiFluidTank( fluidTank, i, DualityFluidInterface.NUMBER_OF_TANKS + i, 36 + 18 * i, 53, 16, 68 ) ); this.guiSlots.add( new GuiFluidSlot( configFluids, i, i, 35 + 18 * i, 35 ) ); } @@ -104,9 +108,33 @@ public class GuiFluidInterface extends GuiUpgradeable } } + @Override + protected void mouseClicked( int xCoord, int yCoord, int btn ) throws IOException + { + for( GuiCustomSlot slot : this.guiSlots ) + { + if( slot instanceof GuiFluidTank ) + { + if( this.isPointInRegion( slot.xPos(), slot.yPos(), slot.getWidth(), slot.getHeight(), xCoord, yCoord ) && slot.canClick( this.mc.player ) ) + { + this.container.setTargetStack( ( (GuiFluidTank) slot ).getFluidStack() ); + slot.slotClicked( this.mc.player.inventory.getItemStack(), btn ); + return; + } + } + } + super.mouseClicked( xCoord, yCoord, btn ); + } + @Override protected boolean drawUpgrades() { return false; } + + @Override + public void updateSetting( IConfigManager manager, Enum settingName, Enum newValue ) + { + + } } diff --git a/src/main/java/appeng/fluids/client/gui/widgets/GuiFluidTank.java b/src/main/java/appeng/fluids/client/gui/widgets/GuiFluidTank.java index 5d9bad9b9..f91d79bdf 100644 --- a/src/main/java/appeng/fluids/client/gui/widgets/GuiFluidTank.java +++ b/src/main/java/appeng/fluids/client/gui/widgets/GuiFluidTank.java @@ -19,42 +19,50 @@ package appeng.fluids.client.gui.widgets; +import appeng.client.gui.widgets.GuiCustomSlot; +import appeng.core.sync.network.NetworkHandler; +import appeng.core.sync.packets.PacketInventoryAction; +import appeng.helpers.InventoryAction; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiButton; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.renderer.texture.TextureMap; +import net.minecraft.item.ItemStack; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import appeng.api.storage.data.IAEFluidStack; -import appeng.api.util.AEColor; import appeng.client.gui.widgets.ITooltip; import appeng.fluids.util.IAEFluidTank; @SideOnly( Side.CLIENT ) -public class GuiFluidTank extends GuiButton implements ITooltip +public class GuiFluidTank extends GuiCustomSlot implements ITooltip { private final IAEFluidTank tank; private final int slot; + private final int width; + private final int height; public GuiFluidTank( IAEFluidTank tank, int slot, int id, int x, int y, int w, int h ) { - super( id, x, y, w, h, "" ); + super( id, x, y ); this.tank = tank; this.slot = slot; + this.width = w; + this.height = h; } @Override - public void drawButton( final Minecraft mc, final int mouseX, final int mouseY, final float partialTicks ) + public void drawContent( Minecraft mc, int mouseX, int mouseY, float partialTicks ) { - if( this.visible ) + final IAEFluidStack fs = this.getFluidStack(); + if( fs != null ) { GlStateManager.disableBlend(); GlStateManager.disableLighting(); - drawRect( this.x, this.y, this.x + this.width, this.y + this.height, AEColor.GRAY.blackVariant | 0xFF000000 ); + //drawRect( this.x, this.y, this.x + this.width, this.y + this.height, AEColor.GRAY.blackVariant | 0xFF000000 ); final IAEFluidStack fluid = this.tank.getFluidInSlot( this.slot ); if( fluid != null && fluid.getStackSize() > 0 ) @@ -69,17 +77,16 @@ public class GuiFluidTank extends GuiButton implements ITooltip TextureAtlasSprite sprite = mc.getTextureMapBlocks().getAtlasSprite( fluid.getFluid().getStill().toString() ); final int scaledHeight = (int) ( this.height * ( (float) fluid.getStackSize() / this.tank.getTankProperties()[this.slot].getCapacity() ) ); - int iconHeightRemainder = scaledHeight % 16; + int iconHeightRemainder = scaledHeight % this.getHeight(); if( iconHeightRemainder > 0 ) { - this.drawTexturedModalRect( this.x, this.y + this.height - iconHeightRemainder, sprite, 16, iconHeightRemainder ); + this.drawTexturedModalRect( this.xPos(), this.yPos() + this.getHeight() - iconHeightRemainder, sprite, this.getWidth(), iconHeightRemainder ); } - for( int i = 0; i < scaledHeight / 16; i++ ) + for( int i = 0; i < scaledHeight / this.getHeight(); i++ ) { - this.drawTexturedModalRect( this.x, this.y + this.height - iconHeightRemainder - ( i + 1 ) * 16, sprite, 16, 16 ); + this.drawTexturedModalRect( this.xPos(), this.yPos() + this.getHeight() - iconHeightRemainder - ( i + 1 ) * 16, sprite, this.getWidth(), this.getHeight() ); } } - } } @@ -100,25 +107,25 @@ public class GuiFluidTank extends GuiButton implements ITooltip @Override public int xPos() { - return this.x - 2; + return this.x - 1; } @Override public int yPos() { - return this.y - 2; + return this.y - 1; } @Override public int getWidth() { - return this.width + 4; + return this.width; } @Override public int getHeight() { - return this.height + 4; + return this.height + 1; } @Override @@ -127,4 +134,24 @@ public class GuiFluidTank extends GuiButton implements ITooltip return true; } + public IAEFluidStack getFluidStack() + { + return this.tank.getFluidInSlot( this.slot ); + } + + @Override + public void slotClicked( ItemStack clickStack, final int mouseButton ) + { + + if( getFluidStack() != null ) + { + NetworkHandler.instance().sendToServer( new PacketInventoryAction( InventoryAction.FILL_ITEM, slot, 0 ) ); + } + else + { + NetworkHandler.instance().sendToServer( new PacketInventoryAction( InventoryAction.EMPTY_ITEM, slot, 0 ) ); + } + + } + } diff --git a/src/main/java/appeng/fluids/container/ContainerFluidInterface.java b/src/main/java/appeng/fluids/container/ContainerFluidInterface.java index 7055f2c1f..36073d25f 100644 --- a/src/main/java/appeng/fluids/container/ContainerFluidInterface.java +++ b/src/main/java/appeng/fluids/container/ContainerFluidInterface.java @@ -19,9 +19,17 @@ package appeng.fluids.container; +import javax.annotation.Nonnull; + import java.util.Collections; import java.util.Map; +import appeng.core.sync.network.NetworkHandler; +import appeng.core.sync.packets.PacketTargetFluidStack; +import appeng.fluids.util.AEFluidStack; +import appeng.helpers.InventoryAction; +import appeng.util.IConfigManagerHost; +import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.IContainerListener; @@ -33,12 +41,19 @@ import appeng.fluids.helper.FluidSyncHelper; import appeng.fluids.helper.IFluidInterfaceHost; import appeng.fluids.util.IAEFluidTank; import appeng.util.Platform; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidUtil; +import net.minecraftforge.fluids.capability.IFluidHandlerItem; -public class ContainerFluidInterface extends ContainerFluidConfigurable +public class ContainerFluidInterface extends ContainerFluidConfigurable implements IConfigManagerHost { private final DualityFluidInterface myDuality; private final FluidSyncHelper tankSync; + private IConfigManagerHost gui; + // Holds the fluid the client wishes to extract, or null for insert + private IAEFluidStack clientRequestedTargetFluid = null; public ContainerFluidInterface( final InventoryPlayer ip, final IFluidInterfaceHost te ) { @@ -60,6 +75,15 @@ public class ContainerFluidInterface extends ContainerFluidConfigurable return this.myDuality.getConfig(); } + @Override + public void updateSetting( IConfigManager manager, Enum settingName, Enum newValue ) + { + if( this.getGui() != null ) + { + this.getGui().updateSetting( manager, settingName, newValue ); + } + } + @Override public void detectAndSendChanges() { @@ -97,6 +121,126 @@ public class ContainerFluidInterface extends ContainerFluidConfigurable this.tankSync.readPacket( fluids ); } + private IConfigManagerHost getGui() + { + return this.gui; + } + + public void setGui( @Nonnull final IConfigManagerHost gui ) + { + this.gui = gui; + } + + 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 ); + + FluidStack extractableFluid = this.myDuality.getTanks().drain( stack.setStackSize( amountAllowed ).getFluidStack(), false ); + if( extractableFluid == null || extractableFluid.amount == 0 ) + { + break; + } + + int fillableAmount = fh.fill( extractableFluid, false ); + if( fillableAmount > 0 ) + { + FluidStack extractedFluid = this.myDuality.getTanks().drain( extractableFluid, true ); + fh.fill( extractedFluid, 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 ); + } + } + } + } + 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 ); + + FluidStack drainable = fh.drain( this.myDuality.getTanks().getTankProperties()[slot].getCapacity(), false ); + if( drainable != null ) + { + fh.drain( drainable, true ); + this.myDuality.getTanks().fill( drainable, 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 ); + } + + 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(); + } + @Override protected boolean supportCapacity() {