mirror of
https://github.com/GTNewHorizons/AE2FluidCraft-Rework.git
synced 2026-11-11 15:57:55 +00:00
oc api for me dual interface
This commit is contained in:
1 parent
1c791480d5
commit
3d5ffbba4c
3 files changed
+141
No files matched your search
@@ -15,9 +15,11 @@ import com.glodblock.github.network.CPacketSwitchGuis;
|
||||
import com.glodblock.github.util.NameConst;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.StatCollector;
|
||||
@@ -48,6 +50,16 @@ public class GuiFluidInterface extends AEBaseGui {
|
||||
this.ySize = 231;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void func_146977_a(final Slot s) {
|
||||
try {
|
||||
GuiContainer.class
|
||||
.getDeclaredMethod("func_146977_a_original", Slot.class)
|
||||
.invoke(this, s);
|
||||
} catch (final Exception ignore) {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void initGui()
|
||||
|
||||
+127
@@ -0,0 +1,127 @@
|
||||
package com.glodblock.github.crossmod.opencomputers;
|
||||
|
||||
import appeng.api.parts.IPartHost;
|
||||
import com.glodblock.github.common.parts.PartFluidInterface;
|
||||
import com.glodblock.github.common.tile.TileFluidInterface;
|
||||
import com.glodblock.github.loader.ItemAndBlockHolder;
|
||||
import com.glodblock.github.util.DualityFluidInterface;
|
||||
import com.glodblock.github.util.NameConst;
|
||||
import com.glodblock.github.util.Util;
|
||||
import li.cil.oc.api.driver.EnvironmentProvider;
|
||||
import li.cil.oc.api.driver.NamedBlock;
|
||||
import li.cil.oc.api.driver.SidedBlock;
|
||||
import li.cil.oc.api.internal.Database;
|
||||
import li.cil.oc.api.machine.Arguments;
|
||||
import li.cil.oc.api.machine.Callback;
|
||||
import li.cil.oc.api.machine.Context;
|
||||
import li.cil.oc.api.network.ManagedEnvironment;
|
||||
import li.cil.oc.api.network.Node;
|
||||
import li.cil.oc.integration.ManagedTileEntityEnvironment;
|
||||
import li.cil.oc.server.network.Component;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
public class DriverDualFluidInterface implements SidedBlock {
|
||||
|
||||
@Override
|
||||
public boolean worksWith(World world, int x, int y, int z, ForgeDirection side) {
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
return isDualFluidInterface(te, side);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ManagedEnvironment createEnvironment(World world, int x, int y, int z, ForgeDirection side) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static class Environment extends ManagedTileEntityEnvironment<DualityFluidInterface> implements NamedBlock {
|
||||
|
||||
public Environment(DualityFluidInterface tileEntity) {
|
||||
super(tileEntity, NameConst.BLOCK_FLUID_INTERFACE);
|
||||
}
|
||||
|
||||
@Callback(doc = "function(index:number):table -- Get the configuration of the dual fluid interface on the specified slot.")
|
||||
public Object[] getFluidInterfaceConfiguration(Context context, Arguments args) {
|
||||
int index = args.checkInteger(0);
|
||||
if (index >= 0 && index < DualityFluidInterface.NUMBER_OF_TANKS) {
|
||||
FluidStack fluid = tileEntity.getConfig().getFluidStackInSlot(index);
|
||||
return new Object[] {fluid == null ? null : new FluidStack(fluid.getFluid(), 1000)};
|
||||
}
|
||||
throw new IllegalArgumentException("invalid slot");
|
||||
}
|
||||
|
||||
@Callback(doc = "function(index:number[, database:address, entry:number]):boolean -- Configure the filter in fluid interface on the specified slot.")
|
||||
public Object[] setFluidInterfaceConfiguration(Context context, Arguments args) {
|
||||
int index = args.checkInteger(0);
|
||||
String address;
|
||||
int entry;
|
||||
if (args.count() == 3){
|
||||
address = args.checkString(1);
|
||||
entry = args.checkInteger(2);
|
||||
} else {
|
||||
tileEntity.getConfig().setFluidInSlot(index, null);
|
||||
context.pause(0.5);
|
||||
return new Object[] {true};
|
||||
}
|
||||
Node node = node().network().node(address);
|
||||
if (!(node instanceof Component))
|
||||
throw new IllegalArgumentException("no such component");
|
||||
if (!(node.host() instanceof Database))
|
||||
throw new IllegalArgumentException("not a database");
|
||||
Database database = (Database) node.host();
|
||||
if (index >= 0 && index < DualityFluidInterface.NUMBER_OF_TANKS) {
|
||||
ItemStack data = database.getStackInSlot(entry - 1);
|
||||
if (data == null) {
|
||||
tileEntity.getConfig().setFluidInSlot(index, null);
|
||||
}
|
||||
else {
|
||||
FluidStack fluid = Util.getFluidFromItem(data);
|
||||
tileEntity.getConfig().setFluidInSlot(index, tileEntity.getStandardFluid(fluid));
|
||||
}
|
||||
context.pause(0.5);
|
||||
return new Object[] {true};
|
||||
}
|
||||
throw new IllegalArgumentException("invalid slot");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String preferredName() {
|
||||
return NameConst.BLOCK_FLUID_INTERFACE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int priority() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isDualFluidInterface(TileEntity te, ForgeDirection face) {
|
||||
if (te != null) {
|
||||
if (te instanceof TileFluidInterface) {
|
||||
return true;
|
||||
}
|
||||
if (te instanceof IPartHost) {
|
||||
return ((IPartHost) te).getPart(face) instanceof PartFluidInterface;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static class Provider implements EnvironmentProvider {
|
||||
Provider() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getEnvironment(ItemStack itemStack) {
|
||||
if (itemStack != null && (itemStack.isItemEqual(ItemAndBlockHolder.FLUID_INTERFACE.stack())
|
||||
|| itemStack.isItemEqual(ItemAndBlockHolder.INTERFACE.stack()))) {
|
||||
return DriverDualFluidInterface.Environment.class;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,6 +9,8 @@ public class OCDriverInit {
|
||||
Driver.add(new DriverOCPatternEditor.Provider());
|
||||
Driver.add(new DriverLevelMaintainer());
|
||||
Driver.add(new DriverLevelMaintainer.Provider());
|
||||
Driver.add(new DriverDualFluidInterface());
|
||||
Driver.add(new DriverDualFluidInterface.Provider());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user