Posted 15 March 2012 - 09:18 AM
I'm just trying to test the peripheral api,
But with my current code the block isn't recognized as a peripheral.
mod_ :
Block :
TileEntity :
But with my current code the block isn't recognized as a peripheral.
mod_ :
Spoiler
package net.minecraft.src;
import java.io.File;
import net.minecraft.client.Minecraft;
import net.minecraft.src.forge.Configuration;
import net.minecraft.src.forge.MinecraftForgeClient;
import dan200.computer.api.IComputerAccess;
import dan200.computer.api.IPeripheral;
public class mod_CCPeriph_Test extends BaseModMp
{
private static Configuration config = new Configuration(new File(Minecraft.getMinecraftDir(), "config/mod_TestPeriph.cfg"));
public static String texture = "tomass1996/blocks.png";
public static int periphID = loadConfig();
public static final Block periph = new CCPeriph_BlockTest(periphID, 0).setBlockName("testPeriph").setHardness(3F).setResistance(4F).setLightValue(1F);
public void load(){
ModLoader.registerBlock(periph);
ModLoader.addName(periph, "Test Periph");
ModLoader.addShapelessRecipe(new ItemStack(periph, 1), new Object [] {Block.dirt});
ModLoader.registerTileEntity(CCPeriph_TileEntityTest.class, "testPeriphTE");
MinecraftForgeClient.preloadTexture(texture);
}
public String getVersion(){
return "1.0.0";
}
private static int loadConfig(){
config.load();
periphID = Integer.parseInt(config.getOrCreateBlockIdProperty("TestPeriph", 160).value);
config.save();
return periphID;
}
}
Block :
Spoiler
package net.minecraft.src;
import dan200.computer.api.IComputerAccess;
import dan200.computer.api.IPeripheral;
import java.util.Random;
import net.minecraft.src.forge.ITextureProvider;
public class CCPeriph_BlockTest extends Block
implements ITextureProvider{
public CCPeriph_BlockTest(int id, int texInd) {
super(id, texInd, Material.ground);
}
@Override
public TileEntity getTileEntity(int md) {
return new CCPeriph_TileEntityTest();
}
@Override
public int idDropped(int i, Random random, int j){
return mod_CCPeriph_Test.periph.blockID;
}
@Override
public int quantityDropped(Random random){
return 1;
}
@Override
public String getTextureFile() {
return mod_CCPeriph_Test.texture;
}
}
TileEntity :
Spoiler
package net.minecraft.src;
import dan200.computer.api.IComputerAccess;
import dan200.computer.api.IPeripheral;
public class CCPeriph_TileEntityTest extends TileEntity
implements IPeripheral{
@Override
public String getType() {
return "TestPeriph";
}
@Override
public String[] getMethodNames() {
return new String[] {"testChat"};
}
@Override
public Object[] callMethod(IComputerAccess computer, int method,Object[] arguments) throws Exception {
if (method == 0){
ModLoader.getMinecraftInstance().thePlayer.addChatMessage((String)arguments[0]);
return new Object[] {true, "testChat"};
}else{
return new Object[] {false, "No Such Method"};
}
}
@Override
public boolean canAttachToSide(int side) {
return true;
}
@Override
public void attach(IComputerAccess computer, String computerSide) {
computer.queueEvent("testPeriph_Attach");
}
@Override
public synchronized void detach(IComputerAccess computer) {
computer.queueEvent("testPeriph_Detach");
}
}