From c7fe1f86ebc5d23c8dd7e316878d506e8895d84c Mon Sep 17 00:00:00 2001 From: aidancbrady Date: Mon, 20 Jul 2015 12:28:18 -0700 Subject: [PATCH] Cleaner CC support with a separate peripheral handler --- .../mekanism/common/block/BlockBounding.java | 22 +++--- .../common/block/BlockEnergyCube.java | 29 ++++---- .../mekanism/common/block/BlockMachine.java | 6 +- .../common/integration/CCPeripheral.java | 62 ++++++++++++++++ .../integration/IComputerIntegration.java | 5 +- .../tile/TileEntityAdvancedBoundingBlock.java | 67 ----------------- .../common/tile/TileEntityBasicMachine.java | 47 ------------ .../common/tile/TileEntityDigitalMiner.java | 47 ------------ .../common/tile/TileEntityElectricPump.java | 47 ------------ .../tile/TileEntityElectrolyticSeparator.java | 47 ------------ .../common/tile/TileEntityEnergyCube.java | 47 ------------ .../common/tile/TileEntityFactory.java | 47 ------------ .../tile/TileEntityFluidicPlenisher.java | 71 ++++--------------- .../common/tile/TileEntityLaserAmplifier.java | 47 ------------ .../tile/TileEntityMetallurgicInfuser.java | 47 ------------ .../common/tile/TileEntityTeleporter.java | 60 ++++------------ .../common/block/BlockGenerator.java | 41 +++++------ .../common/tile/TileEntityGenerator.java | 47 ------------ 18 files changed, 132 insertions(+), 654 deletions(-) create mode 100644 src/main/java/mekanism/common/integration/CCPeripheral.java diff --git a/src/main/java/mekanism/common/block/BlockBounding.java b/src/main/java/mekanism/common/block/BlockBounding.java index cc3eaae8a..a26f808c3 100644 --- a/src/main/java/mekanism/common/block/BlockBounding.java +++ b/src/main/java/mekanism/common/block/BlockBounding.java @@ -1,10 +1,15 @@ package mekanism.common.block; -import java.util.Random; - +import cpw.mods.fml.common.Optional.Interface; +import cpw.mods.fml.common.Optional.Method; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import dan200.computercraft.api.peripheral.IPeripheral; +import dan200.computercraft.api.peripheral.IPeripheralProvider; +import mekanism.common.integration.CCPeripheral; +import mekanism.common.integration.IComputerIntegration; import mekanism.common.tile.TileEntityAdvancedBoundingBlock; import mekanism.common.tile.TileEntityBoundingBlock; - import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; @@ -14,13 +19,8 @@ import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.MovingObjectPosition; import net.minecraft.world.World; -import cpw.mods.fml.common.Optional.Interface; -import cpw.mods.fml.common.Optional.Method; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import dan200.computercraft.api.peripheral.IPeripheral; -import dan200.computercraft.api.peripheral.IPeripheralProvider; +import java.util.Random; @Interface(iface = "dan200.computercraft.api.peripheral.IPeripheralProvider", modid = "ComputerCraft") public class BlockBounding extends Block implements IPeripheralProvider @@ -139,9 +139,9 @@ public class BlockBounding extends Block implements IPeripheralProvider { TileEntity te = world.getTileEntity(x, y, z); - if(te != null && te instanceof IPeripheral) + if(te != null && te instanceof IComputerIntegration) { - return (IPeripheral)te; + return new CCPeripheral((IComputerIntegration)te); } return null; diff --git a/src/main/java/mekanism/common/block/BlockEnergyCube.java b/src/main/java/mekanism/common/block/BlockEnergyCube.java index e87e16cc8..8ddb69399 100644 --- a/src/main/java/mekanism/common/block/BlockEnergyCube.java +++ b/src/main/java/mekanism/common/block/BlockEnergyCube.java @@ -1,8 +1,12 @@ package mekanism.common.block; -import java.util.List; -import java.util.Random; - +import buildcraft.api.tools.IToolWrench; +import cpw.mods.fml.common.Optional.Interface; +import cpw.mods.fml.common.Optional.Method; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import dan200.computercraft.api.peripheral.IPeripheral; +import dan200.computercraft.api.peripheral.IPeripheralProvider; import mekanism.api.energy.IEnergizedItem; import mekanism.common.ItemAttacher; import mekanism.common.Mekanism; @@ -10,12 +14,12 @@ import mekanism.common.MekanismBlocks; import mekanism.common.Tier.EnergyCubeTier; import mekanism.common.base.IEnergyCube; import mekanism.common.base.ISustainedInventory; +import mekanism.common.integration.CCPeripheral; +import mekanism.common.integration.IComputerIntegration; import mekanism.common.item.ItemBlockEnergyCube; import mekanism.common.tile.TileEntityBasicBlock; -import mekanism.common.tile.TileEntityElectricBlock; import mekanism.common.tile.TileEntityEnergyCube; import mekanism.common.util.MekanismUtils; - import net.minecraft.block.Block; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; @@ -27,21 +31,14 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.IIcon; import net.minecraft.util.MathHelper; import net.minecraft.util.MovingObjectPosition; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; -import cpw.mods.fml.common.ModAPIManager; -import cpw.mods.fml.common.Optional.Interface; -import cpw.mods.fml.common.Optional.Method; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import buildcraft.api.tools.IToolWrench; -import dan200.computercraft.api.peripheral.IPeripheral; -import dan200.computercraft.api.peripheral.IPeripheralProvider; +import java.util.List; +import java.util.Random; /** * Block class for handling multiple energy cube block IDs. @@ -341,9 +338,9 @@ public class BlockEnergyCube extends BlockContainer implements IPeripheralProvid { TileEntity te = world.getTileEntity(x, y, z); - if(te != null && te instanceof IPeripheral) + if(te != null && te instanceof IComputerIntegration) { - return (IPeripheral)te; + return new CCPeripheral((IComputerIntegration)te); } return null; diff --git a/src/main/java/mekanism/common/block/BlockMachine.java b/src/main/java/mekanism/common/block/BlockMachine.java index acac61a80..91958730d 100644 --- a/src/main/java/mekanism/common/block/BlockMachine.java +++ b/src/main/java/mekanism/common/block/BlockMachine.java @@ -25,6 +25,8 @@ import mekanism.common.MekanismBlocks; import mekanism.common.Tier.BaseTier; import mekanism.common.base.*; import mekanism.common.base.IFactory.RecipeType; +import mekanism.common.integration.CCPeripheral; +import mekanism.common.integration.IComputerIntegration; import mekanism.common.item.ItemBlockMachine; import mekanism.common.network.PacketElectricChest.ElectricChestMessage; import mekanism.common.network.PacketElectricChest.ElectricChestPacketType; @@ -1302,9 +1304,9 @@ public class BlockMachine extends BlockContainer implements ISpecialBounds, IPer { TileEntity te = world.getTileEntity(x, y, z); - if(te != null && te instanceof IPeripheral) + if(te != null && te instanceof IComputerIntegration) { - return (IPeripheral)te; + return new CCPeripheral((IComputerIntegration)te); } return null; diff --git a/src/main/java/mekanism/common/integration/CCPeripheral.java b/src/main/java/mekanism/common/integration/CCPeripheral.java new file mode 100644 index 000000000..20dedd374 --- /dev/null +++ b/src/main/java/mekanism/common/integration/CCPeripheral.java @@ -0,0 +1,62 @@ +package mekanism.common.integration; + +import cpw.mods.fml.common.Optional; +import dan200.computercraft.api.lua.ILuaContext; +import dan200.computercraft.api.lua.LuaException; +import dan200.computercraft.api.peripheral.IComputerAccess; +import dan200.computercraft.api.peripheral.IPeripheral; + +/** + * Created by aidancbrady on 7/20/15. + */ +public class CCPeripheral implements IPeripheral +{ + public IComputerIntegration computerTile; + + public CCPeripheral(IComputerIntegration tile) + { + computerTile = tile; + } + + @Override + @Optional.Method(modid = "ComputerCraft") + public String getType() + { + return computerTile.getInventoryName(); + } + + @Override + @Optional.Method(modid = "ComputerCraft") + public String[] getMethodNames() + { + return computerTile.getMethods(); + } + + @Override + @Optional.Method(modid = "ComputerCraft") + public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws LuaException, InterruptedException + { + try { + return computerTile.invoke(method, arguments); + } catch(NoSuchMethodException e) { + return new Object[] {"Unknown command."}; + } finally { + return new Object[] {"Error."}; + } + } + + @Override + @Optional.Method(modid = "ComputerCraft") + public void attach(IComputerAccess computer) {} + + @Override + @Optional.Method(modid = "ComputerCraft") + public void detach(IComputerAccess computer) {} + + @Override + @Optional.Method(modid = "ComputerCraft") + public boolean equals(IPeripheral other) + { + return this == other; + } +} diff --git a/src/main/java/mekanism/common/integration/IComputerIntegration.java b/src/main/java/mekanism/common/integration/IComputerIntegration.java index 71e7216e7..7fe1d4b30 100644 --- a/src/main/java/mekanism/common/integration/IComputerIntegration.java +++ b/src/main/java/mekanism/common/integration/IComputerIntegration.java @@ -1,14 +1,11 @@ package mekanism.common.integration; -import cpw.mods.fml.common.Optional; -import dan200.computercraft.api.peripheral.IPeripheral; import net.minecraft.inventory.IInventory; /** * Created by aidancbrady on 7/20/15. */ -@Optional.Interface(iface = "dan200.computercraft.api.peripheral.IPeripheral", modid = "ComputerCraft") -public interface IComputerIntegration extends IInventory, IPeripheral +public interface IComputerIntegration extends IInventory { public String[] getMethods(); diff --git a/src/main/java/mekanism/common/tile/TileEntityAdvancedBoundingBlock.java b/src/main/java/mekanism/common/tile/TileEntityAdvancedBoundingBlock.java index 1824b59dc..ccf6c13d0 100644 --- a/src/main/java/mekanism/common/tile/TileEntityAdvancedBoundingBlock.java +++ b/src/main/java/mekanism/common/tile/TileEntityAdvancedBoundingBlock.java @@ -4,10 +4,6 @@ import cofh.api.energy.IEnergyHandler; import cpw.mods.fml.common.Optional.Interface; import cpw.mods.fml.common.Optional.InterfaceList; import cpw.mods.fml.common.Optional.Method; -import dan200.computercraft.api.lua.ILuaContext; -import dan200.computercraft.api.lua.LuaException; -import dan200.computercraft.api.peripheral.IComputerAccess; -import dan200.computercraft.api.peripheral.IPeripheral; import ic2.api.energy.tile.IEnergySink; import mekanism.api.Coord4D; import mekanism.api.IFilterAccess; @@ -391,38 +387,6 @@ public class TileEntityAdvancedBoundingBlock extends TileEntityBoundingBlock imp } } - @Override - @Method(modid = "ComputerCraft") - public String getType() - { - if(getInv() == null) - { - return null; - } - - return getInv().getType(); - } - - @Override - @Method(modid = "ComputerCraft") - public String[] getMethodNames() - { - return getMethods(); - } - - @Override - @Method(modid = "ComputerCraft") - public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws LuaException, InterruptedException - { - try { - return invoke(method, arguments); - } catch(NoSuchMethodException e) { - return new Object[] {"Unknown command."}; - } finally { - return new Object[] {"Error."}; - } - } - @Override public String[] getMethods() { @@ -445,37 +409,6 @@ public class TileEntityAdvancedBoundingBlock extends TileEntityBoundingBlock imp return getInv().invoke(method, arguments); } - @Override - @Method(modid = "ComputerCraft") - public void attach(IComputerAccess computer) - { - if(getInv() == null) - { - return; - } - - getInv().attach(computer); - } - - @Override - @Method(modid = "ComputerCraft") - public void detach(IComputerAccess computer) - { - if(getInv() == null) - { - return; - } - - getInv().detach(computer); - } - - @Override - @Method(modid = "ComputerCraft") - public boolean equals(IPeripheral other) - { - return this == other; - } - @Override public NBTTagCompound getFilterData(NBTTagCompound nbtTags) { diff --git a/src/main/java/mekanism/common/tile/TileEntityBasicMachine.java b/src/main/java/mekanism/common/tile/TileEntityBasicMachine.java index 098255aa0..a718c3381 100644 --- a/src/main/java/mekanism/common/tile/TileEntityBasicMachine.java +++ b/src/main/java/mekanism/common/tile/TileEntityBasicMachine.java @@ -1,10 +1,5 @@ package mekanism.common.tile; -import cpw.mods.fml.common.Optional.Method; -import dan200.computercraft.api.lua.ILuaContext; -import dan200.computercraft.api.lua.LuaException; -import dan200.computercraft.api.peripheral.IComputerAccess; -import dan200.computercraft.api.peripheral.IPeripheral; import io.netty.buffer.ByteBuf; import mekanism.api.Coord4D; import mekanism.api.MekanismConfig.general; @@ -226,54 +221,12 @@ public abstract class TileEntityBasicMachine, } } - @Override - @Method(modid = "ComputerCraft") - public String getType() - { - return getInventoryName(); - } - - @Override - @Method(modid = "ComputerCraft") - public boolean equals(IPeripheral other) - { - return this == other; - } - - @Override - @Method(modid = "ComputerCraft") - public String[] getMethodNames() - { - return getMethods(); - } - - @Override - @Method(modid = "ComputerCraft") - public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws LuaException, InterruptedException - { - try { - return invoke(method, arguments); - } catch(NoSuchMethodException e) { - return new Object[] {"Unknown command."}; - } finally { - return new Object[] {"Error."}; - } - } - @Override public boolean canSetFacing(int facing) { return facing != 0 && facing != 1; } - @Override - @Method(modid = "ComputerCraft") - public void attach(IComputerAccess computer) {} - - @Override - @Method(modid = "ComputerCraft") - public void detach(IComputerAccess computer) {} - @Override public int[] getAccessibleSlotsFromSide(int side) { diff --git a/src/main/java/mekanism/common/tile/TileEntityDigitalMiner.java b/src/main/java/mekanism/common/tile/TileEntityDigitalMiner.java index 941948c00..34044111a 100644 --- a/src/main/java/mekanism/common/tile/TileEntityDigitalMiner.java +++ b/src/main/java/mekanism/common/tile/TileEntityDigitalMiner.java @@ -1,12 +1,7 @@ package mekanism.common.tile; -import cpw.mods.fml.common.Optional.Method; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import dan200.computercraft.api.lua.ILuaContext; -import dan200.computercraft.api.lua.LuaException; -import dan200.computercraft.api.peripheral.IComputerAccess; -import dan200.computercraft.api.peripheral.IPeripheral; import io.netty.buffer.ByteBuf; import mekanism.api.Chunk3D; import mekanism.api.Coord4D; @@ -1229,33 +1224,6 @@ public class TileEntityDigitalMiner extends TileEntityElectricBlock implements I numPowering--; } - @Override - @Method(modid = "ComputerCraft") - public String getType() - { - return getInventoryName(); - } - - @Override - @Method(modid = "ComputerCraft") - public String[] getMethodNames() - { - return getMethods(); - } - - @Override - @Method(modid = "ComputerCraft") - public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws LuaException, InterruptedException - { - try { - return invoke(method, arguments); - } catch(NoSuchMethodException e) { - return new Object[] {"Unknown command."}; - } finally { - return new Object[] {"Error."}; - } - } - public String[] methods = {"setRadius", "setMin", "setMax", "addFilter", "removeFilter", "addOreFilter", "removeOreFilter", "reset", "start", "stop"}; @Override @@ -1378,21 +1346,6 @@ public class TileEntityDigitalMiner extends TileEntityElectricBlock implements I return null; } - @Override - @Method(modid = "ComputerCraft") - public boolean equals(IPeripheral other) - { - return this == other; - } - - @Override - @Method(modid = "ComputerCraft") - public void attach(IComputerAccess computer) {} - - @Override - @Method(modid = "ComputerCraft") - public void detach(IComputerAccess computer) {} - @Override public NBTTagCompound getFilterData(NBTTagCompound nbtTags) { diff --git a/src/main/java/mekanism/common/tile/TileEntityElectricPump.java b/src/main/java/mekanism/common/tile/TileEntityElectricPump.java index 9359f0cc4..a0ce821e9 100644 --- a/src/main/java/mekanism/common/tile/TileEntityElectricPump.java +++ b/src/main/java/mekanism/common/tile/TileEntityElectricPump.java @@ -1,10 +1,5 @@ package mekanism.common.tile; -import cpw.mods.fml.common.Optional.Method; -import dan200.computercraft.api.lua.ILuaContext; -import dan200.computercraft.api.lua.LuaException; -import dan200.computercraft.api.peripheral.IComputerAccess; -import dan200.computercraft.api.peripheral.IPeripheral; import io.netty.buffer.ByteBuf; import mekanism.api.Coord4D; import mekanism.api.EnumColor; @@ -512,33 +507,6 @@ public class TileEntityElectricPump extends TileEntityElectricBlock implements I return new Object[] {fluidTank}; } - @Override - @Method(modid = "ComputerCraft") - public String getType() - { - return getInventoryName(); - } - - @Override - @Method(modid = "ComputerCraft") - public String[] getMethodNames() - { - return getMethods(); - } - - @Override - @Method(modid = "ComputerCraft") - public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws LuaException, InterruptedException - { - try { - return invoke(method, arguments); - } catch(NoSuchMethodException e) { - return new Object[] {"Unknown command."}; - } finally { - return new Object[] {"Error."}; - } - } - private static final String[] methods = new String[] {"reset"}; @Override @@ -559,19 +527,4 @@ public class TileEntityElectricPump extends TileEntityElectricBlock implements I throw new NoSuchMethodException(); } } - - @Override - @Method(modid = "ComputerCraft") - public void attach(IComputerAccess computer) {} - - @Override - @Method(modid = "ComputerCraft") - public void detach(IComputerAccess computer) {} - - @Override - @Method(modid = "ComputerCraft") - public boolean equals(IPeripheral other) - { - return this == other; - } } diff --git a/src/main/java/mekanism/common/tile/TileEntityElectrolyticSeparator.java b/src/main/java/mekanism/common/tile/TileEntityElectrolyticSeparator.java index 8f49b2100..d5d4ad2dd 100644 --- a/src/main/java/mekanism/common/tile/TileEntityElectrolyticSeparator.java +++ b/src/main/java/mekanism/common/tile/TileEntityElectrolyticSeparator.java @@ -1,10 +1,5 @@ package mekanism.common.tile; -import cpw.mods.fml.common.Optional.Method; -import dan200.computercraft.api.lua.ILuaContext; -import dan200.computercraft.api.lua.LuaException; -import dan200.computercraft.api.peripheral.IComputerAccess; -import dan200.computercraft.api.peripheral.IPeripheral; import io.netty.buffer.ByteBuf; import mekanism.api.Coord4D; import mekanism.api.Range4D; @@ -532,33 +527,6 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp nbtTags.setInteger("dumpRight", dumpRight.ordinal()); } - @Override - @Method(modid = "ComputerCraft") - public String getType() - { - return getInventoryName(); - } - - @Override - @Method(modid = "ComputerCraft") - public String[] getMethodNames() - { - return getMethods(); - } - - @Override - @Method(modid = "ComputerCraft") - public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws LuaException, InterruptedException - { - try { - return invoke(method, arguments); - } catch(NoSuchMethodException e) { - return new Object[] {"Unknown command."}; - } finally { - return new Object[] {"Error."}; - } - } - private static final String[] methods = new String[] {"getStored", "getOutput", "getMaxEnergy", "getEnergyNeeded", "getWater", "getWaterNeeded", "getHydrogen", "getHydrogenNeeded", "getOxygen", "getOxygenNeeded"}; @Override @@ -597,21 +565,6 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp } } - @Override - @Method(modid = "ComputerCraft") - public boolean equals(IPeripheral other) - { - return this == other; - } - - @Override - @Method(modid = "ComputerCraft") - public void attach(IComputerAccess computer) {} - - @Override - @Method(modid = "ComputerCraft") - public void detach(IComputerAccess computer) {} - @Override public boolean canTubeConnect(ForgeDirection side) { diff --git a/src/main/java/mekanism/common/tile/TileEntityEnergyCube.java b/src/main/java/mekanism/common/tile/TileEntityEnergyCube.java index adcdfb791..5949f4235 100644 --- a/src/main/java/mekanism/common/tile/TileEntityEnergyCube.java +++ b/src/main/java/mekanism/common/tile/TileEntityEnergyCube.java @@ -1,10 +1,5 @@ package mekanism.common.tile; -import cpw.mods.fml.common.Optional.Method; -import dan200.computercraft.api.lua.ILuaContext; -import dan200.computercraft.api.lua.LuaException; -import dan200.computercraft.api.peripheral.IComputerAccess; -import dan200.computercraft.api.peripheral.IPeripheral; import io.netty.buffer.ByteBuf; import mekanism.api.Coord4D; import mekanism.api.Range4D; @@ -150,33 +145,6 @@ public class TileEntityEnergyCube extends TileEntityElectricBlock implements ICo return false; } - @Override - @Method(modid = "ComputerCraft") - public String getType() - { - return getInventoryName(); - } - - @Override - @Method(modid = "ComputerCraft") - public String[] getMethodNames() - { - return getMethods(); - } - - @Override - @Method(modid = "ComputerCraft") - public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws LuaException, InterruptedException - { - try { - return invoke(method, arguments); - } catch(NoSuchMethodException e) { - return new Object[] {"Unknown command."}; - } finally { - return new Object[] {"Error."}; - } - } - private static final String[] methods = new String[] {"getStored", "getOutput", "getMaxEnergy", "getEnergyNeeded"}; @Override @@ -203,21 +171,6 @@ public class TileEntityEnergyCube extends TileEntityElectricBlock implements ICo } } - @Override - @Method(modid = "ComputerCraft") - public boolean equals(IPeripheral other) - { - return this == other; - } - - @Override - @Method(modid = "ComputerCraft") - public void attach(IComputerAccess computer) {} - - @Override - @Method(modid = "ComputerCraft") - public void detach(IComputerAccess computer) {} - @Override public void handlePacketData(ByteBuf dataStream) { diff --git a/src/main/java/mekanism/common/tile/TileEntityFactory.java b/src/main/java/mekanism/common/tile/TileEntityFactory.java index a2ee29d7b..4a6716eb4 100644 --- a/src/main/java/mekanism/common/tile/TileEntityFactory.java +++ b/src/main/java/mekanism/common/tile/TileEntityFactory.java @@ -1,12 +1,7 @@ package mekanism.common.tile; -import cpw.mods.fml.common.Optional.Method; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import dan200.computercraft.api.lua.ILuaContext; -import dan200.computercraft.api.lua.LuaException; -import dan200.computercraft.api.peripheral.IComputerAccess; -import dan200.computercraft.api.peripheral.IPeripheral; import io.netty.buffer.ByteBuf; import mekanism.api.Coord4D; import mekanism.api.EnumColor; @@ -782,33 +777,6 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I return tier.getBaseTier().getLocalizedName() + " " + recipeType.getLocalizedName() + " " + super.getInventoryName(); } - @Override - @Method(modid = "ComputerCraft") - public String getType() - { - return getInventoryName(); - } - - @Override - @Method(modid = "ComputerCraft") - public String[] getMethodNames() - { - return getMethods(); - } - - @Override - @Method(modid = "ComputerCraft") - public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws LuaException, InterruptedException - { - try { - return invoke(method, arguments); - } catch(NoSuchMethodException e) { - return new Object[] {"Unknown command."}; - } finally { - return new Object[] {"Error."}; - } - } - private static final String[] methods = new String[] {"getStored", "getProgress", "facing", "canOperate", "getMaxEnergy", "getEnergyNeeded"}; @Override @@ -869,21 +837,6 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I } } - @Override - @Method(modid = "ComputerCraft") - public void attach(IComputerAccess computer) {} - - @Override - @Method(modid = "ComputerCraft") - public void detach(IComputerAccess computer) {} - - @Override - @Method(modid = "ComputerCraft") - public boolean equals(IPeripheral other) - { - return this == other; - } - @Override public void setActive(boolean active) { diff --git a/src/main/java/mekanism/common/tile/TileEntityFluidicPlenisher.java b/src/main/java/mekanism/common/tile/TileEntityFluidicPlenisher.java index f83656a0a..240694104 100644 --- a/src/main/java/mekanism/common/tile/TileEntityFluidicPlenisher.java +++ b/src/main/java/mekanism/common/tile/TileEntityFluidicPlenisher.java @@ -1,10 +1,5 @@ package mekanism.common.tile; -import cpw.mods.fml.common.Optional.Method; -import dan200.computercraft.api.lua.ILuaContext; -import dan200.computercraft.api.lua.LuaException; -import dan200.computercraft.api.peripheral.IComputerAccess; -import dan200.computercraft.api.peripheral.IPeripheral; import io.netty.buffer.ByteBuf; import mekanism.api.Coord4D; import mekanism.api.EnumColor; @@ -503,33 +498,6 @@ public class TileEntityFluidicPlenisher extends TileEntityElectricBlock implemen { return false; } - - @Override - @Method(modid = "ComputerCraft") - public String getType() - { - return getInventoryName(); - } - - @Override - @Method(modid = "ComputerCraft") - public String[] getMethodNames() - { - return getMethods(); - } - - @Override - @Method(modid = "ComputerCraft") - public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws LuaException, InterruptedException - { - try { - return invoke(method, arguments); - } catch(NoSuchMethodException e) { - return new Object[] {"Unknown command."}; - } finally { - return new Object[] {"Error."}; - } - } private static final String[] methods = new String[] {"reset"}; @@ -541,32 +509,17 @@ public class TileEntityFluidicPlenisher extends TileEntityElectricBlock implemen @Override public Object[] invoke(int method, Object[] arguments) throws Exception - { - switch(method) - { - case 0: - activeNodes.clear(); - usedNodes.clear(); - finishedCalc = false; - - return new Object[] {"Plenisher calculation reset."}; - default: - throw new NoSuchMethodException(); - } - } + { + switch(method) + { + case 0: + activeNodes.clear(); + usedNodes.clear(); + finishedCalc = false; - @Override - @Method(modid = "ComputerCraft") - public void attach(IComputerAccess computer) {} - - @Override - @Method(modid = "ComputerCraft") - public void detach(IComputerAccess computer) {} - - @Override - @Method(modid = "ComputerCraft") - public boolean equals(IPeripheral other) - { - return this == other; - } + return new Object[]{"Plenisher calculation reset."}; + default: + throw new NoSuchMethodException(); + } + } } diff --git a/src/main/java/mekanism/common/tile/TileEntityLaserAmplifier.java b/src/main/java/mekanism/common/tile/TileEntityLaserAmplifier.java index ce47ac46c..342fbaff4 100644 --- a/src/main/java/mekanism/common/tile/TileEntityLaserAmplifier.java +++ b/src/main/java/mekanism/common/tile/TileEntityLaserAmplifier.java @@ -1,10 +1,5 @@ package mekanism.common.tile; -import cpw.mods.fml.common.Optional.Method; -import dan200.computercraft.api.lua.ILuaContext; -import dan200.computercraft.api.lua.LuaException; -import dan200.computercraft.api.peripheral.IComputerAccess; -import dan200.computercraft.api.peripheral.IPeripheral; import io.netty.buffer.ByteBuf; import mekanism.api.Coord4D; import mekanism.api.MekanismConfig.general; @@ -314,33 +309,6 @@ public class TileEntityLaserAmplifier extends TileEntityContainerBlock implement { return MAX_ENERGY; } - - @Override - @Method(modid = "ComputerCraft") - public String getType() - { - return getInventoryName(); - } - - @Override - @Method(modid = "ComputerCraft") - public String[] getMethodNames() - { - return getMethods(); - } - - @Override - @Method(modid = "ComputerCraft") - public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws LuaException, InterruptedException - { - try { - return invoke(method, arguments); - } catch(NoSuchMethodException e) { - return new Object[] {"Unknown command."}; - } finally { - return new Object[] {"Error."}; - } - } private static final String[] methods = new String[] {"getStored", "getMaxEnergy"}; @@ -363,19 +331,4 @@ public class TileEntityLaserAmplifier extends TileEntityContainerBlock implement throw new NoSuchMethodException(); } } - - @Override - @Method(modid = "ComputerCraft") - public void attach(IComputerAccess computer) {} - - @Override - @Method(modid = "ComputerCraft") - public void detach(IComputerAccess computer) {} - - @Override - @Method(modid = "ComputerCraft") - public boolean equals(IPeripheral other) - { - return this == other; - } } diff --git a/src/main/java/mekanism/common/tile/TileEntityMetallurgicInfuser.java b/src/main/java/mekanism/common/tile/TileEntityMetallurgicInfuser.java index deb25ef27..5bbbc5d66 100644 --- a/src/main/java/mekanism/common/tile/TileEntityMetallurgicInfuser.java +++ b/src/main/java/mekanism/common/tile/TileEntityMetallurgicInfuser.java @@ -1,10 +1,5 @@ package mekanism.common.tile; -import cpw.mods.fml.common.Optional.Method; -import dan200.computercraft.api.lua.ILuaContext; -import dan200.computercraft.api.lua.LuaException; -import dan200.computercraft.api.peripheral.IComputerAccess; -import dan200.computercraft.api.peripheral.IPeripheral; import io.netty.buffer.ByteBuf; import mekanism.api.Coord4D; import mekanism.api.EnumColor; @@ -364,33 +359,6 @@ public class TileEntityMetallurgicInfuser extends TileEntityNoisyElectricBlock i return data; } - @Override - @Method(modid = "ComputerCraft") - public String getType() - { - return getInventoryName(); - } - - @Override - @Method(modid = "ComputerCraft") - public String[] getMethodNames() - { - return getMethods(); - } - - @Override - @Method(modid = "ComputerCraft") - public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws LuaException, InterruptedException - { - try { - return invoke(method, arguments); - } catch(NoSuchMethodException e) { - return new Object[] {"Unknown command."}; - } finally { - return new Object[] {"Error."}; - } - } - private static final String[] methods = new String[] {"getStored", "getProgress", "facing", "canOperate", "getMaxEnergy", "getEnergyNeeded", "getInfuse", "getInfuseNeeded"}; @Override @@ -425,21 +393,6 @@ public class TileEntityMetallurgicInfuser extends TileEntityNoisyElectricBlock i } } - @Override - @Method(modid = "ComputerCraft") - public boolean equals(IPeripheral other) - { - return this == other; - } - - @Override - @Method(modid = "ComputerCraft") - public void attach(IComputerAccess computer) {} - - @Override - @Method(modid = "ComputerCraft") - public void detach(IComputerAccess computer) {} - @Override public int[] getAccessibleSlotsFromSide(int side) { diff --git a/src/main/java/mekanism/common/tile/TileEntityTeleporter.java b/src/main/java/mekanism/common/tile/TileEntityTeleporter.java index fe534f6c4..360abb24f 100644 --- a/src/main/java/mekanism/common/tile/TileEntityTeleporter.java +++ b/src/main/java/mekanism/common/tile/TileEntityTeleporter.java @@ -1,13 +1,9 @@ package mekanism.common.tile; +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; import io.netty.buffer.ByteBuf; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Set; - import mekanism.api.Chunk3D; import mekanism.api.Coord4D; import mekanism.common.Mekanism; @@ -17,6 +13,7 @@ import mekanism.common.block.BlockMachine.MachineType; import mekanism.common.chunkloading.IChunkLoader; import mekanism.common.frequency.Frequency; import mekanism.common.frequency.FrequencyManager; +import mekanism.common.integration.IComputerIntegration; import mekanism.common.network.PacketPortalFX.PortalFXMessage; import mekanism.common.network.PacketTileEntity.TileEntityMessage; import mekanism.common.util.ChargeUtils; @@ -36,18 +33,10 @@ import net.minecraft.world.WorldServer; import net.minecraftforge.common.ForgeChunkManager; import net.minecraftforge.common.ForgeChunkManager.Ticket; import net.minecraftforge.common.ForgeChunkManager.Type; -import cpw.mods.fml.common.FMLCommonHandler; -import cpw.mods.fml.common.Optional.Interface; -import cpw.mods.fml.common.Optional.Method; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import dan200.computercraft.api.lua.ILuaContext; -import dan200.computercraft.api.lua.LuaException; -import dan200.computercraft.api.peripheral.IComputerAccess; -import dan200.computercraft.api.peripheral.IPeripheral; -@Interface(iface = "dan200.computercraft.api.peripheral.IPeripheral", modid = "ComputerCraft") -public class TileEntityTeleporter extends TileEntityElectricBlock implements IPeripheral, IChunkLoader +import java.util.*; + +public class TileEntityTeleporter extends TileEntityElectricBlock implements IComputerIntegration, IChunkLoader { private MinecraftServer server = MinecraftServer.getServer(); @@ -655,23 +644,16 @@ public class TileEntityTeleporter extends TileEntityElectricBlock implements IPe return ChargeUtils.canBeOutputted(itemstack, false); } + private static final String[] methods = new String[] {"getStored", "canTeleport", "getMaxEnergy", "getEnergyNeeded", "teleport", "set"}; + @Override - @Method(modid = "ComputerCraft") - public String getType() + public String[] getMethods() { - return getInventoryName(); + return methods; } @Override - @Method(modid = "ComputerCraft") - public String[] getMethodNames() - { - return new String[] {"getStored", "canTeleport", "getMaxEnergy", "getEnergyNeeded", "teleport", "set"}; - } - - @Override - @Method(modid = "ComputerCraft") - public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws LuaException, InterruptedException + public Object[] invoke(int method, Object[] arguments) throws Exception { switch(method) { @@ -699,26 +681,10 @@ public class TileEntityTeleporter extends TileEntityElectricBlock implements IPe return new Object[] {"Frequency set."}; default: - Mekanism.logger.error("Attempted to call unknown method with computer ID " + computer.getID()); - return new Object[] {"Unknown command."}; + throw new NoSuchMethodException(); } } - @Override - @Method(modid = "ComputerCraft") - public boolean equals(IPeripheral other) - { - return this == other; - } - - @Override - @Method(modid = "ComputerCraft") - public void attach(IComputerAccess computer) {} - - @Override - @Method(modid = "ComputerCraft") - public void detach(IComputerAccess computer) {} - @Override @SideOnly(Side.CLIENT) public AxisAlignedBB getRenderBoundingBox() diff --git a/src/main/java/mekanism/generators/common/block/BlockGenerator.java b/src/main/java/mekanism/generators/common/block/BlockGenerator.java index 9d7c6f255..d0495c3ab 100644 --- a/src/main/java/mekanism/generators/common/block/BlockGenerator.java +++ b/src/main/java/mekanism/generators/common/block/BlockGenerator.java @@ -1,30 +1,26 @@ package mekanism.generators.common.block; -import java.util.List; -import java.util.Random; - +import buildcraft.api.tools.IToolWrench; +import cpw.mods.fml.common.Optional.Interface; +import cpw.mods.fml.common.Optional.Method; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import dan200.computercraft.api.peripheral.IPeripheral; +import dan200.computercraft.api.peripheral.IPeripheralProvider; import mekanism.api.MekanismConfig.general; import mekanism.api.energy.IEnergizedItem; import mekanism.common.ItemAttacher; import mekanism.common.Mekanism; -import mekanism.common.base.IActiveState; -import mekanism.common.base.IBoundingBlock; -import mekanism.common.base.ISpecialBounds; -import mekanism.common.base.ISustainedData; -import mekanism.common.base.ISustainedInventory; -import mekanism.common.base.ISustainedTank; +import mekanism.common.base.*; +import mekanism.common.integration.CCPeripheral; +import mekanism.common.integration.IComputerIntegration; import mekanism.common.tile.TileEntityBasicBlock; import mekanism.common.tile.TileEntityElectricBlock; import mekanism.common.util.LangUtils; import mekanism.common.util.MekanismUtils; import mekanism.generators.common.GeneratorsBlocks; import mekanism.generators.common.MekanismGenerators; -import mekanism.generators.common.tile.TileEntityAdvancedSolarGenerator; -import mekanism.generators.common.tile.TileEntityBioGenerator; -import mekanism.generators.common.tile.TileEntityGasGenerator; -import mekanism.generators.common.tile.TileEntityHeatGenerator; -import mekanism.generators.common.tile.TileEntitySolarGenerator; -import mekanism.generators.common.tile.TileEntityWindTurbine; +import mekanism.generators.common.tile.*; import net.minecraft.block.Block; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; @@ -41,14 +37,9 @@ import net.minecraft.util.MovingObjectPosition; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; -import buildcraft.api.tools.IToolWrench; -import cpw.mods.fml.common.ModAPIManager; -import cpw.mods.fml.common.Optional.Interface; -import cpw.mods.fml.common.Optional.Method; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import dan200.computercraft.api.peripheral.IPeripheral; -import dan200.computercraft.api.peripheral.IPeripheralProvider; + +import java.util.List; +import java.util.Random; /** @@ -654,9 +645,9 @@ public class BlockGenerator extends BlockContainer implements ISpecialBounds, IP { TileEntity te = world.getTileEntity(x, y, z); - if(te != null && te instanceof IPeripheral) + if(te != null && te instanceof IComputerIntegration) { - return (IPeripheral)te; + return new CCPeripheral((IComputerIntegration)te); } return null; diff --git a/src/main/java/mekanism/generators/common/tile/TileEntityGenerator.java b/src/main/java/mekanism/generators/common/tile/TileEntityGenerator.java index 232f56392..5b830fa8c 100644 --- a/src/main/java/mekanism/generators/common/tile/TileEntityGenerator.java +++ b/src/main/java/mekanism/generators/common/tile/TileEntityGenerator.java @@ -1,12 +1,7 @@ package mekanism.generators.common.tile; -import cpw.mods.fml.common.Optional.Method; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import dan200.computercraft.api.lua.ILuaContext; -import dan200.computercraft.api.lua.LuaException; -import dan200.computercraft.api.peripheral.IComputerAccess; -import dan200.computercraft.api.peripheral.IPeripheral; import io.netty.buffer.ByteBuf; import mekanism.api.Coord4D; import mekanism.api.MekanismConfig.general; @@ -139,48 +134,6 @@ public abstract class TileEntityGenerator extends TileEntityNoisyElectricBlock i } } - @Override - @Method(modid = "ComputerCraft") - public String getType() - { - return getInventoryName(); - } - - @Override - @Method(modid = "ComputerCraft") - public String[] getMethodNames() - { - return getMethods(); - } - - @Override - @Method(modid = "ComputerCraft") - public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws LuaException, InterruptedException - { - try { - return invoke(method, arguments); - } catch(NoSuchMethodException e) { - return new Object[] {"Unknown command."}; - } finally { - return new Object[] {"Error."}; - } - } - - @Override - @Method(modid = "ComputerCraft") - public void attach(IComputerAccess computer) {} - - @Override - @Method(modid = "ComputerCraft") - public void detach(IComputerAccess computer) {} - - @Override - @Method(modid = "ComputerCraft") - public boolean equals(IPeripheral other) - { - return this == other; - } - @Override public boolean canSetFacing(int side) {