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

@@ -13,6 +13,7 @@ import com.glodblock.github.common.parts.PartFluidPatternTerminalEx;
import com.glodblock.github.common.parts.PartFluidTerminal;
import com.glodblock.github.inventory.InventoryHandler;
import com.glodblock.github.inventory.gui.GuiType;
import com.glodblock.github.inventory.item.WirelessTerminal;
import com.glodblock.github.loader.ItemAndBlockHolder;
import com.glodblock.github.util.Ae2ReflectClient;
@@ -34,7 +35,10 @@ public class GuiFluidPatternTerminalCraftingStatus extends GuiCraftingStatus {
Ae2ReflectClient.rewriteIcon(this, new ItemStack(ItemAndBlockHolder.FLUID_TERMINAL_EX, 1));
else if (host instanceof PartFluidTerminal) {
Ae2ReflectClient.rewriteIcon(this, new ItemStack(ItemAndBlockHolder.FLUID_TERM, 1));
} else if (host instanceof WirelessTerminal) {
Ae2ReflectClient.rewriteIcon(this, new ItemStack(ItemAndBlockHolder.WIRELESS_FLUID_TERM, 1));
}
super.initGui();
originalGuiBtn = Ae2ReflectClient.getOriginalGuiButton(this);
}
@@ -46,6 +50,7 @@ public class GuiFluidPatternTerminalCraftingStatus extends GuiCraftingStatus {
else if (host instanceof PartFluidPatternTerminalEx)
InventoryHandler.switchGui(GuiType.FLUID_PATTERN_TERMINAL_EX);
else if (host instanceof PartFluidTerminal) InventoryHandler.switchGui(GuiType.FLUID_TERMINAL);
else if (host instanceof WirelessTerminal) InventoryHandler.switchGui(GuiType.WIRELESS_FLUID_TERMINAL);
} else {
super.actionPerformed(btn);
}
@@ -6,6 +6,7 @@ import appeng.container.slot.AppEngSlot;
import com.glodblock.github.client.gui.container.ContainerFluidPortableCell;
import com.glodblock.github.inventory.item.IFluidPortableCell;
import com.glodblock.github.inventory.item.IWirelessTerminal;
public class GuiFluidPortableCell extends GuiFluidTerminal {
@@ -20,6 +21,10 @@ public class GuiFluidPortableCell extends GuiFluidTerminal {
@Override
protected int getMaxRows() {
return 3;
if (this.container.getHost() instanceof IWirelessTerminal) {
return super.getMaxRows();
} else {
return 3;
}
}
}
@@ -32,6 +32,8 @@ import appeng.util.ConfigManager;
import appeng.util.IConfigManagerHost;
import appeng.util.Platform;
import com.glodblock.github.inventory.item.IWirelessTerminal;
public abstract class FCContainerMonitor<T extends IAEStack<T>> extends AEBaseContainer
implements IConfigManagerHost, IConfigurableObject, IMEMonitorHandlerReceiver<T> {
@@ -98,6 +100,7 @@ public abstract class FCContainerMonitor<T extends IAEStack<T>> extends AEBaseCo
this.updatePowerStatus();
final boolean oldAccessible = this.canAccessViewCells;
this.canAccessViewCells = this.host instanceof WirelessTerminalGuiObject
|| this.host instanceof IWirelessTerminal
|| this.hasAccess(SecurityPermissions.BUILD, false);
if (this.canAccessViewCells != oldAccessible) {
for (int y = 0; y < 5; y++) {
@@ -214,4 +217,8 @@ public abstract class FCContainerMonitor<T extends IAEStack<T>> extends AEBaseCo
this.getGui().updateSetting(manager, settingName, newValue);
}
}
public ITerminalHost getHost() {
return this.host;
}
}
@@ -192,7 +192,7 @@ public class ItemPortableFluidCell extends AEBasePoweredItem
}
@Override
public Object getInventory(ItemStack stack, World world, int x, int y, int z) {
public Object getInventory(ItemStack stack, World world, int x, int y, int z, EntityPlayer player) {
return new PortableFluidCellInventory(stack, x);
}
@@ -0,0 +1,94 @@
package com.glodblock.github.common.item;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import appeng.api.AEApi;
import appeng.api.features.ILocatable;
import appeng.api.features.IWirelessTermHandler;
import appeng.api.features.IWirelessTermRegistry;
import appeng.core.localization.PlayerMessages;
import appeng.items.tools.powered.ToolWirelessTerminal;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.common.tabs.FluidCraftingTabs;
import com.glodblock.github.inventory.InventoryHandler;
import com.glodblock.github.inventory.gui.GuiType;
import com.glodblock.github.inventory.item.IItemInventory;
import com.glodblock.github.inventory.item.WirelessTerminal;
import com.glodblock.github.loader.IRegister;
import com.glodblock.github.util.BlockPos;
import com.glodblock.github.util.NameConst;
import cpw.mods.fml.common.registry.GameRegistry;
public class ItemWirelessFluidTerminal extends ToolWirelessTerminal
implements IItemInventory, IRegister<ItemWirelessFluidTerminal> {
public ItemWirelessFluidTerminal() {
super();
AEApi.instance().registries().wireless().registerWirelessHandler(this);
setUnlocalizedName(NameConst.ITEM_WIRELESS_FLUID_TERMINAL);
setTextureName(FluidCraft.resource(NameConst.ITEM_WIRELESS_FLUID_TERMINAL).toString());
}
@Override
public ItemStack onItemRightClick(final ItemStack item, final World w, final EntityPlayer player) {
IWirelessTermRegistry term = AEApi.instance().registries().wireless();
if (!term.isWirelessTerminal(item)) {
player.addChatMessage(PlayerMessages.DeviceNotWirelessTerminal.get());
return item;
}
final IWirelessTermHandler handler = term.getWirelessTerminalHandler(item);
final String unparsedKey = handler.getEncryptionKey(item);
if (unparsedKey.isEmpty()) {
player.addChatMessage(PlayerMessages.DeviceNotLinked.get());
return item;
}
final long parsedKey = Long.parseLong(unparsedKey);
final ILocatable securityStation = AEApi.instance().registries().locatable().getLocatableBy(parsedKey);
if (securityStation == null) {
player.addChatMessage(PlayerMessages.StationCanNotBeLocated.get());
return item;
}
if (handler.hasPower(player, 0.5, item)) {
InventoryHandler.openGui(
player,
w,
new BlockPos((int) player.posX, (int) player.posY, (int) player.posZ),
ForgeDirection.UNKNOWN,
GuiType.WIRELESS_FLUID_TERMINAL);
} else {
player.addChatMessage(PlayerMessages.DeviceNotPowered.get());
}
return item;
}
@Override
public boolean canHandle(final ItemStack is) {
return is.getItem() == this;
}
@Override
public ItemWirelessFluidTerminal register() {
GameRegistry.registerItem(this, NameConst.ITEM_WIRELESS_FLUID_TERMINAL, FluidCraft.MODID);
setCreativeTab(FluidCraftingTabs.INSTANCE);
return this;
}
@Override
public Object getInventory(ItemStack stack, World world, int x, int y, int z, EntityPlayer player) {
try {
return new WirelessTerminal(stack, new BlockPos(x, y, z, world), player);
} catch (Exception e) {
player.addChatMessage(PlayerMessages.OutOfRange.get());
return null;
}
}
public ItemStack stack() {
return new ItemStack(this, 1);
}
}
@@ -60,7 +60,6 @@ public class TileFluidAutoFiller extends AENetworkInvTile
private final AppEngInternalInventory inventory = new AppEngInternalInventory(this, 1);
private final BaseActionSource source = new MachineSource(this);
private IItemList<IAEFluidStack> fluids = AEApi.instance().storage().createFluidList();
public ItemStack containerItem;
private final Item encodedPattern = AEApi.instance().definitions().items().encodedPattern().maybeItem().orNull();
private IAEItemStack returnStack;
private boolean isPowered;
@@ -74,7 +73,14 @@ public class TileFluidAutoFiller extends AENetworkInvTile
getProxy().setIdlePowerUsage(1D);
getProxy().setFlags(GridFlags.REQUIRE_CHANNEL);
inventory.setInventorySlotContents(0, BUCKET);
this.containerItem = getInventory().getStackInSlot(0);
}
public ItemStack getContainerItem() {
return getInventory().getStackInSlot(0);
}
public void setContainerItem(ItemStack is) {
getInventory().setInventorySlotContents(0, is);
}
@Override
@@ -92,8 +98,8 @@ public class TileFluidAutoFiller extends AENetworkInvTile
public void updatePattern() {
ItemStack is = inventory.getStackInSlot(0);
if (is == null || this.containerItem.isItemEqual(is)) return;
this.containerItem = is;
if (is == null || this.getContainerItem().isItemEqual(is)) return;
this.setContainerItem(is);
postEvent();
}
@@ -141,12 +147,12 @@ public class TileFluidAutoFiller extends AENetworkInvTile
for (IAEFluidStack fluidStack : fluidStorage) {
Fluid fluid = fluidStack.getFluid();
if (fluid == null) continue;
int maxCapacity = Util.FluidUtil.getCapacity(this.containerItem, fluid);
int maxCapacity = Util.FluidUtil.getCapacity(this.getContainerItem(), fluid);
if (maxCapacity == 0) continue;
MutablePair<Integer, ItemStack> filled = Util.FluidUtil
.fillStack(this.containerItem.copy(), new FluidStack(fluid, maxCapacity));
.fillStack(this.getContainerItem().copy(), new FluidStack(fluid, maxCapacity));
if (filled.right == null) continue;
ItemStack pattern = getPattern(this.containerItem, filled.right);
ItemStack pattern = getPattern(this.getContainerItem(), filled.right);
ICraftingPatternItem patter = (ICraftingPatternItem) pattern.getItem();
craftingTracker.addCraftingOption(this, patter.getPatternForItem(pattern, getWorldObj()));
}
@@ -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) {}
}
@@ -32,6 +32,7 @@ public class ItemAndBlockHolder {
public static ItemFluidStorageMonitor FLUID_STORAGE_MONITOR = new ItemFluidStorageMonitor().register();
public static ItemFluidConversionMonitor FLUID_CONVERSION_MONITOR = new ItemFluidConversionMonitor().register();
public static ItemPortableFluidCell PORTABLE_FLUID_CELL = new ItemPortableFluidCell().register();
public static ItemWirelessFluidTerminal WIRELESS_FLUID_TERM = new ItemWirelessFluidTerminal().register();
public static ItemFluidPacket PACKET = new ItemFluidPacket().register();
public static ItemBasicFluidStorageCell CELL1K = new ItemBasicFluidStorageCell(CellType.Cell1kPart, 1).register();
public static ItemBasicFluidStorageCell CELL4K = new ItemBasicFluidStorageCell(CellType.Cell4kPart, 4).register();
@@ -128,6 +128,7 @@ public class RecipeLoader implements Runnable {
AE2_INTERFACE));
GameRegistry.addShapelessRecipe(FLUID_INTERFACE.stack(), INTERFACE.stack());
GameRegistry.addShapelessRecipe(INTERFACE.stack(), FLUID_INTERFACE.stack());
GameRegistry.addShapelessRecipe(WIRELESS_FLUID_TERM.stack(), AE2_TERMINAL, BUFFER.stack());
GameRegistry
.addRecipe(new ShapedOreRecipe(CERTUS_QUARTZ_TANK.stack(), "GGG", "G G", "GGG", 'G', AE2_QUARTZ_GLASS));
GameRegistry.addShapelessRecipe(FLUID_AUTO_FILLER.stack(), FLUID_TERMINAL, ENCODER);
@@ -14,6 +14,7 @@ import appeng.container.ContainerOpenContext;
import com.glodblock.github.inventory.InventoryHandler;
import com.glodblock.github.inventory.gui.GuiType;
import com.glodblock.github.util.BlockPos;
import com.glodblock.github.util.Util;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
@@ -60,15 +61,25 @@ public class CPacketSwitchGuis implements IMessage {
return null;
}
TileEntity te = context.getTile();
if (te == null) {
return null;
if (te != null) {
InventoryHandler.openGui(
player,
player.worldObj,
new BlockPos(te),
Objects.requireNonNull(context.getSide()),
message.guiType);
} else {
InventoryHandler.openGui(
player,
player.worldObj,
new BlockPos(
(int) player.posX,
Util.GuiHelper.encodeType((int) player.posY, Util.GuiHelper.GuiType.ITEM),
(int) player.posZ),
Objects.requireNonNull(context.getSide()),
message.guiType);
}
InventoryHandler.openGui(
player,
player.worldObj,
new BlockPos(te),
Objects.requireNonNull(context.getSide()),
message.guiType);
return null;
}
}
@@ -36,6 +36,7 @@ public class NameConst {
public static final String ITEM_FLUID_PACKET = "fluid_packet";
public static final String ITEM_FLUID_STORAGE = "fluid_storage";
public static final String ITEM_FLUID_PORTABLE_CELL = "portable_fluid_cell";
public static final String ITEM_WIRELESS_FLUID_TERMINAL = "wireless_fluid_terminal";
public static final String ITEM_FLUID_PART = "fluid_part";
public static final String TT_KEY = FluidCraft.MODID + ".tooltip.";
@@ -15,17 +15,25 @@ import org.apache.commons.lang3.tuple.MutablePair;
import appeng.api.AEApi;
import appeng.api.config.SecurityPermissions;
import appeng.api.implementations.tiles.IWirelessAccessPoint;
import appeng.api.networking.IGrid;
import appeng.api.networking.IGridHost;
import appeng.api.networking.IGridNode;
import appeng.api.networking.security.ISecurityGrid;
import appeng.api.networking.storage.IBaseMonitor;
import appeng.api.networking.storage.IStorageGrid;
import appeng.api.parts.IPart;
import appeng.api.storage.StorageChannel;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IAEStack;
import appeng.api.util.WorldCoord;
import appeng.tile.networking.TileCableBus;
import appeng.tile.networking.TileWireless;
import appeng.util.item.AEFluidStack;
import com.glodblock.github.common.item.ItemFluidDrop;
import com.glodblock.github.common.item.ItemFluidPacket;
import com.glodblock.github.common.item.ItemWirelessFluidTerminal;
import com.glodblock.github.inventory.IAEFluidTank;
import cpw.mods.fml.common.ModContainer;
@@ -34,6 +42,39 @@ import io.netty.buffer.ByteBuf;
public final class Util {
public static IGridNode getWirelessGrid(ItemStack is, BlockPos pos, StorageChannel channel) {
String key = ((ItemWirelessFluidTerminal) is.getItem()).getEncryptionKey(is);
IGridHost securityTerminal = (IGridHost) AEApi.instance().registries().locatable()
.getLocatableBy(Long.parseLong(key));
if (securityTerminal == null) return null;
return securityTerminal.getGridNode(ForgeDirection.UNKNOWN);
}
@SuppressWarnings("unchecked")
public static IBaseMonitor<? extends IAEStack<? extends IAEStack<?>>> getWirelessInv(ItemStack is, BlockPos pos,
StorageChannel channel) {
IGridNode gridNode = getWirelessGrid(is, pos, channel);
if (gridNode == null) return null;
IGrid grid = gridNode.getGrid();
if (grid == null) return null;
for (IGridNode node : grid.getMachines(TileWireless.class)) {
IWirelessAccessPoint accessPoint = (IWirelessAccessPoint) node.getMachine();
WorldCoord distance = accessPoint.getLocation().subtract(pos.getX(), pos.getY(), pos.getZ());
int squaredDistance = distance.x * distance.x + distance.y * distance.y + distance.z * distance.z;
if (squaredDistance <= accessPoint.getRange() * accessPoint.getRange()) {
IStorageGrid gridCache = grid.getCache(IStorageGrid.class);
if (gridCache != null) {
if (channel == StorageChannel.FLUIDS) {
return gridCache.getFluidInventory();
} else {
return gridCache.getItemInventory();
}
}
}
}
return null;
}
public static int findItemInPlayerInvSlot(EntityPlayer player, ItemStack itemStack) {
for (int i = 0; i < player.inventory.mainInventory.length; i++) {
if (player.inventory.mainInventory[i] != null && player.inventory.mainInventory[i] == itemStack) return i;
@@ -218,6 +259,31 @@ public final class Util {
}
}
public static class GuiHelper {
public enum GuiType {
TILE,
ITEM
}
private static final int value = 1 << 30;
public static int encodeType(int y, GuiType type) {
if (y > (1 << 28)) {
throw new IllegalArgumentException("out of range");
}
return value | (type.ordinal() << 29) | y;
}
public static MutablePair<GuiType, Integer> decodeType(int y) {
if (y > (1 << 28)) {
return new MutablePair<>(GuiType.values()[y >> 29 & 1], y - (3 << 29 & y));
} else {
return new MutablePair<>(GuiType.TILE, y);
}
}
}
public static int clamp(int value, int min, int max) {
return value < min ? min : (Math.min(value, max));
}
@@ -11,6 +11,7 @@ item.part_fluid_level_emitter.name=ME Fluid Level Emitter
item.part_fluid_storage_monitor.name=ME Fluid Storage Monitor
item.part_fluid_conversion_monitor.name=ME Fluid Conversion Monitor
item.portable_fluid_cell.name=Portable Fluid Cell
item.wireless_fluid_terminal.name=Wireless Fluid Terminal
item.fluid_packet.name=Fluid Packet
item.fluid_storage.1.name=%s1k%s ME Fluid Storage Cell
item.fluid_storage.4.name=%s4k%s ME Fluid Storage Cell
Binary file not shown.

After

Width:  |  Height:  |  Size: 355 B