add wireless fluid terminal

This commit is contained in:
asdflj committed 2023-01-30 22:52:25 +08:00
1 parent 482298021e
commit a22814940b
19 files changed
+449 -23

No files matched your search

@@ -22,6 +22,7 @@ import com.glodblock.github.common.parts.base.FCSharedFluidBus;
import com.glodblock.github.common.tile.*;
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;
public enum GuiType {
@@ -169,15 +170,15 @@ public enum GuiType {
}
}),
CRAFTING_STATUS(new PartGuiFactory<FCPart>(FCPart.class) {
CRAFTING_STATUS(new PartItemGuiFactory<ITerminalHost>(ITerminalHost.class) {
@Override
protected Object createServerGui(EntityPlayer player, FCPart inv) {
protected Object createServerGui(EntityPlayer player, ITerminalHost inv) {
return new ContainerCraftingStatus(player.inventory, inv);
}
@Override
protected Object createClientGui(EntityPlayer player, FCPart inv) {
protected Object createClientGui(EntityPlayer player, ITerminalHost inv) {
return new GuiFluidPatternTerminalCraftingStatus(player.inventory, inv);
}
}),
@@ -207,6 +208,18 @@ public enum GuiType {
return new GuiFluidPortableCell(player.inventory, inv);
}
}),
WIRELESS_FLUID_TERMINAL(new ItemGuiFactory<IWirelessTerminal>(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);
}
}),
FLUID_PATTERN_TERMINAL(new PartGuiFactory<ITerminalHost>(ITerminalHost.class) {
@@ -32,7 +32,7 @@ public abstract class ItemGuiFactory<T> implements IGuiFactory {
if (item == null || !(item.getItem() instanceof IItemInventory)) {
return null;
}
T inv = getInventory(((IItemInventory) item.getItem()).getInventory(item, world, x, y, z));
T inv = getInventory(((IItemInventory) item.getItem()).getInventory(item, world, x, y, z, player));
if (inv == null) {
return null;
}
@@ -59,7 +59,7 @@ public abstract class ItemGuiFactory<T> implements IGuiFactory {
if (item == null || !(item.getItem() instanceof IItemInventory)) {
return null;
}
T inv = getInventory(((IItemInventory) item.getItem()).getInventory(item, world, x, y, z));
T inv = getInventory(((IItemInventory) item.getItem()).getInventory(item, world, x, y, z, player));
return inv != null ? createClientGui(player, inv) : null;
}
@@ -0,0 +1,79 @@
package com.glodblock.github.inventory.gui;
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;
import org.apache.commons.lang3.tuple.MutablePair;
import appeng.container.AEBaseContainer;
import appeng.container.ContainerOpenContext;
import com.glodblock.github.inventory.item.IItemInventory;
import com.glodblock.github.util.Util;
public abstract class PartItemGuiFactory<T> extends PartGuiFactory<T> {
PartItemGuiFactory(Class<T> invClass) {
super(invClass);
}
@Nullable
protected T getItemInventory(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) {
MutablePair<Util.GuiHelper.GuiType, Integer> result = Util.GuiHelper.decodeType(y);
if (result.left == Util.GuiHelper.GuiType.ITEM) {
ItemStack item = player.getHeldItem();
if (item == null || !(item.getItem() instanceof IItemInventory)) {
return null;
}
T inv = getItemInventory(
((IItemInventory) item.getItem()).getInventory(item, world, x, result.right, z, player));
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;
} else {
return super.createServerGui(player, world, x, result.right, z, face);
}
}
@Nullable
@Override
public Object createClientGui(EntityPlayer player, World world, int x, int y, int z, ForgeDirection face) {
MutablePair<Util.GuiHelper.GuiType, Integer> result = Util.GuiHelper.decodeType(y);
if (result.left == Util.GuiHelper.GuiType.ITEM) {
ItemStack item = player.getHeldItem();
if (item == null || !(item.getItem() instanceof IItemInventory)) {
return null;
}
T inv = getItemInventory(
((IItemInventory) item.getItem()).getInventory(item, world, x, result.right, z, player));
return inv != null ? createClientGui(player, inv) : null;
} else {
return super.createClientGui(player, world, x, result.right, z, face);
}
}
}
@@ -1,9 +1,10 @@
package com.glodblock.github.inventory.item;
import net.minecraft.entity.player.EntityPlayer;
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);
Object getInventory(ItemStack stack, World world, int x, int y, int z, EntityPlayer player);
}
@@ -0,0 +1,9 @@
package com.glodblock.github.inventory.item;
import appeng.api.implementations.tiles.IViewCellStorage;
import appeng.api.networking.IGridHost;
import appeng.tile.inventory.IAEAppEngInventory;
public interface IWirelessTerminal extends IFluidPortableCell, IViewCellStorage, IAEAppEngInventory, IGridHost {
}
@@ -0,0 +1,126 @@
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 appeng.api.config.*;
import appeng.api.implementations.items.IAEItemPowerStorage;
import appeng.api.networking.IGridNode;
import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.MEMonitorHandler;
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;
import com.glodblock.github.util.BlockPos;
import com.glodblock.github.util.Util;
public class WirelessTerminal extends MEMonitorHandler<IAEFluidStack> implements IWirelessTerminal {
private final ItemStack target;
private final IAEItemPowerStorage ips;
private final EntityPlayer p;
private final int inventorySlot;
private final AppEngInternalInventory viewCell;
private final BlockPos pos;
private final StorageChannel channel;
@SuppressWarnings("unchecked")
public WirelessTerminal(final ItemStack is, BlockPos pos, EntityPlayer player) {
super(
(IMEInventoryHandler<IAEFluidStack>) Objects
.requireNonNull(Util.getWirelessInv(is, pos, StorageChannel.FLUIDS)));
this.ips = (ToolWirelessTerminal) is.getItem();
this.target = is;
this.p = player;
this.pos = pos;
this.inventorySlot = p.inventory.currentItem;
this.viewCell = new WirelessTerminalViewCells(is);
this.channel = StorageChannel.FLUIDS;
}
@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<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(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;
}
@Override
public int getInventorySlot() {
return this.inventorySlot;
}
@Override
public IInventory getViewCellStorage() {
return this.viewCell;
}
@Override
public IGridNode getGridNode(ForgeDirection dir) {
return Util.getWirelessGrid(this.target, this.pos, this.channel);
}
@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 void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removedStack,
ItemStack newStack) {}
}