mirror of
https://github.com/GTNewHorizons/AE2FluidCraft-Rework.git
synced 2026-11-22 21:09:43 +00:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a3debac678 | ||
|
|
c0ba18417d |
No files matched your search
@@ -11,7 +11,7 @@ import appeng.tile.inventory.InvOperation;
|
|||||||
|
|
||||||
public class TileOCPatternEditor extends AEBaseInvTile {
|
public class TileOCPatternEditor extends AEBaseInvTile {
|
||||||
|
|
||||||
private final AppEngInternalInventory invItems = new AppEngInternalInventory(this, 16);
|
private final AppEngInternalInventory invItems = new AppEngInternalInventory(this, 16, 1);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IInventory getInternalInventory() {
|
public IInventory getInternalInventory() {
|
||||||
|
|||||||
+49
-142
@@ -3,31 +3,24 @@ package com.glodblock.github.crossmod.opencomputers;
|
|||||||
import net.minecraft.inventory.IInventory;
|
import net.minecraft.inventory.IInventory;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.nbt.NBTTagList;
|
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
import net.minecraftforge.common.util.ForgeDirection;
|
||||||
import net.minecraftforge.fluids.FluidStack;
|
|
||||||
|
|
||||||
import com.glodblock.github.common.item.ItemFluidDrop;
|
|
||||||
import com.glodblock.github.common.item.ItemFluidEncodedPattern;
|
|
||||||
import com.glodblock.github.common.tile.TileOCPatternEditor;
|
import com.glodblock.github.common.tile.TileOCPatternEditor;
|
||||||
import com.glodblock.github.loader.ItemAndBlockHolder;
|
import com.glodblock.github.loader.ItemAndBlockHolder;
|
||||||
import com.glodblock.github.util.NameConst;
|
import com.glodblock.github.util.NameConst;
|
||||||
import com.glodblock.github.util.Util;
|
|
||||||
|
|
||||||
import appeng.items.misc.ItemEncodedPattern;
|
import appeng.api.AEApi;
|
||||||
import appeng.util.item.AEItemStack;
|
|
||||||
import li.cil.oc.api.driver.EnvironmentProvider;
|
import li.cil.oc.api.driver.EnvironmentProvider;
|
||||||
import li.cil.oc.api.driver.NamedBlock;
|
import li.cil.oc.api.driver.NamedBlock;
|
||||||
import li.cil.oc.api.internal.Database;
|
|
||||||
import li.cil.oc.api.machine.Arguments;
|
import li.cil.oc.api.machine.Arguments;
|
||||||
import li.cil.oc.api.machine.Callback;
|
import li.cil.oc.api.machine.Callback;
|
||||||
import li.cil.oc.api.machine.Context;
|
import li.cil.oc.api.machine.Context;
|
||||||
import li.cil.oc.api.network.Component;
|
|
||||||
import li.cil.oc.api.network.ManagedEnvironment;
|
import li.cil.oc.api.network.ManagedEnvironment;
|
||||||
import li.cil.oc.api.network.Node;
|
|
||||||
import li.cil.oc.api.prefab.DriverSidedTileEntity;
|
import li.cil.oc.api.prefab.DriverSidedTileEntity;
|
||||||
import li.cil.oc.integration.ManagedTileEntityEnvironment;
|
import li.cil.oc.integration.ManagedTileEntityEnvironment;
|
||||||
|
import li.cil.oc.integration.appeng.internal.PatternEnvironment;
|
||||||
|
import li.cil.oc.integration.appeng.internal.PatternEnvironment$class;
|
||||||
|
|
||||||
public class DriverOCPatternEditor extends DriverSidedTileEntity {
|
public class DriverOCPatternEditor extends DriverSidedTileEntity {
|
||||||
|
|
||||||
@@ -43,12 +36,33 @@ public class DriverOCPatternEditor extends DriverSidedTileEntity {
|
|||||||
return new DriverOCPatternEditor.Environment((TileOCPatternEditor) world.getTileEntity(x, y, z));
|
return new DriverOCPatternEditor.Environment((TileOCPatternEditor) world.getTileEntity(x, y, z));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Environment extends ManagedTileEntityEnvironment<TileOCPatternEditor> implements NamedBlock {
|
public static class Environment extends ManagedTileEntityEnvironment<TileOCPatternEditor>
|
||||||
|
implements NamedBlock, PatternEnvironment {
|
||||||
|
|
||||||
public Environment(TileOCPatternEditor tileEntity) {
|
public Environment(TileOCPatternEditor tileEntity) {
|
||||||
super(tileEntity, NameConst.BLOCK_OC_PATTERN_EDITOR);
|
super(tileEntity, NameConst.BLOCK_OC_PATTERN_EDITOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IInventory getPatternInventory(Context context, Arguments args) {
|
||||||
|
return tileEntity.getInternalInventory();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int offset() {
|
||||||
|
return PatternEnvironment$class.offset(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object[] setPatternSlot(Context context, Arguments args, String tag) {
|
||||||
|
return PatternEnvironment$class.setPatternSlot(this, context, args, tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object[] storeInterfacePattern(Context context, Arguments args, String tag) {
|
||||||
|
return PatternEnvironment$class.storeInterfacePattern(this, context, args, tag);
|
||||||
|
}
|
||||||
|
|
||||||
private int optSlot(Arguments args, IInventory inv, int index, int def) {
|
private int optSlot(Arguments args, IInventory inv, int index, int def) {
|
||||||
if (index >= 0 && index < args.count()) {
|
if (index >= 0 && index < args.count()) {
|
||||||
int slot = args.checkInteger(index) - 1;
|
int slot = args.checkInteger(index) - 1;
|
||||||
@@ -62,132 +76,23 @@ public class DriverOCPatternEditor extends DriverSidedTileEntity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int checkSlot(Arguments args, IInventory inv, int index) {
|
private int checkSlot(Arguments args, IInventory inv, int index) {
|
||||||
if (index >= 0 && index < args.count()) {
|
int slot = args.checkInteger(index) - 1;
|
||||||
int slot = args.checkInteger(index) - 1;
|
if (slot < 0 || slot >= inv.getSizeInventory()) {
|
||||||
if (slot < 0 || slot >= inv.getSizeInventory()) {
|
|
||||||
throw new IllegalArgumentException("invalid slot");
|
|
||||||
}
|
|
||||||
return slot;
|
|
||||||
} else {
|
|
||||||
throw new IllegalArgumentException("invalid slot");
|
throw new IllegalArgumentException("invalid slot");
|
||||||
}
|
}
|
||||||
|
return slot;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean validPattern(ItemStack pattern) {
|
private void replaceBlankPattern(Arguments args) {
|
||||||
if (pattern == null) {
|
|
||||||
throw new IllegalArgumentException("No pattern here!");
|
|
||||||
}
|
|
||||||
if (pattern.getItem() instanceof ItemEncodedPattern iep
|
|
||||||
&& !(pattern.getItem() instanceof ItemFluidEncodedPattern)) {
|
|
||||||
return iep.getOutput(pattern) == null;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private ItemStack getStack(Arguments args) {
|
|
||||||
if (args.count() > 1) {
|
|
||||||
String address;
|
|
||||||
int entry;
|
|
||||||
int size;
|
|
||||||
if (args.isString(0)) {
|
|
||||||
address = args.checkString(0);
|
|
||||||
entry = args.checkInteger(1);
|
|
||||||
size = args.optInteger(2, 1);
|
|
||||||
} else {
|
|
||||||
address = args.checkString(1);
|
|
||||||
entry = args.checkInteger(2);
|
|
||||||
size = args.optInteger(3, 1);
|
|
||||||
}
|
|
||||||
Node node = node().network().node(address);
|
|
||||||
if (node instanceof Component) {
|
|
||||||
if (node.host() instanceof Database) {
|
|
||||||
ItemStack dbStack = ((Database) node.host()).getStackInSlot(entry - 1);
|
|
||||||
if (dbStack == null || size < 1) {
|
|
||||||
return null;
|
|
||||||
} else {
|
|
||||||
dbStack.stackSize = Math.min(size, dbStack.getMaxStackSize());
|
|
||||||
return dbStack;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw new IllegalArgumentException("not a database");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw new IllegalArgumentException("no such component");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Object[] clearInterfacePattern(Context context, Arguments args, String tag) {
|
|
||||||
IInventory inv = tileEntity.getInternalInventory();
|
IInventory inv = tileEntity.getInternalInventory();
|
||||||
ItemStack pattern = inv.getStackInSlot(checkSlot(args, inv, 0));
|
int slot = checkSlot(args, inv, 0);
|
||||||
if (validPattern(pattern)) {
|
if (AEApi.instance().definitions().materials().blankPattern().isSameAs(inv.getStackInSlot(slot))) {
|
||||||
NBTTagCompound encodedValue = pattern.getTagCompound();
|
ItemStack pattern = AEApi.instance().definitions().items().encodedUltimatePattern().maybeStack(1).get();
|
||||||
int slot = checkSlot(args, inv, 0);
|
pattern.setTagCompound(new NBTTagCompound());
|
||||||
if (encodedValue == null) throw new IllegalArgumentException("No pattern here!");
|
|
||||||
NBTTagList nbt = encodedValue.getTagList(tag, 10);
|
|
||||||
int index = args.checkInteger(1) - 1;
|
|
||||||
if (index < 0) throw new IllegalArgumentException("Invalid index!");
|
|
||||||
nbt.removeTag(index);
|
|
||||||
encodedValue.setTag(tag, nbt);
|
|
||||||
pattern.setTagCompound(encodedValue);
|
|
||||||
inv.setInventorySlotContents(slot, null);
|
|
||||||
inv.setInventorySlotContents(slot, pattern);
|
inv.setInventorySlotContents(slot, pattern);
|
||||||
context.pause(0.1);
|
|
||||||
return new Object[] { true };
|
|
||||||
} else {
|
|
||||||
throw new IllegalArgumentException("Not Fluid Encoded pattern!");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object[] setPatternSlot(Context context, Arguments args, String tag, boolean fluid) {
|
|
||||||
IInventory inv = tileEntity.getInternalInventory();
|
|
||||||
int slot = args.isString(0) ? 0 : optSlot(args, inv, 0, 0);
|
|
||||||
ItemStack stack = getStack(args);
|
|
||||||
if (fluid) {
|
|
||||||
FluidStack fluids = Util.getFluidFromItem(stack);
|
|
||||||
stack = ItemFluidDrop.newStack(fluids);
|
|
||||||
}
|
|
||||||
int index = args.checkInteger(4) - 1;
|
|
||||||
if (index < 0 || index > 511) throw new IllegalArgumentException("Invalid index!");
|
|
||||||
ItemStack pattern = inv.getStackInSlot(slot);
|
|
||||||
if (validPattern(pattern)) {
|
|
||||||
NBTTagCompound encodedValue = pattern.getTagCompound();
|
|
||||||
if (encodedValue == null) throw new IllegalArgumentException("No pattern here!");
|
|
||||||
|
|
||||||
NBTTagList inTag = encodedValue.getTagList(tag, 10);
|
|
||||||
while (inTag.tagCount() <= index) inTag.appendTag(new NBTTagCompound());
|
|
||||||
if (stack != null) {
|
|
||||||
NBTTagCompound nbt = new NBTTagCompound();
|
|
||||||
AEItemStack aeStack = AEItemStack.create(stack);
|
|
||||||
aeStack.writeToNBT(nbt);
|
|
||||||
inTag.func_150304_a(index, nbt);
|
|
||||||
} else {
|
|
||||||
inTag.removeTag(index);
|
|
||||||
}
|
|
||||||
encodedValue.setTag(tag, inTag);
|
|
||||||
pattern.setTagCompound(encodedValue);
|
|
||||||
inv.setInventorySlotContents(slot, null);
|
|
||||||
inv.setInventorySlotContents(slot, pattern);
|
|
||||||
context.pause(0.1);
|
|
||||||
return new Object[] { true };
|
|
||||||
} else {
|
|
||||||
throw new IllegalArgumentException("Not Fluid Encoded pattern!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Callback(doc = "function([slot:number]):table -- Get the configuration of the interface.")
|
|
||||||
public Object[] getInterfaceConfiguration(Context context, Arguments args) {
|
|
||||||
IInventory config = tileEntity.getInternalInventory();
|
|
||||||
int slot = optSlot(args, config, 0, 0);
|
|
||||||
ItemStack stack = config.getStackInSlot(slot);
|
|
||||||
if (!validPattern(stack)) {
|
|
||||||
throw new IllegalArgumentException("Not Fluid Encoded pattern!");
|
|
||||||
}
|
|
||||||
return new Object[] { stack };
|
|
||||||
}
|
|
||||||
|
|
||||||
@Callback(doc = "function([slot:number]):table -- Get the given pattern in the interface.")
|
@Callback(doc = "function([slot:number]):table -- Get the given pattern in the interface.")
|
||||||
public Object[] getInterfacePattern(Context context, Arguments args) {
|
public Object[] getInterfacePattern(Context context, Arguments args) {
|
||||||
IInventory inv = tileEntity.getInternalInventory();
|
IInventory inv = tileEntity.getInternalInventory();
|
||||||
@@ -197,37 +102,39 @@ public class DriverOCPatternEditor extends DriverSidedTileEntity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Callback(
|
@Callback(
|
||||||
doc = "function(slot:number, database:address, entry:number, size:number, index:number):boolean -- Set the pattern item input at the given index.")
|
doc = "function(slot:number, index:number[, database:address, entry:number, size:number]):boolean OR function(slot:number, index:number[, detail:table, type:string]):boolean -- Set the pattern input at the given index. A blank pattern becomes an ultimate pattern.")
|
||||||
public Object[] setInterfacePatternItemInput(Context context, Arguments args) {
|
public Object[] setInterfacePatternInput(Context context, Arguments args) {
|
||||||
return setPatternSlot(context, args, "in", false);
|
replaceBlankPattern(args);
|
||||||
|
return setPatternSlot(context, args, "in");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Callback(
|
@Callback(
|
||||||
doc = "function(slot:number, database:address, entry:number, size:number, index:number):boolean -- Set the pattern item output at the given index.")
|
doc = "function(slot:number, index:number[, database:address, entry:number, size:number]):boolean OR function(slot:number, index:number[, detail:table, type:string]):boolean -- Set the pattern output at the given index. A blank pattern becomes an ultimate pattern.")
|
||||||
public Object[] setInterfacePatternItemOutput(Context context, Arguments args) {
|
public Object[] setInterfacePatternOutput(Context context, Arguments args) {
|
||||||
return setPatternSlot(context, args, "out", false);
|
replaceBlankPattern(args);
|
||||||
|
return setPatternSlot(context, args, "out");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Callback(
|
@Callback(
|
||||||
doc = "function(slot:number, database:address, entry:number, size:number, index:number):boolean -- Set the pattern fluid input at the given index.")
|
doc = "function(slot:number, index:number, database:address, entry:number):boolean -- Store pattern input at the given index to the database entry.")
|
||||||
public Object[] setInterfacePatternFluidInput(Context context, Arguments args) {
|
public Object[] storeInterfacePatternInput(Context context, Arguments args) {
|
||||||
return setPatternSlot(context, args, "in", true);
|
return storeInterfacePattern(context, args, "in");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Callback(
|
@Callback(
|
||||||
doc = "function(slot:number, database:address, entry:number, size:number, index:number):boolean -- Set the pattern fluid output at the given index.")
|
doc = "function(slot:number, index:number, database:address, entry:number):boolean -- Store pattern output at the given index to the database entry.")
|
||||||
public Object[] setInterfacePatternFluidOutput(Context context, Arguments args) {
|
public Object[] storeInterfacePatternOutput(Context context, Arguments args) {
|
||||||
return setPatternSlot(context, args, "out", true);
|
return storeInterfacePattern(context, args, "out");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Callback(doc = "function(slot:number, index:number):boolean -- Clear pattern input at the given index.")
|
@Callback(doc = "function(slot:number, index:number):boolean -- Clear pattern input at the given index.")
|
||||||
public Object[] clearInterfacePatternInput(Context context, Arguments args) {
|
public Object[] clearInterfacePatternInput(Context context, Arguments args) {
|
||||||
return clearInterfacePattern(context, args, "in");
|
return setPatternSlot(context, args, "in");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Callback(doc = "function(slot:number, index:number):boolean -- Clear pattern output at the given index.")
|
@Callback(doc = "function(slot:number, index:number):boolean -- Clear pattern output at the given index.")
|
||||||
public Object[] clearInterfacePatternOutput(Context context, Arguments args) {
|
public Object[] clearInterfacePatternOutput(Context context, Arguments args) {
|
||||||
return clearInterfacePattern(context, args, "out");
|
return setPatternSlot(context, args, "out");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+17
-9
@@ -5,8 +5,11 @@ import net.minecraftforge.common.util.ForgeDirection;
|
|||||||
|
|
||||||
import appeng.api.implementations.tiles.ITileStorageMonitorable;
|
import appeng.api.implementations.tiles.ITileStorageMonitorable;
|
||||||
import appeng.api.networking.security.BaseActionSource;
|
import appeng.api.networking.security.BaseActionSource;
|
||||||
|
import appeng.api.parts.IPart;
|
||||||
|
import appeng.api.parts.IPartHost;
|
||||||
import appeng.api.storage.IExternalStorageHandler;
|
import appeng.api.storage.IExternalStorageHandler;
|
||||||
import appeng.api.storage.IMEInventory;
|
import appeng.api.storage.IMEInventory;
|
||||||
|
import appeng.api.storage.IStorageMonitorable;
|
||||||
import appeng.api.storage.StorageChannel;
|
import appeng.api.storage.StorageChannel;
|
||||||
import appeng.util.Platform;
|
import appeng.util.Platform;
|
||||||
|
|
||||||
@@ -16,8 +19,8 @@ public class AEFluidInterfaceHandler implements IExternalStorageHandler {
|
|||||||
public boolean canHandle(TileEntity te, ForgeDirection d, StorageChannel channel, BaseActionSource mySrc) {
|
public boolean canHandle(TileEntity te, ForgeDirection d, StorageChannel channel, BaseActionSource mySrc) {
|
||||||
if (channel == StorageChannel.FLUIDS) {
|
if (channel == StorageChannel.FLUIDS) {
|
||||||
if (te instanceof ITileStorageMonitorable) {
|
if (te instanceof ITileStorageMonitorable) {
|
||||||
return true;
|
return !(te instanceof IPartHost);
|
||||||
} else return Platform.getPartFromTE(te, d.getOpposite()) instanceof ITileStorageMonitorable;
|
} else return getMonitorablePart(te, d, mySrc) != null;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -26,14 +29,19 @@ public class AEFluidInterfaceHandler implements IExternalStorageHandler {
|
|||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
public IMEInventory getInventory(TileEntity te, ForgeDirection d, StorageChannel channel, BaseActionSource src) {
|
public IMEInventory getInventory(TileEntity te, ForgeDirection d, StorageChannel channel, BaseActionSource src) {
|
||||||
if (channel == StorageChannel.FLUIDS) {
|
if (channel == StorageChannel.FLUIDS) {
|
||||||
if (te instanceof ITileStorageMonitorable
|
if (te instanceof ITileStorageMonitorable tsm) {
|
||||||
&& ((ITileStorageMonitorable) te).getMonitorable(d, src) != null) {
|
final IStorageMonitorable monitorable = tsm.getMonitorable(d, src);
|
||||||
return ((ITileStorageMonitorable) te).getMonitorable(d, src).getFluidInventory();
|
return monitorable != null ? monitorable.getFluidInventory() : null;
|
||||||
} else if (Platform.getPartFromTE(te, d.getOpposite()) instanceof ITileStorageMonitorable part
|
} else {
|
||||||
&& part.getMonitorable(d, src) != null) {
|
final IStorageMonitorable monitorable = getMonitorablePart(te, d, src);
|
||||||
return part.getMonitorable(d, src).getFluidInventory();
|
return monitorable != null ? monitorable.getFluidInventory() : null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static IStorageMonitorable getMonitorablePart(TileEntity te, ForgeDirection d, BaseActionSource src) {
|
||||||
|
final IPart part = Platform.getPartFromTE(te, d);
|
||||||
|
return part instanceof ITileStorageMonitorable monitorablePart ? monitorablePart.getMonitorable(d, src) : null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user