Posted 19 January 2014 - 01:18 PM
Hi,
I was coding today for a little tiny mod to experiment for a bit. But there was one thing that I noticed. But first, the code:
As you can see I have put up some test prints here and there. But the main problem is, I never see 'READING' or 'WRITING' getting called, so I cannot save my first method's string.
How to reproduce you ask?
Well, here are some steps:
Thanks for reading!
I was coding today for a little tiny mod to experiment for a bit. But there was one thing that I noticed. But first, the code:
CODE
calling the register method
@Mod(modid = ModInfo.ID, name = ModInfo.NAME, version = ModInfo.VERSION, dependencies=ModInfo.DEPENDENCIES)
@NetworkMod(clientSideRequired = ModInfo.clientReq, serverSideRequired = ModInfo.serverReq)
public class test
{
// Got more code here, but it is a direct call to CC
@Mod.EventHandler
public void load(FMLInitializationEvent event)
{
ComputerCraftAPI.registerExternalPeripheral(TileEntityDispenser.class, new PeripheralHandler());
}
}
peripheral handler
public class PeripheralHandler implements IPeripheralHandler
{
@Override
public IHostedPeripheral getPeripheral(TileEntity tile)
{
return new PeripheralDispenser();
}
}
PeripheralDispenser
public class PeripheralDispenser implements IHostedPeripheral
{
private String storage = "";
@Override
public String getType() {
return "dispenser";
}
@Override
public String[] getMethodNames() {
return new String[] { "t", "e" };
}
@Override
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception
{
// Should do error checking, but Im testing
if(method == 0 )
{
this.storage = (String) arguments[0];
return new Object[] { arguments[0] };
}
if( method == 1 )
{
return new Object[] { this.storage };
}
return null;
}
@Override
public boolean canAttachToSide(int side)
{
return true;
}
@Override
public void attach(IComputerAccess computer)
{
}
@Override
public void detach(IComputerAccess computer)
{
}
@Override
public void update()
{
}
@Override
public void readFromNBT(NBTTagCompound nbt)
{
System.out.println("READING");
this.storage = nbt.getString("DATA");
}
@Override
public void writeToNBT(NBTTagCompound nbt)
{
System.out.println("WRITING");
nbt.setString("DATA", this.storage);
}
}
As you can see I have put up some test prints here and there. But the main problem is, I never see 'READING' or 'WRITING' getting called, so I cannot save my first method's string.
How to reproduce you ask?
Well, here are some steps:
- Take this code and run minecraft with it
- Place a computer next to a dispenser
- wrap to the dispenser and call the method: wrap.t("Some random string")
- call the following method: wrap.e() -> you should see 'Some random string' (this part works)
- Place another dispenser next to the computer (You dont have to wrap to it)
- call again the method: wrap.e() -> you should see 'Some random string', but it shows an empty string instead.
Thanks for reading!