mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-19 04:06:43 -04:00
buildcraft drivers and some refactored tile entity interface driver logic into abstract class
This commit is contained in:
parent
80710afada
commit
f730b1eb6a
@ -1,7 +1,9 @@
|
|||||||
package li.cil.oc;
|
package li.cil.oc;
|
||||||
|
|
||||||
|
import cpw.mods.fml.common.Loader;
|
||||||
import cpw.mods.fml.common.Mod;
|
import cpw.mods.fml.common.Mod;
|
||||||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||||
|
import li.cil.oc.driver.buildcraft.ComponentsBuildCraft;
|
||||||
import li.cil.oc.driver.vanilla.ComponentsVanilla;
|
import li.cil.oc.driver.vanilla.ComponentsVanilla;
|
||||||
|
|
||||||
@Mod(modid = "OpenComputers|Components", name = "OpenComponents", version = "1.0.0", dependencies = "required-after:OpenComputers@[1.2.0,)")
|
@Mod(modid = "OpenComputers|Components", name = "OpenComponents", version = "1.0.0", dependencies = "required-after:OpenComputers@[1.2.0,)")
|
||||||
@ -12,5 +14,8 @@ public class OpenComponents {
|
|||||||
@Mod.EventHandler
|
@Mod.EventHandler
|
||||||
public static void init(final FMLInitializationEvent e) {
|
public static void init(final FMLInitializationEvent e) {
|
||||||
ComponentsVanilla.register();
|
ComponentsVanilla.register();
|
||||||
|
if (Loader.isModLoaded("BuildCraft|Core")) {
|
||||||
|
ComponentsBuildCraft.register();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
22
src/main/java/li/cil/oc/driver/TileEntityDriver.java
Normal file
22
src/main/java/li/cil/oc/driver/TileEntityDriver.java
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
package li.cil.oc.driver;
|
||||||
|
|
||||||
|
import li.cil.oc.util.TileEntityLookup;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.tileentity.TileEntity;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
public abstract class TileEntityDriver implements li.cil.oc.api.driver.Block {
|
||||||
|
public abstract Class<?> getFilterClass();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean worksWith(final World world, final ItemStack stack) {
|
||||||
|
final Class clazz = TileEntityLookup.get(world, stack);
|
||||||
|
return clazz != null && getFilterClass().isAssignableFrom(clazz);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean worksWith(final World world, final int x, final int y, final int z) {
|
||||||
|
final TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
|
||||||
|
return tileEntity != null && getFilterClass().isAssignableFrom(tileEntity.getClass());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
package li.cil.oc.driver.buildcraft;
|
||||||
|
|
||||||
|
import li.cil.oc.api.Driver;
|
||||||
|
|
||||||
|
public final class ComponentsBuildCraft {
|
||||||
|
private ComponentsBuildCraft() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void register() {
|
||||||
|
Driver.add(new DriverPipe());
|
||||||
|
Driver.add(new DriverPowerReceptor());
|
||||||
|
}
|
||||||
|
}
|
42
src/main/java/li/cil/oc/driver/buildcraft/DriverPipe.java
Normal file
42
src/main/java/li/cil/oc/driver/buildcraft/DriverPipe.java
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
package li.cil.oc.driver.buildcraft;
|
||||||
|
|
||||||
|
import buildcraft.api.transport.IPipe;
|
||||||
|
import li.cil.oc.api.network.Arguments;
|
||||||
|
import li.cil.oc.api.network.Callback;
|
||||||
|
import li.cil.oc.api.network.Context;
|
||||||
|
import li.cil.oc.api.network.ManagedEnvironment;
|
||||||
|
import li.cil.oc.driver.ManagedTileEntityEnvironment;
|
||||||
|
import li.cil.oc.driver.TileEntityDriver;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
public final class DriverPipe extends TileEntityDriver {
|
||||||
|
@Override
|
||||||
|
public Class<?> getFilterClass() {
|
||||||
|
return IPipe.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ManagedEnvironment createEnvironment(final World world, final int x, final int y, final int z) {
|
||||||
|
return new Environment((IPipe) world.getBlockTileEntity(x, y, z));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final class Environment extends ManagedTileEntityEnvironment<IPipe> {
|
||||||
|
public Environment(IPipe tileEntity) {
|
||||||
|
super(tileEntity, "pipe");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Callback
|
||||||
|
public Object[] hasGate(final Context context, final Arguments args) {
|
||||||
|
return new Object[]{tileEntity.hasGate()};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Callback
|
||||||
|
public Object[] isWired(final Context context, final Arguments args) {
|
||||||
|
try {
|
||||||
|
return new Object[]{tileEntity.isWired(IPipe.WireColor.valueOf(args.checkString(0)))};
|
||||||
|
} catch (Throwable ignored) {
|
||||||
|
}
|
||||||
|
return new Object[]{false};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,65 @@
|
|||||||
|
package li.cil.oc.driver.buildcraft;
|
||||||
|
|
||||||
|
import buildcraft.api.power.IPowerReceptor;
|
||||||
|
import buildcraft.api.power.PowerHandler;
|
||||||
|
import li.cil.oc.api.network.Arguments;
|
||||||
|
import li.cil.oc.api.network.Callback;
|
||||||
|
import li.cil.oc.api.network.Context;
|
||||||
|
import li.cil.oc.api.network.ManagedEnvironment;
|
||||||
|
import li.cil.oc.driver.ManagedTileEntityEnvironment;
|
||||||
|
import li.cil.oc.driver.TileEntityDriver;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraftforge.common.ForgeDirection;
|
||||||
|
|
||||||
|
public final class DriverPowerReceptor extends TileEntityDriver {
|
||||||
|
@Override
|
||||||
|
public Class<?> getFilterClass() {
|
||||||
|
return IPowerReceptor.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ManagedEnvironment createEnvironment(final World world, final int x, final int y, final int z) {
|
||||||
|
return new Environment((IPowerReceptor) world.getBlockTileEntity(x, y, z));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final class Environment extends ManagedTileEntityEnvironment<IPowerReceptor> {
|
||||||
|
public Environment(IPowerReceptor tileEntity) {
|
||||||
|
super(tileEntity, "power_receptor");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Callback
|
||||||
|
public Object[] getActivationEnergy(final Context context, final Arguments args) {
|
||||||
|
final ForgeDirection side = args.count() > 0 ? ForgeDirection.getOrientation(args.checkInteger(0)) : ForgeDirection.UNKNOWN;
|
||||||
|
final PowerHandler.PowerReceiver powerReceiver = tileEntity.getPowerReceiver(side);
|
||||||
|
return new Object[]{powerReceiver.getActivationEnergy()};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Callback
|
||||||
|
public Object[] getEnergyStored(final Context context, final Arguments args) {
|
||||||
|
final ForgeDirection side = args.count() > 0 ? ForgeDirection.getOrientation(args.checkInteger(0)) : ForgeDirection.UNKNOWN;
|
||||||
|
final PowerHandler.PowerReceiver powerReceiver = tileEntity.getPowerReceiver(side);
|
||||||
|
return new Object[]{powerReceiver.getEnergyStored()};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Callback
|
||||||
|
public Object[] getMaxEnergyReceived(final Context context, final Arguments args) {
|
||||||
|
final ForgeDirection side = args.count() > 0 ? ForgeDirection.getOrientation(args.checkInteger(0)) : ForgeDirection.UNKNOWN;
|
||||||
|
final PowerHandler.PowerReceiver powerReceiver = tileEntity.getPowerReceiver(side);
|
||||||
|
return new Object[]{powerReceiver.getMaxEnergyReceived()};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Callback
|
||||||
|
public Object[] getMaxEnergyStored(final Context context, final Arguments args) {
|
||||||
|
final ForgeDirection side = args.count() > 0 ? ForgeDirection.getOrientation(args.checkInteger(0)) : ForgeDirection.UNKNOWN;
|
||||||
|
final PowerHandler.PowerReceiver powerReceiver = tileEntity.getPowerReceiver(side);
|
||||||
|
return new Object[]{powerReceiver.getMaxEnergyStored()};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Callback
|
||||||
|
public Object[] getMinEnergyReceived(final Context context, final Arguments args) {
|
||||||
|
final ForgeDirection side = args.count() > 0 ? ForgeDirection.getOrientation(args.checkInteger(0)) : ForgeDirection.UNKNOWN;
|
||||||
|
final PowerHandler.PowerReceiver powerReceiver = tileEntity.getPowerReceiver(side);
|
||||||
|
return new Object[]{powerReceiver.getMinEnergyReceived()};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -13,8 +13,8 @@ import net.minecraft.tileentity.TileEntityBeacon;
|
|||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.oredict.OreDictionary;
|
import net.minecraftforge.oredict.OreDictionary;
|
||||||
|
|
||||||
public class DriverBeacon extends DriverBlock {
|
public final class DriverBeacon extends DriverBlock {
|
||||||
public DriverBeacon() {
|
DriverBeacon() {
|
||||||
super(new ItemStack(Block.beacon, 1, OreDictionary.WILDCARD_VALUE));
|
super(new ItemStack(Block.beacon, 1, OreDictionary.WILDCARD_VALUE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -23,7 +23,7 @@ public class DriverBeacon extends DriverBlock {
|
|||||||
return new Environment((TileEntityBeacon) world.getBlockTileEntity(x, y, z));
|
return new Environment((TileEntityBeacon) world.getBlockTileEntity(x, y, z));
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Environment extends ManagedTileEntityEnvironment<TileEntityBeacon> {
|
public static final class Environment extends ManagedTileEntityEnvironment<TileEntityBeacon> {
|
||||||
public Environment(final TileEntityBeacon tileEntity) {
|
public Environment(final TileEntityBeacon tileEntity) {
|
||||||
super(tileEntity, "beacon");
|
super(tileEntity, "beacon");
|
||||||
}
|
}
|
||||||
|
@ -13,9 +13,10 @@ import net.minecraft.tileentity.TileEntityBrewingStand;
|
|||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.oredict.OreDictionary;
|
import net.minecraftforge.oredict.OreDictionary;
|
||||||
|
|
||||||
public class DriverBrewingStand extends DriverBlock {
|
public final class DriverBrewingStand extends DriverBlock {
|
||||||
public DriverBrewingStand() {
|
DriverBrewingStand() {
|
||||||
super(new ItemStack(Item.brewingStand), new ItemStack(Block.brewingStand, 1, OreDictionary.WILDCARD_VALUE));
|
super(new ItemStack(Item.brewingStand),
|
||||||
|
new ItemStack(Block.brewingStand, 1, OreDictionary.WILDCARD_VALUE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -23,7 +24,7 @@ public class DriverBrewingStand extends DriverBlock {
|
|||||||
return new Environment((TileEntityBrewingStand) world.getBlockTileEntity(x, y, z));
|
return new Environment((TileEntityBrewingStand) world.getBlockTileEntity(x, y, z));
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Environment extends ManagedTileEntityEnvironment<TileEntityBrewingStand> {
|
public static final class Environment extends ManagedTileEntityEnvironment<TileEntityBrewingStand> {
|
||||||
public Environment(final TileEntityBrewingStand tileEntity) {
|
public Environment(final TileEntityBrewingStand tileEntity) {
|
||||||
super(tileEntity, "brewing_stand");
|
super(tileEntity, "brewing_stand");
|
||||||
}
|
}
|
||||||
|
@ -13,8 +13,8 @@ import net.minecraft.tileentity.TileEntityComparator;
|
|||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.oredict.OreDictionary;
|
import net.minecraftforge.oredict.OreDictionary;
|
||||||
|
|
||||||
public class DriverComparator extends DriverBlock {
|
public final class DriverComparator extends DriverBlock {
|
||||||
public DriverComparator() {
|
DriverComparator() {
|
||||||
super(new ItemStack(Item.comparator),
|
super(new ItemStack(Item.comparator),
|
||||||
new ItemStack(Block.redstoneComparatorIdle, 1, OreDictionary.WILDCARD_VALUE),
|
new ItemStack(Block.redstoneComparatorIdle, 1, OreDictionary.WILDCARD_VALUE),
|
||||||
new ItemStack(Block.redstoneComparatorActive, 1, OreDictionary.WILDCARD_VALUE));
|
new ItemStack(Block.redstoneComparatorActive, 1, OreDictionary.WILDCARD_VALUE));
|
||||||
@ -25,7 +25,7 @@ public class DriverComparator extends DriverBlock {
|
|||||||
return new Environment((TileEntityComparator) world.getBlockTileEntity(x, y, z));
|
return new Environment((TileEntityComparator) world.getBlockTileEntity(x, y, z));
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Environment extends ManagedTileEntityEnvironment<TileEntityComparator> {
|
public static final class Environment extends ManagedTileEntityEnvironment<TileEntityComparator> {
|
||||||
public Environment(final TileEntityComparator tileEntity) {
|
public Environment(final TileEntityComparator tileEntity) {
|
||||||
super(tileEntity, "comparator");
|
super(tileEntity, "comparator");
|
||||||
}
|
}
|
||||||
|
@ -5,9 +5,8 @@ import li.cil.oc.api.network.Callback;
|
|||||||
import li.cil.oc.api.network.Context;
|
import li.cil.oc.api.network.Context;
|
||||||
import li.cil.oc.api.network.ManagedEnvironment;
|
import li.cil.oc.api.network.ManagedEnvironment;
|
||||||
import li.cil.oc.driver.ManagedTileEntityEnvironment;
|
import li.cil.oc.driver.ManagedTileEntityEnvironment;
|
||||||
import li.cil.oc.util.TileEntityLookup;
|
import li.cil.oc.driver.TileEntityDriver;
|
||||||
import net.minecraft.item.ItemStack;
|
import li.cil.oc.util.TypeConversion;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.common.ForgeDirection;
|
import net.minecraftforge.common.ForgeDirection;
|
||||||
import net.minecraftforge.fluids.FluidTankInfo;
|
import net.minecraftforge.fluids.FluidTankInfo;
|
||||||
@ -15,17 +14,10 @@ import net.minecraftforge.fluids.IFluidHandler;
|
|||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class DriverFluidHandler implements li.cil.oc.api.driver.Block {
|
public final class DriverFluidHandler extends TileEntityDriver {
|
||||||
@Override
|
@Override
|
||||||
public boolean worksWith(final World world, final ItemStack stack) {
|
public Class<?> getFilterClass() {
|
||||||
final Class clazz = TileEntityLookup.get(world, stack);
|
return IFluidHandler.class;
|
||||||
return clazz != null && IFluidHandler.class.isAssignableFrom(clazz);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean worksWith(final World world, final int x, final int y, final int z) {
|
|
||||||
final TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
|
|
||||||
return tileEntity != null && tileEntity instanceof IFluidHandler;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -33,7 +25,7 @@ public class DriverFluidHandler implements li.cil.oc.api.driver.Block {
|
|||||||
return new Environment((IFluidHandler) world.getBlockTileEntity(x, y, z));
|
return new Environment((IFluidHandler) world.getBlockTileEntity(x, y, z));
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Environment extends ManagedTileEntityEnvironment<IFluidHandler> {
|
public static final class Environment extends ManagedTileEntityEnvironment<IFluidHandler> {
|
||||||
public Environment(final IFluidHandler tileEntity) {
|
public Environment(final IFluidHandler tileEntity) {
|
||||||
super(tileEntity, "fluid_handler");
|
super(tileEntity, "fluid_handler");
|
||||||
}
|
}
|
||||||
@ -44,7 +36,7 @@ public class DriverFluidHandler implements li.cil.oc.api.driver.Block {
|
|||||||
FluidTankInfo[] info = tileEntity.getTankInfo(side);
|
FluidTankInfo[] info = tileEntity.getTankInfo(side);
|
||||||
Map[] result = new Map[info.length];
|
Map[] result = new Map[info.length];
|
||||||
for (int i = 0; i < info.length; ++i) {
|
for (int i = 0; i < info.length; ++i) {
|
||||||
result[i] = DriverFluidTank.convertInfo(info[i]);
|
result[i] = TypeConversion.toMap(info[i]);
|
||||||
}
|
}
|
||||||
return new Object[]{result};
|
return new Object[]{result};
|
||||||
}
|
}
|
||||||
|
@ -5,28 +5,16 @@ import li.cil.oc.api.network.Callback;
|
|||||||
import li.cil.oc.api.network.Context;
|
import li.cil.oc.api.network.Context;
|
||||||
import li.cil.oc.api.network.ManagedEnvironment;
|
import li.cil.oc.api.network.ManagedEnvironment;
|
||||||
import li.cil.oc.driver.ManagedTileEntityEnvironment;
|
import li.cil.oc.driver.ManagedTileEntityEnvironment;
|
||||||
import li.cil.oc.util.TileEntityLookup;
|
import li.cil.oc.driver.TileEntityDriver;
|
||||||
import net.minecraft.item.ItemStack;
|
import li.cil.oc.util.TypeConversion;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.fluids.Fluid;
|
|
||||||
import net.minecraftforge.fluids.FluidTankInfo;
|
import net.minecraftforge.fluids.FluidTankInfo;
|
||||||
import net.minecraftforge.fluids.IFluidTank;
|
import net.minecraftforge.fluids.IFluidTank;
|
||||||
|
|
||||||
import java.util.HashMap;
|
public final class DriverFluidTank extends TileEntityDriver {
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class DriverFluidTank implements li.cil.oc.api.driver.Block {
|
|
||||||
@Override
|
@Override
|
||||||
public boolean worksWith(final World world, final ItemStack stack) {
|
public Class<?> getFilterClass() {
|
||||||
final Class clazz = TileEntityLookup.get(world, stack);
|
return IFluidTank.class;
|
||||||
return clazz != null && IFluidTank.class.isAssignableFrom(clazz);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean worksWith(final World world, final int x, final int y, final int z) {
|
|
||||||
final TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
|
|
||||||
return tileEntity != null && tileEntity instanceof IFluidTank;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -34,7 +22,7 @@ public class DriverFluidTank implements li.cil.oc.api.driver.Block {
|
|||||||
return new Environment((IFluidTank) world.getBlockTileEntity(x, y, z));
|
return new Environment((IFluidTank) world.getBlockTileEntity(x, y, z));
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Environment extends ManagedTileEntityEnvironment<IFluidTank> {
|
public static final class Environment extends ManagedTileEntityEnvironment<IFluidTank> {
|
||||||
public Environment(final IFluidTank tileEntity) {
|
public Environment(final IFluidTank tileEntity) {
|
||||||
super(tileEntity, "fluid_tank");
|
super(tileEntity, "fluid_tank");
|
||||||
}
|
}
|
||||||
@ -42,24 +30,7 @@ public class DriverFluidTank implements li.cil.oc.api.driver.Block {
|
|||||||
@Callback
|
@Callback
|
||||||
public Object[] getInfo(final Context context, final Arguments args) {
|
public Object[] getInfo(final Context context, final Arguments args) {
|
||||||
final FluidTankInfo info = tileEntity.getInfo();
|
final FluidTankInfo info = tileEntity.getInfo();
|
||||||
return new Object[]{convertInfo(info)};
|
return new Object[]{TypeConversion.toMap(info)};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map convertInfo(final FluidTankInfo info) {
|
|
||||||
final Map<String, Object> map = new HashMap<String, Object>();
|
|
||||||
map.put("capacity", info.capacity);
|
|
||||||
if (info.fluid != null) {
|
|
||||||
map.put("amount", info.fluid.amount);
|
|
||||||
map.put("id", info.fluid.fluidID);
|
|
||||||
final Fluid fluid = info.fluid.getFluid();
|
|
||||||
if (fluid != null) {
|
|
||||||
map.put("name", fluid.getName());
|
|
||||||
map.put("label", fluid.getLocalizedName());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
map.put("amount", 0);
|
|
||||||
}
|
|
||||||
return map;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -12,8 +12,8 @@ import net.minecraft.tileentity.TileEntityFurnace;
|
|||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.oredict.OreDictionary;
|
import net.minecraftforge.oredict.OreDictionary;
|
||||||
|
|
||||||
public class DriverFurnace extends DriverBlock {
|
public final class DriverFurnace extends DriverBlock {
|
||||||
public DriverFurnace() {
|
DriverFurnace() {
|
||||||
super(new ItemStack(Block.furnaceIdle, 1, OreDictionary.WILDCARD_VALUE),
|
super(new ItemStack(Block.furnaceIdle, 1, OreDictionary.WILDCARD_VALUE),
|
||||||
new ItemStack(Block.furnaceBurning, 1, OreDictionary.WILDCARD_VALUE));
|
new ItemStack(Block.furnaceBurning, 1, OreDictionary.WILDCARD_VALUE));
|
||||||
}
|
}
|
||||||
@ -23,7 +23,7 @@ public class DriverFurnace extends DriverBlock {
|
|||||||
return new Environment((TileEntityFurnace) world.getBlockTileEntity(x, y, z));
|
return new Environment((TileEntityFurnace) world.getBlockTileEntity(x, y, z));
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Environment extends ManagedTileEntityEnvironment<TileEntityFurnace> {
|
public static final class Environment extends ManagedTileEntityEnvironment<TileEntityFurnace> {
|
||||||
public Environment(final TileEntityFurnace tileEntity) {
|
public Environment(final TileEntityFurnace tileEntity) {
|
||||||
super(tileEntity, "furnace");
|
super(tileEntity, "furnace");
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ public class DriverInventory implements li.cil.oc.api.driver.Block {
|
|||||||
return new Environment((IInventory) world.getBlockTileEntity(x, y, z));
|
return new Environment((IInventory) world.getBlockTileEntity(x, y, z));
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Environment extends ManagedTileEntityEnvironment<IInventory> {
|
public static final class Environment extends ManagedTileEntityEnvironment<IInventory> {
|
||||||
public Environment(final IInventory tileEntity) {
|
public Environment(final IInventory tileEntity) {
|
||||||
super(tileEntity, "inventory");
|
super(tileEntity, "inventory");
|
||||||
}
|
}
|
||||||
|
@ -12,8 +12,8 @@ import net.minecraft.tileentity.TileEntityMobSpawner;
|
|||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.oredict.OreDictionary;
|
import net.minecraftforge.oredict.OreDictionary;
|
||||||
|
|
||||||
public class DriverMobSpawner extends DriverBlock {
|
public final class DriverMobSpawner extends DriverBlock {
|
||||||
public DriverMobSpawner() {
|
DriverMobSpawner() {
|
||||||
super(new ItemStack(Block.mobSpawner, 1, OreDictionary.WILDCARD_VALUE));
|
super(new ItemStack(Block.mobSpawner, 1, OreDictionary.WILDCARD_VALUE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ public class DriverMobSpawner extends DriverBlock {
|
|||||||
return new Environment((TileEntityMobSpawner) world.getBlockTileEntity(x, y, z));
|
return new Environment((TileEntityMobSpawner) world.getBlockTileEntity(x, y, z));
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Environment extends ManagedTileEntityEnvironment<TileEntityMobSpawner> {
|
public static final class Environment extends ManagedTileEntityEnvironment<TileEntityMobSpawner> {
|
||||||
public Environment(final TileEntityMobSpawner tileEntity) {
|
public Environment(final TileEntityMobSpawner tileEntity) {
|
||||||
super(tileEntity, "mob_spawner");
|
super(tileEntity, "mob_spawner");
|
||||||
}
|
}
|
||||||
|
@ -12,8 +12,8 @@ import net.minecraft.tileentity.TileEntityRecordPlayer;
|
|||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.oredict.OreDictionary;
|
import net.minecraftforge.oredict.OreDictionary;
|
||||||
|
|
||||||
public class DriverRecordPlayer extends DriverBlock {
|
public final class DriverRecordPlayer extends DriverBlock {
|
||||||
public DriverRecordPlayer() {
|
DriverRecordPlayer() {
|
||||||
super(new ItemStack(Block.jukebox, 1, OreDictionary.WILDCARD_VALUE));
|
super(new ItemStack(Block.jukebox, 1, OreDictionary.WILDCARD_VALUE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ public class DriverRecordPlayer extends DriverBlock {
|
|||||||
return new Environment((TileEntityRecordPlayer) world.getBlockTileEntity(x, y, z));
|
return new Environment((TileEntityRecordPlayer) world.getBlockTileEntity(x, y, z));
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Environment extends ManagedTileEntityEnvironment<TileEntityRecordPlayer> {
|
public static final class Environment extends ManagedTileEntityEnvironment<TileEntityRecordPlayer> {
|
||||||
public Environment(final TileEntityRecordPlayer tileEntity) {
|
public Environment(final TileEntityRecordPlayer tileEntity) {
|
||||||
super(tileEntity, "jukebox");
|
super(tileEntity, "jukebox");
|
||||||
}
|
}
|
||||||
|
47
src/main/java/li/cil/oc/util/TypeConversion.java
Normal file
47
src/main/java/li/cil/oc/util/TypeConversion.java
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
package li.cil.oc.util;
|
||||||
|
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraftforge.fluids.Fluid;
|
||||||
|
import net.minecraftforge.fluids.FluidTankInfo;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public final class TypeConversion {
|
||||||
|
private TypeConversion() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map toMap(final ItemStack value) {
|
||||||
|
if (value == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
final Map<String, Object> map = new HashMap<String, Object>();
|
||||||
|
map.put("id", value.itemID);
|
||||||
|
map.put("damage", value.getItemDamage());
|
||||||
|
map.put("maxDamage", value.getMaxDamage());
|
||||||
|
map.put("size", value.stackSize);
|
||||||
|
map.put("maxSize", value.getMaxStackSize());
|
||||||
|
map.put("hasTag", value.hasTagCompound());
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map toMap(final FluidTankInfo value) {
|
||||||
|
if (value == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
final Map<String, Object> map = new HashMap<String, Object>();
|
||||||
|
map.put("capacity", value.capacity);
|
||||||
|
if (value.fluid != null) {
|
||||||
|
map.put("amount", value.fluid.amount);
|
||||||
|
map.put("id", value.fluid.fluidID);
|
||||||
|
final Fluid fluid = value.fluid.getFluid();
|
||||||
|
if (fluid != null) {
|
||||||
|
map.put("name", fluid.getName());
|
||||||
|
map.put("label", fluid.getLocalizedName());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
map.put("amount", 0);
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user