This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Xtansia's profile picture

Peripheral not recognized as present

Started by Xtansia, 15 March 2012 - 08:18 AM
Xtansia #1
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_ :
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");
}

}
Espen #2
Posted 15 March 2012 - 12:16 PM
I'm not using forge in my current workspace, so I don't know if that's why you use getTileEntity, but try to replace getTileEntity(int md) with getBlockEntity() in your Block file.

Edit: Oops, sorry forgot something. If you use getBlockEntity, then you have to extend BlockContainer instead of Block. :D/>/>
Edited on 15 March 2012 - 11:28 AM
Xfel #3
Posted 15 March 2012 - 03:46 PM
You can't add tile entities for blocks which don't extend BlockContainer. So you need to subclass BlockContainer instead of Block.
rockymc #4
Posted 15 March 2012 - 04:57 PM
Note #1: Doesn't use Forge Sprites/Textures
Xtansia #5
Posted 16 March 2012 - 02:43 AM
Herp A Derp,
I knew it would be something simple like that,
Thanks Espen & Xfel

@rockymc
I have Forge Texture support in this,
I know how to use forge.
Casper7526 #6
Posted 16 March 2012 - 02:58 AM
Yep just change to extends BlockContainer and you should be fine.

BTW, if Anyone would like to make a VERY basic framework that uses forge sprite/textures feel free.