Hi everybody!
I started modding the other day and made some good progress but now I've hit a wall.
My idea is this: I have a semi-expensive to craft block a player can right click. The block (a TileEntity obviously) stores the player's name.
I then listen to the LivingDeathEvent event. If a player dies I cancel the event, set his health to half a heart and teleport him on top of the block he was "bound" to.
Now...I've managed the right-clicking, the event handling and the teleporting but it all works a bit wonky probably due to massive syncing issues I'm currently not able to comprehend.
Currently I'm doing something like this: a player clicks the block -> the TileEntity registers at a central class which holds a static collection of all active resurrection blocks (i.e. TileEntities). If the LivingDeathEvent occurs it checks if it was a player and then iterates over all elements (TileEntities) in the collection to check if the player was "bound" to one of them. Which one of these things do I need to handle on which side (client/server)? Do I need packages or am I overlooking something obvious?
Here's some random code:
click on the block
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9) {
TileEntityResurrectionBlock base = (TileEntityResurrectionBlock)world.getBlockTileEntity(x, y, z);
if (base != null) {
if (player.isSneaking()) {
if (base.isBound()) {
if(!world.isRemote) player.addChatMessage(MessagesEn.SOMEONE_ELSE_BOUND);
} else {
base.setBinding(player.getEntityName());
if(!world.isRemote) player.addChatMessage(MessagesEn.NOW_BOUND);
}
} else {
if (base.isBound()) {
if(!world.isRemote) player.addChatMessage(MessagesEn.PLAYER_BOUND + base.getBoundPlayer());
} else {
if(!world.isRemote) player.addChatMessage(MessagesEn.NOT_BOUND);
}
}
}
return false;
}
setBinding in TileEntityResurrectionBlock
public void setBinding(String playerName) {
boundPlayer = playerName;
BlockManager.addBlock(this);
}
BlockManager
public class BlockManager {
private static List blocks = new ArrayList();
public static void addBlock(TileEntityResurrectionBlock base) {
//if(!Minecraft.getMinecraft().theWorld.isRemote) return;
Iterator it = blocks.iterator();
// check if this player already has a bound vita-chamber anywhere
// and remove that one
while (it.hasNext()) {
TileEntityResurrectionBlock b = (TileEntityResurrectionBlock)it.next();
if (b.getBoundPlayer().equals(base.getBoundPlayer())) {
b.setBoundPlayer("");
it.remove();
}
}
blocks.add(base);
}
public static void removeBlock(TileEntityResurrectionBlock base) {
//if(Minecraft.getMinecraft().theWorld.isRemote) return;
blocks.remove(base);
}
public static TileEntityResurrectionBlock isPlayerBoundAnywhere(String playerName) {
Iterator it = blocks.iterator();
boolean isBound = false;
while (it.hasNext()) {
TileEntityResurrectionBlock base = (TileEntityResurrectionBlock)it.next();
if (base.getBoundPlayer().equals(playerName)) {
return base;
}
}
return null;
}
}
Cheers
- Chris