Posted 27 April 2014 - 02:34 AM
So here is my problem,
I am trying to make a custom peripheral for CC 1.63 but the computers wont
recognize my peripheral. When I try to wrap it and get its type with type() it returns nil.
Please help :3
Here is my code:
import java.awt.image.TileObserver;
import java.util.HashMap;
import java.util.Iterator;
import dan200.computercraft.api.lua.ILuaContext;
import dan200.computercraft.api.peripheral.IComputerAccess;
import dan200.computercraft.api.peripheral.IPeripheral;
import appeng.api.IAEItemStack;
import appeng.api.IItemList;
import appeng.api.Util;
import appeng.api.WorldCoord;
import appeng.api.me.tiles.IGridMachine;
import appeng.api.me.util.IGridInterface;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
public class TileEntityCCMEInterface extends TileEntity implements IPeripheral, IGridMachine {
public static final String PERIPHERAL_TYPE = "ccmeinterface";
public static final String[] PERIPHERAL_METHODS = new String[]{"receiveItem", "listItems", "hasItem"};
public IGridInterface gridInterface;
public boolean powered;
@Override
public String getType() {
return PERIPHERAL_TYPE;
}
@Override
public String[] getMethodNames() {
return PERIPHERAL_METHODS;
}
@Override
public Object[] callMethod(IComputerAccess parComputer, ILuaContext parLuaContext, int parMethod, Object[] parArguments) throws Exception {
String methodName = PERIPHERAL_METHODS[parMethod];
if(methodName == "receiveItem") {
if(parArguments.length != 3) throw new Exception("Correct use: receiveItem <number:id> <number:meta> <number:amount> <string:side>");
int argID;
int argMeta;
int argAmount;
String argSide;
try {
argID = ((Double)parArguments[0]).intValue();
argMeta = ((Double)parArguments[1]).intValue();
argAmount = ((Double)parArguments[2]).intValue();
argSide = (String)parArguments[3];
}
catch(Exception e) {
throw new Exception("Correct use: receiveItem <number:id> <number:meta> <number:amount> <string:side>");
}
if(!(argSide == "top" || argSide == "bottom" || argSide == "north" || argSide == "east" || argSide == "south" || argSide == "west")) {
throw new Exception("Side has to be: top, bottom, north, east, south, west!");
}
IAEItemStack itemsReturned = gridInterface.getCellArray().extractItems(Util.createItemStack(new ItemStack(argID, argAmount, argMeta)));
return new Object[]{itemsReturned.getStackSize()};
}
else if(methodName == "listItems") {
if(parArguments.length != 0) throw new Exception("Correct use: listItems");
IItemList items = gridInterface.getCellArray().getAvailableItems();
HashMap<String, Object>[] allItems = new HashMap[items.size()];
Iterator<IAEItemStack> iterator = items.iterator();
for(int i = 0; iterator.hasNext(); i++) {
IAEItemStack itemStack = iterator.next();
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("id", itemStack.getItemID());
map.put("meta", itemStack.getItemDamage());
map.put("amount", itemStack.getStackSize());
allItems = map;
}
return new Object[]{allItems};
}
else if(methodName == "hasItem") {
if(parArguments.length != 3) throw new Exception("Correct use: hasItem <number:id> <number:meta> <number:amount>");
int argID;
int argMeta;
int argAmount;
try {
argID = ((Double)parArguments[0]).intValue();
argMeta = ((Double)parArguments[1]).intValue();
argAmount = ((Double)parArguments[2]).intValue();
}
catch(Exception e) {
throw new Exception("Correct use: hasItem <number:id> <number:meta> <number:amount>");
}
IAEItemStack itemsReturned = gridInterface.getCellArray().extractItems(Util.createItemStack(new ItemStack(argID, argAmount, argMeta)));
return new Object[]{itemsReturned.getStackSize()};
}
return null;
}
@Override
public void attach(IComputerAccess parComputer) {
}
@Override
public void detach(IComputerAccess parComputer) {
}
@Override
public boolean equals(IPeripheral parOther) {
return parOther.getClass().equals(this.getClass());
}
@Override
public WorldCoord getLocation() {
return new WorldCoord(xCoord, yCoord, zCoord);
}
@Override
public boolean isValid() {
return true;
}
@Override
public void setPowerStatus(boolean parHasPower) {
powered = parHasPower;
}
@Override
public boolean isPowered() {
return powered;
}
@Override
public IGridInterface getGrid() {
return gridInterface;
}
@Override
public void setGrid(IGridInterface parGridInterface) {
gridInterface = parGridInterface;
}
@Override
public World getWorld() {
return worldObj;
}
@Override
public float getPowerDrainPerTick() {
return 1f;
}
}
I am trying to make a custom peripheral for CC 1.63 but the computers wont
recognize my peripheral. When I try to wrap it and get its type with type() it returns nil.
Please help :3
Here is my code:
package de.mrpixelp.itempedia.tileentity;
import java.awt.image.TileObserver;
import java.util.HashMap;
import java.util.Iterator;
import dan200.computercraft.api.lua.ILuaContext;
import dan200.computercraft.api.peripheral.IComputerAccess;
import dan200.computercraft.api.peripheral.IPeripheral;
import appeng.api.IAEItemStack;
import appeng.api.IItemList;
import appeng.api.Util;
import appeng.api.WorldCoord;
import appeng.api.me.tiles.IGridMachine;
import appeng.api.me.util.IGridInterface;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
public class TileEntityCCMEInterface extends TileEntity implements IPeripheral, IGridMachine {
public static final String PERIPHERAL_TYPE = "ccmeinterface";
public static final String[] PERIPHERAL_METHODS = new String[]{"receiveItem", "listItems", "hasItem"};
public IGridInterface gridInterface;
public boolean powered;
@Override
public String getType() {
return PERIPHERAL_TYPE;
}
@Override
public String[] getMethodNames() {
return PERIPHERAL_METHODS;
}
@Override
public Object[] callMethod(IComputerAccess parComputer, ILuaContext parLuaContext, int parMethod, Object[] parArguments) throws Exception {
String methodName = PERIPHERAL_METHODS[parMethod];
if(methodName == "receiveItem") {
if(parArguments.length != 3) throw new Exception("Correct use: receiveItem <number:id> <number:meta> <number:amount> <string:side>");
int argID;
int argMeta;
int argAmount;
String argSide;
try {
argID = ((Double)parArguments[0]).intValue();
argMeta = ((Double)parArguments[1]).intValue();
argAmount = ((Double)parArguments[2]).intValue();
argSide = (String)parArguments[3];
}
catch(Exception e) {
throw new Exception("Correct use: receiveItem <number:id> <number:meta> <number:amount> <string:side>");
}
if(!(argSide == "top" || argSide == "bottom" || argSide == "north" || argSide == "east" || argSide == "south" || argSide == "west")) {
throw new Exception("Side has to be: top, bottom, north, east, south, west!");
}
IAEItemStack itemsReturned = gridInterface.getCellArray().extractItems(Util.createItemStack(new ItemStack(argID, argAmount, argMeta)));
return new Object[]{itemsReturned.getStackSize()};
}
else if(methodName == "listItems") {
if(parArguments.length != 0) throw new Exception("Correct use: listItems");
IItemList items = gridInterface.getCellArray().getAvailableItems();
HashMap<String, Object>[] allItems = new HashMap[items.size()];
Iterator<IAEItemStack> iterator = items.iterator();
for(int i = 0; iterator.hasNext(); i++) {
IAEItemStack itemStack = iterator.next();
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("id", itemStack.getItemID());
map.put("meta", itemStack.getItemDamage());
map.put("amount", itemStack.getStackSize());
allItems = map;
}
return new Object[]{allItems};
}
else if(methodName == "hasItem") {
if(parArguments.length != 3) throw new Exception("Correct use: hasItem <number:id> <number:meta> <number:amount>");
int argID;
int argMeta;
int argAmount;
try {
argID = ((Double)parArguments[0]).intValue();
argMeta = ((Double)parArguments[1]).intValue();
argAmount = ((Double)parArguments[2]).intValue();
}
catch(Exception e) {
throw new Exception("Correct use: hasItem <number:id> <number:meta> <number:amount>");
}
IAEItemStack itemsReturned = gridInterface.getCellArray().extractItems(Util.createItemStack(new ItemStack(argID, argAmount, argMeta)));
return new Object[]{itemsReturned.getStackSize()};
}
return null;
}
@Override
public void attach(IComputerAccess parComputer) {
}
@Override
public void detach(IComputerAccess parComputer) {
}
@Override
public boolean equals(IPeripheral parOther) {
return parOther.getClass().equals(this.getClass());
}
@Override
public WorldCoord getLocation() {
return new WorldCoord(xCoord, yCoord, zCoord);
}
@Override
public boolean isValid() {
return true;
}
@Override
public void setPowerStatus(boolean parHasPower) {
powered = parHasPower;
}
@Override
public boolean isPowered() {
return powered;
}
@Override
public IGridInterface getGrid() {
return gridInterface;
}
@Override
public void setGrid(IGridInterface parGridInterface) {
gridInterface = parGridInterface;
}
@Override
public World getWorld() {
return worldObj;
}
@Override
public float getPowerDrainPerTick() {
return 1f;
}
}