mirror of
https://github.com/GTNewHorizons/AE2FluidCraft-Rework.git
synced 2026-11-16 10:34:40 +00:00
add portable fluid cell
This commit is contained in:
1 parent
fc9893ac32
commit
80340dbd75
29 files changed
+523
-98
No files matched your search
@@ -3,17 +3,16 @@ package com.glodblock.github.inventory.gui;
|
||||
import appeng.api.storage.ITerminalHost;
|
||||
import appeng.container.implementations.ContainerCraftAmount;
|
||||
import appeng.container.implementations.ContainerCraftingStatus;
|
||||
import appeng.container.implementations.ContainerInterface;
|
||||
import appeng.container.implementations.ContainerPriority;
|
||||
import appeng.helpers.IPriorityHost;
|
||||
import com.glodblock.github.client.gui.*;
|
||||
import com.glodblock.github.client.gui.container.*;
|
||||
import com.glodblock.github.common.parts.PartFluidInterface;
|
||||
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.*;
|
||||
import com.glodblock.github.inventory.item.IFluidPortableCell;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
@@ -31,6 +30,7 @@ public enum GuiType {
|
||||
return new GuiFluidLevelEmitter(player.inventory, inv);
|
||||
}
|
||||
}),
|
||||
|
||||
LEVEL_MAINTAINER(new TileGuiFactory<TileLevelMaintainer>(TileLevelMaintainer.class) {
|
||||
@Override
|
||||
protected Object createServerGui(EntityPlayer player, TileLevelMaintainer inv) {
|
||||
@@ -42,6 +42,7 @@ public enum GuiType {
|
||||
return new GuiLevelMaintainer(player.inventory, inv);
|
||||
}
|
||||
}),
|
||||
|
||||
OC_PATTERN_EDITOR(new TileGuiFactory<TileOCPatternEditor>(TileOCPatternEditor.class) {
|
||||
@Override
|
||||
protected Object createServerGui(EntityPlayer player, TileOCPatternEditor inv) {
|
||||
@@ -54,31 +55,7 @@ public enum GuiType {
|
||||
}
|
||||
}),
|
||||
|
||||
DUAL_INTERFACE_PART(new PartGuiFactory<PartFluidInterface>(PartFluidInterface.class) {
|
||||
@Override
|
||||
protected Object createServerGui(EntityPlayer player, PartFluidInterface inv) {
|
||||
return new ContainerInterface(player.inventory, inv);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object createClientGui(EntityPlayer player, PartFluidInterface inv) {
|
||||
return new GuiDualInterface(player.inventory, inv);
|
||||
}
|
||||
}),
|
||||
|
||||
DUAL_INTERFACE_FLUID_PART(new PartGuiFactory<PartFluidInterface>(PartFluidInterface.class) {
|
||||
@Override
|
||||
protected Object createServerGui(EntityPlayer player, PartFluidInterface inv) {
|
||||
return new ContainerFluidInterface(player.inventory, inv);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object createClientGui(EntityPlayer player, PartFluidInterface inv) {
|
||||
return new GuiFluidInterface(player.inventory, inv);
|
||||
}
|
||||
}),
|
||||
|
||||
DUAL_INTERFACE(new TileGuiFactory<TileFluidInterface>(TileFluidInterface.class) {
|
||||
DUAL_INTERFACE(new TileOrPartGuiFactory<TileFluidInterface>(TileFluidInterface.class) {
|
||||
@Override
|
||||
protected Object createServerGui(EntityPlayer player, TileFluidInterface inv) {
|
||||
return new ContainerDualInterface(player.inventory, inv);
|
||||
@@ -90,7 +67,7 @@ public enum GuiType {
|
||||
}
|
||||
}),
|
||||
|
||||
DUAL_INTERFACE_FLUID(new TileGuiFactory<TileFluidInterface>(TileFluidInterface.class) {
|
||||
DUAL_INTERFACE_FLUID(new TileOrPartGuiFactory<TileFluidInterface>(TileFluidInterface.class) {
|
||||
@Override
|
||||
protected Object createServerGui(EntityPlayer player, TileFluidInterface inv) {
|
||||
return new ContainerFluidInterface(player.inventory, inv);
|
||||
@@ -102,19 +79,7 @@ public enum GuiType {
|
||||
}
|
||||
}),
|
||||
|
||||
PRIORITY_PART(new PartGuiFactory<IPriorityHost>(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);
|
||||
}
|
||||
}),
|
||||
|
||||
PRIORITY_TILE(new TileGuiFactory<IPriorityHost>(IPriorityHost.class) {
|
||||
PRIORITY(new TileOrPartGuiFactory<IPriorityHost>(IPriorityHost.class) {
|
||||
@Override
|
||||
protected Object createServerGui(EntityPlayer player, IPriorityHost inv) {
|
||||
return new ContainerPriority(player.inventory, inv);
|
||||
@@ -186,7 +151,7 @@ public enum GuiType {
|
||||
}
|
||||
}),
|
||||
|
||||
FLUID_TERMINAL(new PartGuiFactory<ITerminalHost>(ITerminalHost.class) {
|
||||
FLUID_TERMINAL(new TileOrPartGuiFactory<ITerminalHost>(ITerminalHost.class) {
|
||||
@Override
|
||||
protected Object createServerGui(EntityPlayer player, ITerminalHost inv) {
|
||||
return new ContainerFluidMonitor(player.inventory, inv);
|
||||
@@ -198,6 +163,18 @@ public enum GuiType {
|
||||
}
|
||||
}),
|
||||
|
||||
PORTABLE_FLUID_CELL(new ItemGuiFactory<IFluidPortableCell>(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);
|
||||
}
|
||||
}),
|
||||
|
||||
FLUID_PATTERN_TERMINAL(new PartGuiFactory<ITerminalHost>(ITerminalHost.class) {
|
||||
@Override
|
||||
protected Object createServerGui(EntityPlayer player, ITerminalHost inv) {
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
package com.glodblock.github.inventory.gui;
|
||||
|
||||
import appeng.container.AEBaseContainer;
|
||||
import appeng.container.ContainerOpenContext;
|
||||
import com.glodblock.github.inventory.item.IItemInventory;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public abstract class ItemGuiFactory<T> implements IGuiFactory {
|
||||
|
||||
protected final Class<T> invClass;
|
||||
|
||||
ItemGuiFactory(Class<T> invClass) {
|
||||
this.invClass = invClass;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected T getInventory(Object inv) {
|
||||
return invClass.isInstance(inv) ? invClass.cast(inv) : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Object createServerGui(EntityPlayer player, World world, int x, int y, int z, ForgeDirection face) {
|
||||
ItemStack item = player.getHeldItem();
|
||||
if (item == null || !(item.getItem() instanceof IItemInventory)) {
|
||||
return null;
|
||||
}
|
||||
T inv = getInventory(((IItemInventory) item.getItem()).getInventory(item, world, x, y, z));
|
||||
if (inv == null) {
|
||||
return null;
|
||||
}
|
||||
Object gui = createServerGui(player, inv);
|
||||
if (gui instanceof AEBaseContainer) {
|
||||
ContainerOpenContext ctx = new ContainerOpenContext(inv);
|
||||
ctx.setWorld(world);
|
||||
ctx.setX(x);
|
||||
ctx.setY(y);
|
||||
ctx.setZ(z);
|
||||
ctx.setSide(face);
|
||||
((AEBaseContainer) gui).setOpenContext(ctx);
|
||||
}
|
||||
return gui;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected abstract Object createServerGui(EntityPlayer player, T inv);
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Object createClientGui(EntityPlayer player, World world, int x, int y, int z, ForgeDirection face) {
|
||||
ItemStack item = player.getHeldItem();
|
||||
if (item == null || !(item.getItem() instanceof IItemInventory)) {
|
||||
return null;
|
||||
}
|
||||
T inv = getInventory(((IItemInventory) item.getItem()).getInventory(item, world, x, y, z));
|
||||
return inv != null ? createClientGui(player, inv) : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected abstract Object createClientGui(EntityPlayer player, T inv);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.glodblock.github.inventory.gui;
|
||||
|
||||
import appeng.api.parts.IPart;
|
||||
import appeng.api.parts.IPartHost;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public abstract class TileOrPartGuiFactory<T> extends TileGuiFactory<T> {
|
||||
|
||||
TileOrPartGuiFactory(Class<T> invClass) {
|
||||
super(invClass);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected T getInventory(TileEntity tile, ForgeDirection face) {
|
||||
if (tile instanceof IPartHost) {
|
||||
IPart part = ((IPartHost) tile).getPart(face);
|
||||
if (invClass.isInstance(part)) {
|
||||
return invClass.cast(part);
|
||||
}
|
||||
}
|
||||
return super.getInventory(tile, face);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.glodblock.github.inventory.item;
|
||||
|
||||
import appeng.api.implementations.guiobjects.IGuiItemObject;
|
||||
import appeng.api.networking.energy.IEnergySource;
|
||||
import appeng.api.storage.ITerminalHost;
|
||||
import appeng.container.interfaces.IInventorySlotAware;
|
||||
|
||||
public interface IFluidPortableCell extends ITerminalHost, IInventorySlotAware, IEnergySource, IGuiItemObject {}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.glodblock.github.inventory.item;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public interface IItemInventory {
|
||||
|
||||
Object getInventory(ItemStack stack, World world, int x, int y, int z);
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.glodblock.github.inventory.item;
|
||||
|
||||
import appeng.api.config.*;
|
||||
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;
|
||||
import com.glodblock.github.common.storage.FluidCellInventory;
|
||||
import java.util.Objects;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class PortableFluidCellInventory extends MEMonitorHandler<IAEFluidStack> 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<IAEItemStack> getItemInventory() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMEMonitor<IAEFluidStack> 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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user