Skip to content

Commit

Permalink
fix OC API
Browse files Browse the repository at this point in the history
  • Loading branch information
aagrishankov committed Dec 25, 2020
1 parent b90428f commit 7263fcd
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
import extracells.registries.PartEnum;
import extracells.util.FluidUtil;
import li.cil.oc.api.Network;
import li.cil.oc.api.driver.EnvironmentProvider;
import li.cil.oc.api.driver.EnvironmentAware;
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.Environment;
import li.cil.oc.api.network.Node;
import li.cil.oc.api.network.Visibility;
import li.cil.oc.api.prefab.ManagedEnvironment;
Expand All @@ -26,19 +26,19 @@
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;

public class DriverFluidExportBus implements SidedBlock{
public class DriverFluidExportBus implements li.cil.oc.api.driver.Block, EnvironmentAware{

@Override
public boolean worksWith(World world, int x, int y, int z, ForgeDirection side) {
return getExportBus(world, x, y, z, side) != null;
public boolean worksWith(World world, int x, int y, int z) {
return getExportBus(world, x, y, z, ForgeDirection.UNKNOWN) != null;
}

@Override
public ManagedEnvironment createEnvironment(World world, int x, int y, int z, ForgeDirection side) {
public ManagedEnvironment createEnvironment(World world, int x, int y, int z) {
TileEntity tile = world.getTileEntity(x, y, z);
if (tile == null || (!(tile instanceof IPartHost)))
return null;
return new Environment((IPartHost) tile);
return new Enviroment((IPartHost) tile);
}

private static PartFluidExport getExportBus(World world, int x, int y, int z, ForgeDirection dir){
Expand All @@ -59,12 +59,12 @@ private static PartFluidExport getExportBus(World world, int x, int y, int z, Fo
}
}

public class Environment extends ManagedEnvironment implements NamedBlock{
public class Enviroment extends ManagedEnvironment implements NamedBlock{

protected final TileEntity tile;
protected final IPartHost host;

Environment(IPartHost host){
public Enviroment(IPartHost host){
tile = (TileEntity) host;
this.host = host;
setNode(Network.newNode(this, Visibility.Network).
Expand Down Expand Up @@ -127,7 +127,8 @@ public Object[] setFluidExportConfiguration(Context context, Arguments args){
throw new IllegalArgumentException("no such component");
if (!(node instanceof Component))
throw new IllegalArgumentException("no such component");
li.cil.oc.api.network.Environment env = node.host();
Component component = (Component) node;
Environment env = node.host();
if (!(env instanceof Database))
throw new IllegalArgumentException("not a database");
Database database = (Database) env;
Expand Down Expand Up @@ -159,7 +160,7 @@ public Object[] exportFluid(Context context, Arguments args){
return new Object[]{false, "no export bus"};
if (part.getFacingTank() == null)
return new Object[]{false, "no tank"};
int amount = Math.min(args.optInteger(1, 62500), 12500 + part.getSpeedState() * 12500);
int amount = Math.min(args.optInteger(1, 62500), 1250 + part.getSpeedState() * 1250);
boolean didSomething = part.doWork(amount, 1);
if (didSomething)
context.pause(0.25);
Expand All @@ -177,15 +178,14 @@ public int priority() {
}

}
static class Provider implements EnvironmentProvider {
@Override
public Class<? extends li.cil.oc.api.network.Environment> getEnvironment(ItemStack stack) {
if (stack == null)
return null;
if (stack.getItem() == ItemEnum.PARTITEM.getItem() && stack.getItemDamage() == PartEnum.FLUIDEXPORT.ordinal())
return Environment.class;

@Override
public Class<? extends Environment> providedEnvironment(ItemStack stack) {
if(stack == null)
return null;
}
if(stack.getItem() == ItemEnum.PARTITEM.getItem() && stack.getItemDamage() == PartEnum.FLUIDEXPORT.ordinal())
return Enviroment.class;
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
import extracells.registries.PartEnum;
import extracells.util.FluidUtil;
import li.cil.oc.api.Network;
import li.cil.oc.api.driver.EnvironmentProvider;
import li.cil.oc.api.driver.EnvironmentAware;
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;
Expand All @@ -27,15 +26,15 @@
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;

public class DriverFluidImportBus implements SidedBlock {
public class DriverFluidImportBus implements li.cil.oc.api.driver.Block, EnvironmentAware{

@Override
public boolean worksWith(World world, int x, int y, int z, ForgeDirection side) {
return getImportBus(world, x, y, z, side) != null;
public boolean worksWith(World world, int x, int y, int z) {
return getImportBus(world, x, y, z, ForgeDirection.UNKNOWN) != null;
}

@Override
public ManagedEnvironment createEnvironment(World world, int x, int y, int z, ForgeDirection side) {
public ManagedEnvironment createEnvironment(World world, int x, int y, int z) {
TileEntity tile = world.getTileEntity(x, y, z);
if (tile == null || (!(tile instanceof IPartHost)))
return null;
Expand Down Expand Up @@ -65,7 +64,7 @@ public class Enviroment extends ManagedEnvironment implements NamedBlock{
protected final TileEntity tile;
protected final IPartHost host;

Enviroment(IPartHost host){
public Enviroment(IPartHost host){
tile = (TileEntity) host;
this.host = host;
setNode(Network.newNode(this, Visibility.Network).
Expand Down Expand Up @@ -128,6 +127,7 @@ public Object[] setFluidImportConfiguration(Context context, Arguments args){
throw new IllegalArgumentException("no such component");
if (!(node instanceof Component))
throw new IllegalArgumentException("no such component");
Component component = (Component) node;
Environment env = node.host();
if (!(env instanceof Database))
throw new IllegalArgumentException("not a database");
Expand All @@ -150,23 +150,6 @@ public Object[] setFluidImportConfiguration(Context context, Arguments args){
}
}

/*@Callback(doc = "function(side:number, amount:number):boolean -- Make the fluid export bus facing the specified direction perform a single export operation.")
public Object[] exportFluid(Context context, Arguments args){
ForgeDirection dir = ForgeDirection.getOrientation(args.checkInteger(0));
if (dir == null || dir == ForgeDirection.UNKNOWN)
return new Object[]{false, "unknown side"};
PartFluidImport part = getImportBus(tile.getWorldObj(), tile.xCoord, tile.yCoord, tile.zCoord, dir);
if (part == null)
return new Object[]{false, "no export bus"};
if (part.getFacingTank() == null)
return new Object[]{false, "no tank"};
int amount = Math.min(args.optInteger(1, 625), 125 + part.getSpeedState() * 125);
boolean didSomething = part.doWork(amount, 1);
if (didSomething)
context.pause(0.25);
return new Object[]{didSomething};
}*/

@Override
public String preferredName() {
return "me_importbus";
Expand All @@ -179,14 +162,13 @@ public int priority() {

}

static class Provider implements EnvironmentProvider {
@Override
public Class<? extends Environment> getEnvironment(ItemStack stack) {
if(stack == null)
return null;
if(stack.getItem() == ItemEnum.PARTITEM.getItem() && stack.getItemDamage() == PartEnum.FLUIDEXPORT.ordinal())
return Enviroment.class;
@Override
public Class<? extends Environment> providedEnvironment(ItemStack stack) {
if(stack == null)
return null;
}
if(stack.getItem() == ItemEnum.PARTITEM.getItem() && stack.getItemDamage() == PartEnum.FLUIDEXPORT.ordinal())
return Enviroment.class;
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
import extracells.tileentity.TileEntityFluidInterface;
import extracells.util.FluidUtil;
import li.cil.oc.api.Network;
import li.cil.oc.api.driver.EnvironmentProvider;
import li.cil.oc.api.driver.EnvironmentAware;
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.Environment;
import li.cil.oc.api.network.Node;
import li.cil.oc.api.network.Visibility;
import li.cil.oc.api.prefab.ManagedEnvironment;
Expand All @@ -29,20 +29,22 @@
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;

public class DriverFluidInterface implements SidedBlock{
public class DriverFluidInterface implements li.cil.oc.api.driver.Block, EnvironmentAware{

@Override
public boolean worksWith(World world, int x, int y, int z, ForgeDirection side) {
public boolean worksWith(World world, int x, int y, int z) {
TileEntity tile = world.getTileEntity(x, y, z);
return tile != null && (getFluidInterface(world, x, y, z, side) != null || tile instanceof IFluidInterface);
if (tile == null)
return false;
return getFluidInterface(world, x, y, z, ForgeDirection.UNKNOWN) != null || tile instanceof IFluidInterface;
}

@Override
public ManagedEnvironment createEnvironment(World world, int x, int y, int z, ForgeDirection side) {
public ManagedEnvironment createEnvironment(World world, int x, int y, int z) {
TileEntity tile = world.getTileEntity(x, y, z);
if (tile == null || (!(tile instanceof IPartHost || tile instanceof IFluidInterface)))
return null;
return new Environment(tile);
return new Enviroment(tile);
}

private static PartFluidInterface getFluidInterface(World world, int x, int y, int z, ForgeDirection dir){
Expand All @@ -63,12 +65,12 @@ private static PartFluidInterface getFluidInterface(World world, int x, int y, i
}
}

public class Environment extends ManagedEnvironment implements NamedBlock{
public class Enviroment extends ManagedEnvironment implements NamedBlock{

protected final TileEntity tile;
protected final IPartHost host;

Environment(TileEntity tile){
public Enviroment(TileEntity tile){
this.tile = tile;
this.host = tile instanceof IPartHost ? (IPartHost) tile : null;
setNode(Network.newNode(this, Visibility.Network).
Expand Down Expand Up @@ -122,7 +124,7 @@ public Object[] setFluidInterfaceConfiguration(Context context, Arguments args){
if (!(node instanceof Component))
throw new IllegalArgumentException("no such component");
Component component = (Component) node;
li.cil.oc.api.network.Environment env = node.host();
Environment env = node.host();
if (!(env instanceof Database))
throw new IllegalArgumentException("not a database");
Database database = (Database) env;
Expand Down Expand Up @@ -155,16 +157,15 @@ public int priority() {

}

static class Provider implements EnvironmentProvider {
@Override
public Class<? extends li.cil.oc.api.network.Environment> getEnvironment(ItemStack stack) {
if (stack == null)
return null;
if (stack.getItem() == ItemEnum.PARTITEM.getItem() && stack.getItemDamage() == PartEnum.INTERFACE.ordinal())
return Environment.class;
if (stack.getItem() == Item.getItemFromBlock(BlockEnum.ECBASEBLOCK.getBlock()) && stack.getItemDamage() == 0)
return Environment.class;
@Override
public Class<? extends Environment> providedEnvironment(ItemStack stack) {
if(stack == null)
return null;
}
if(stack.getItem() == ItemEnum.PARTITEM.getItem() && stack.getItemDamage() == PartEnum.INTERFACE.ordinal())
return Enviroment.class;
if(stack.getItem() == Item.getItemFromBlock(BlockEnum.ECBASEBLOCK.getBlock()) && stack.getItemDamage() == 0)
return Enviroment.class;
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,43 @@
import extracells.registries.ItemEnum;
import extracells.registries.PartEnum;
import li.cil.oc.api.Network;
import li.cil.oc.api.driver.EnvironmentProvider;
import li.cil.oc.api.driver.EnvironmentAware;
import li.cil.oc.api.driver.NamedBlock;
import li.cil.oc.api.driver.SidedBlock;
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.Environment;
import li.cil.oc.api.network.Visibility;
import li.cil.oc.api.prefab.ManagedEnvironment;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;

public class DriverOreDictExportBus implements SidedBlock{
public class DriverOreDictExportBus implements li.cil.oc.api.driver.Block, EnvironmentAware{

@Override
public boolean worksWith(World world, int x, int y, int z, ForgeDirection side) {
return getExportBus(world, x, y, z, side) != null;
public boolean worksWith(World world, int x, int y, int z) {
return getExportBus(world, x, y, z, ForgeDirection.UNKNOWN) != null;
}

@Override
public ManagedEnvironment createEnvironment(World world, int x, int y, int z, ForgeDirection side) {
public ManagedEnvironment createEnvironment(World world, int x, int y, int z) {
TileEntity tile = world.getTileEntity(x, y, z);
if (!(tile instanceof IPartHost))
if (tile == null || (!(tile instanceof IPartHost)))
return null;
return new Environment((IPartHost) tile);
return new Enviroment((IPartHost) tile);
}

private static PartOreDictExporter getExportBus(World world, int x, int y, int z, ForgeDirection dir){
TileEntity tile = world.getTileEntity(x, y, z);
if ((!(tile instanceof IPartHost)))
if (tile == null || (!(tile instanceof IPartHost)))
return null;
IPartHost host = (IPartHost) tile;
if(dir == null || dir == ForgeDirection.UNKNOWN){
for (ForgeDirection side: ForgeDirection.VALID_DIRECTIONS){
IPart part = host.getPart(side);
if (part instanceof PartOreDictExporter)
if (part != null && part instanceof PartOreDictExporter)
return (PartOreDictExporter) part;
}
return null;
Expand All @@ -52,12 +52,12 @@ private static PartOreDictExporter getExportBus(World world, int x, int y, int z
}
}

public static class Environment extends ManagedEnvironment implements NamedBlock{
public class Enviroment extends ManagedEnvironment implements NamedBlock{

protected final TileEntity tile;
protected final IPartHost host;

Environment(IPartHost host){
public Enviroment(IPartHost host){
tile = (TileEntity) host;
this.host = host;
setNode(Network.newNode(this, Visibility.Network).
Expand Down Expand Up @@ -102,13 +102,13 @@ public int priority() {

}

static class Provider implements EnvironmentProvider {
@Override
public Class<? extends li.cil.oc.api.network.Environment> getEnvironment(ItemStack stack){
if (stack.getItem() == ItemEnum.PARTITEM.getItem() && stack.getItemDamage() == PartEnum.OREDICTEXPORTBUS.ordinal())
return Environment.class;
@Override
public Class<? extends Environment> providedEnvironment(ItemStack stack) {
if(stack == null)
return null;
}
if(stack.getItem() == ItemEnum.PARTITEM.getItem() && stack.getItemDamage() == PartEnum.OREDICTEXPORTBUS.ordinal())
return Enviroment.class;
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,9 @@ object OpenComputers {

def init(){
Driver.add(new DriverFluidExportBus)
Driver.add(new DriverFluidExportBus.Provider)
Driver.add(new DriverFluidImportBus)
Driver.add(new DriverFluidImportBus.Provider)
Driver.add(new DriverOreDictExportBus)
Driver.add(new DriverOreDictExportBus.Provider)
Driver.add(new DriverFluidInterface)
Driver.add(new DriverFluidInterface.Provider)
if(Integration.Mods.MEKANISMGAS.isEnabled){
Driver.add(new DriverGasExportBus)
Driver.add(new DriverGasExportBus.Provider)
Expand Down

0 comments on commit 7263fcd

Please sign in to comment.