mirror of
https://github.com/GTNewHorizons/AE2FluidCraft-Rework.git
synced 2026-11-17 10:55:06 +00:00
native fluid io bus
This commit is contained in:
1 parent
a548d3094d
commit
a053b51b57
23 files changed
+1038
No files matched your search
@@ -0,0 +1,32 @@
|
||||
package com.glodblock.github.client.gui;
|
||||
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.client.gui.implementations.GuiUpgradeable;
|
||||
import appeng.core.localization.GuiText;
|
||||
import com.glodblock.github.client.gui.container.ContainerFluidIO;
|
||||
import com.glodblock.github.common.parts.PartFluidImportBus;
|
||||
import com.glodblock.github.common.parts.PartSharedFluidBus;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
|
||||
public class GuiFluidIO extends GuiUpgradeable
|
||||
{
|
||||
private final PartSharedFluidBus bus;
|
||||
|
||||
public GuiFluidIO(InventoryPlayer inventoryPlayer, PartSharedFluidBus 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);
|
||||
}
|
||||
|
||||
}
|
||||
+141
@@ -0,0 +1,141 @@
|
||||
package com.glodblock.github.client.gui.container;
|
||||
|
||||
import appeng.api.config.Upgrades;
|
||||
import appeng.api.implementations.IUpgradeableHost;
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.container.implementations.ContainerUpgradeable;
|
||||
import appeng.container.slot.AppEngSlot;
|
||||
import appeng.tile.inventory.AppEngInternalAEInventory;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.item.AEFluidStack;
|
||||
import com.glodblock.github.FluidCraft;
|
||||
import com.glodblock.github.common.item.ItemFluidPacket;
|
||||
import com.glodblock.github.inventory.slot.OptionalFluidSlotFakeTypeOnly;
|
||||
import com.glodblock.github.network.SPacketFluidUpdate;
|
||||
import com.glodblock.github.util.Ae2Reflect;
|
||||
import com.glodblock.github.util.Util;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class ContainerFluidConfigurable extends ContainerUpgradeable {
|
||||
|
||||
public ContainerFluidConfigurable(InventoryPlayer ip, IUpgradeableHost te)
|
||||
{
|
||||
super( ip, te );
|
||||
}
|
||||
|
||||
public abstract AppEngInternalAEInventory getFakeFluidInv();
|
||||
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(final EntityPlayer p, final int idx )
|
||||
{
|
||||
AppEngSlot clickSlot = (AppEngSlot)this.inventorySlots.get(idx);
|
||||
if (clickSlot == null || !clickSlot.getHasStack()) return null;
|
||||
|
||||
ItemStack tis = clickSlot.getStack();
|
||||
FluidStack fs = Util.getFluidFromItem(tis);
|
||||
if( fs != null )
|
||||
{
|
||||
final AppEngInternalAEInventory inv = this.getFakeFluidInv();
|
||||
final IAEFluidStack stack = AEFluidStack.create( fs );
|
||||
for( int i = 0; i < inv.getSizeInventory(); ++i )
|
||||
{
|
||||
if( inv.getStackInSlot(i) == null && this.isValidForConfig( i, stack ) )
|
||||
{
|
||||
ItemStack tmp = ItemFluidPacket.newStack(fs);
|
||||
if (tmp != null) {
|
||||
tmp.setStackDisplayName(fs.getLocalizedName());
|
||||
}
|
||||
inv.setInventorySlotContents( i, tmp );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.standardDetectAndSendChanges();
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void setupConfig()
|
||||
{
|
||||
this.setupUpgrades();
|
||||
|
||||
final IInventory inv = Ae2Reflect.getUpgradeList(this).getInventoryByName( "config" );
|
||||
final int y = 40;
|
||||
final int x = 80;
|
||||
this.addSlotToContainer( new OptionalFluidSlotFakeTypeOnly( inv, this, 0, x, y, 0, 0, 0 ) );
|
||||
if( this.supportCapacity() )
|
||||
{
|
||||
this.addSlotToContainer( new OptionalFluidSlotFakeTypeOnly( inv, this, 1, x, y, -1, 0, 1 ) );
|
||||
this.addSlotToContainer( new OptionalFluidSlotFakeTypeOnly( inv, this, 2, x, y, 1, 0, 1 ) );
|
||||
this.addSlotToContainer( new OptionalFluidSlotFakeTypeOnly( inv, this, 3, x, y, 0, -1, 1 ) );
|
||||
this.addSlotToContainer( new OptionalFluidSlotFakeTypeOnly( inv, this, 4, x, y, 0, 1, 1 ) );
|
||||
|
||||
this.addSlotToContainer( new OptionalFluidSlotFakeTypeOnly( inv, this, 5, x, y, -1, -1, 2 ) );
|
||||
this.addSlotToContainer( new OptionalFluidSlotFakeTypeOnly( inv, this, 6, x, y, 1, -1, 2 ) );
|
||||
this.addSlotToContainer( new OptionalFluidSlotFakeTypeOnly( inv, this, 7, x, y, -1, 1, 2 ) );
|
||||
this.addSlotToContainer( new OptionalFluidSlotFakeTypeOnly( inv, this, 8, x, y, 1, 1, 2 ) );
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean isValidForConfig( int slot, IAEFluidStack fs )
|
||||
{
|
||||
if( this.supportCapacity() )
|
||||
{
|
||||
// assumes 4 slots per upgrade
|
||||
final int upgrades = Ae2Reflect.getUpgradeList(this).getInstalledUpgrades( Upgrades.CAPACITY );
|
||||
|
||||
if( slot > 0 && upgrades < 1 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return slot <= 4 || upgrades >= 2;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void standardDetectAndSendChanges()
|
||||
{
|
||||
if( Platform.isServer() )
|
||||
{
|
||||
// clear out config items that are no longer valid (eg capacity upgrade removed)
|
||||
final AppEngInternalAEInventory inv = this.getFakeFluidInv();
|
||||
final Map<Integer, IAEFluidStack> tmp = new HashMap<>();
|
||||
for( int i = 0; i < inv.getSizeInventory(); ++i )
|
||||
{
|
||||
if( inv.getStackInSlot( i ) != null && !this.isValidForConfig( i, AEFluidStack.create(ItemFluidPacket.getFluidStack(inv.getStackInSlot( i )))) )
|
||||
{
|
||||
inv.setInventorySlotContents( i, null );
|
||||
}
|
||||
tmp.put(i, AEFluidStack.create(ItemFluidPacket.getFluidStack(inv.getStackInSlot( i ))));
|
||||
}
|
||||
for( final Object g : this.crafters )
|
||||
{
|
||||
if( g instanceof EntityPlayer)
|
||||
{
|
||||
FluidCraft.proxy.netHandler.sendTo(new SPacketFluidUpdate(tmp), (EntityPlayerMP) g);
|
||||
}
|
||||
}
|
||||
}
|
||||
super.standardDetectAndSendChanges();
|
||||
}
|
||||
|
||||
public void setFluid(int id, IAEFluidStack fluidStack) {
|
||||
final AppEngInternalAEInventory inv = this.getFakeFluidInv();
|
||||
if (inv != null && this.isValidForConfig(id, AEFluidStack.create(fluidStack))) {
|
||||
ItemStack tmp = ItemFluidPacket.newStack(fluidStack.getFluidStack());
|
||||
if (tmp != null) {
|
||||
tmp.setStackDisplayName(fluidStack.getFluidStack().getLocalizedName());
|
||||
}
|
||||
inv.setInventorySlotContents(id, tmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.glodblock.github.client.gui.container;
|
||||
|
||||
import appeng.tile.inventory.AppEngInternalAEInventory;
|
||||
import com.glodblock.github.common.parts.PartSharedFluidBus;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
|
||||
public class ContainerFluidIO extends ContainerFluidConfigurable
|
||||
{
|
||||
private final PartSharedFluidBus bus;
|
||||
|
||||
public ContainerFluidIO(InventoryPlayer ip, PartSharedFluidBus te )
|
||||
{
|
||||
super( ip, te );
|
||||
this.bus = te;
|
||||
}
|
||||
|
||||
public PartSharedFluidBus getBus() {
|
||||
return this.bus;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AppEngInternalAEInventory getFakeFluidInv() {
|
||||
return (AppEngInternalAEInventory) this.bus.getInventoryByName("config");
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ public enum FCPartsTexture {
|
||||
|
||||
PartFluidPatternTerminal_Bright("pattern_terminal_bright"), PartFluidPatternTerminal_Dark("pattern_terminal_dark"),
|
||||
PartFluidPatternTerminal_Colored("pattern_terminal_medium"), PartTerminalBroad("terminal_broad"),
|
||||
PartFluidImportBus("fluid_import_face"), PartFluidExportBus("fluid_export_face"),
|
||||
BlockFluidInterfaceAlternate_Arrow("fluid_interface_arrow"), BlockInterfaceAlternate("fluid_interface_a"),
|
||||
BlockInterface_Face("fluid_interface");
|
||||
|
||||
|
||||
Reference in new issue
Block a user