Posted 12 November 2012 - 11:46 AM
Hello again,
Now that I've finally managed to get ComputerCraft running from Eclipse, I am looking to create a peripheral just to try things out. For some reason peripheral.isPresent(side) just returns nil. Could someone look over this code and tell me what I'm doing wrong? I'm sure it's something stupid but I can't seem to figure this out.
BlockPeripheralBlock.java
TileEntityPeripheral.java
Peripheral.java
Eclipse is not giving me any errors.
Note: This is not intended for release (obviously). It is merely a test of the CC api and creating peripherals.
Now that I've finally managed to get ComputerCraft running from Eclipse, I am looking to create a peripheral just to try things out. For some reason peripheral.isPresent(side) just returns nil. Could someone look over this code and tell me what I'm doing wrong? I'm sure it's something stupid but I can't seem to figure this out.
BlockPeripheralBlock.java
Spoiler
package peripheral.common;
import net.minecraft.src.Block;
import net.minecraft.src.CreativeTabs;
import net.minecraft.src.Material;
import net.minecraft.src.TileEntity;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
import dan200.computer.api.IComputerAccess;
import net.minecraft.src.World;
public class BlockPeripheralBlock extends Block
{
public BlockPeripheralBlock(int id, int texture)
{
super(id, texture, Material.cloth);
this.setCreativeTab(CreativeTabs.tabBlock);
}
}
TileEntityPeripheral.java
Spoiler
package peripheral.common;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.src.TileEntity;
import dan200.computer.api.IComputerAccess;
import dan200.computer.api.IPeripheral;
public class TileEntityPeripheral extends TileEntity implements IPeripheral
{
IComputerAccess computers = null;
public String getType()
{
return "Peripheral";
}
public String[] getMethodNames()
{
return new String[] { "getBlockId", "setBlockId" };
}
public Object[] callMethod(IComputerAccess computer, int method, Object[] arguments)
{
if (method == 0)
{
System.out.println("Called 1");
} else if (method == 1) {
System.out.println("Called 2");
}
return null;
}
public boolean canAttachToSide(int side)
{
return true;
}
public void attach(IComputerAccess computer, String computerSide)
{
}
public void detach(IComputerAccess computer)
{
}
}
Peripheral.java
Spoiler
package peripheral.common;
import net.minecraft.src.Block;
import net.minecraft.src.TileEntity;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;
@Mod(modid = "Peripheral", name = "Peripheral", version = "1.0")
@NetworkMod(clientSideRequired = true, serverSideRequired = false)
public class peripheral
{
public static Block peripheralBlock;
@Mod.Instance("Peripheral")
public static Object instance;
@Init
public void load(FMLInitializationEvent event)
{
GameRegistry.registerTileEntity(TileEntityPeripheral.class, "TileEntityPeripheral");
peripheralBlock = new BlockPeripheralBlock(250, 0).setBlockName("peripheralBlock");
GameRegistry.registerBlock(peripheralBlock);
LanguageRegistry.addName(peripheralBlock, "Peripheral Block");
}
}
Eclipse is not giving me any errors.
Note: This is not intended for release (obviously). It is merely a test of the CC api and creating peripherals.