I'm still learning and having difficulty understanding the client / server relationship. I don't expect someone to solve this problem for me but rather just point me in the right direction. My goal is to learn. Thank you for your patience and I apologize in advance for being long-winded and/or daft!
The basic concept of the mod I'm working on (To teach myself) is that the player can look at a list of all entity items in the game and mark any of them. When the player encounters that item on the ground, s/he will not pick it up if it is marked. I've got it working in single player, but when I go to test in in multiplayer, it isn't doing what I want. The player that started the server is the "master", so that all players in the game are prevented from picking up the blocks that the "master" player has marked.
The unwanted items are stored as an ArrayList of the type UniqueIdentifier. That ArrayList is just defined in my base mod class:
@Mod(modid = DoNotWant.MODID, version = DoNotWant.VERSION)
public class DoNotWant
{
public static final String MODID = "donotwant";
public static final String VERSION = "0.1";
public ArrayList unwanted;
...
In the client side preInit():
public void preInit() {
super.preInit();
DoNotWant.instance.unwanted = new ArrayList();
MinecraftForge.EVENT_BUS.register(new EntityItemPickup());
FMLCommonHandler.instance().bus().register(new KeyInputHandler());
KeyBindings.init();
}
I then have a GUI implemented from the base class thusly:
@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
if (ID == GuiBlockManager.GUI_ID) {
return new GuiBlockManager();
}
return null;
}
From that GUI, when the player clicks a button representing a particular block, I get the block's unique identifier and add it to the ArrayList:
DoNotWant.instance.unwanted.add(item.getUniqueIdentifier());
And finally I subscribe to the entityItemPickupEvent:
private UniqueIdentifier ident;
protected Minecraft mc = Minecraft.getMinecraft();
@SubscribeEvent
public void entityItemPickup(EntityItemPickupEvent event) {
ident = GameRegistry.findUniqueIdentifierFor(event.item.getEntityItem().getItem());
if (DoNotWant.instance.unwanted.indexOf(ident) != -1) {
event.setCanceled(true);
}
}
Is there another place I can define the ArrayList so that each client has a unique instance of it? I have a feeling it isn't that simple. I considered keeping track of the unwanted items in an ArrayList where each player was a key, and the value was a list of UniqueIdentifiers for that player, but I'm not sure if that is the way I should do it.
When I call mc.thePlayer.getUniqueID() within the entityItemPickup event handler, I always get the UUID of the "master" player, even when the event is triggered from the guest player's client. What's up with that?