February 24, 20178 yr Author Do you mean something like this? I make an integer, assign it in my Clone event an use it in Respawn event. It doesn't even work like that. Edited February 24, 20178 yr by Terrails
February 24, 20178 yr Author What exactly do you mean by copy it over, so I use the IThirst instance and need to copy it over but how?
February 24, 20178 yr Author I don't know what's wrong but I'm having problems, how am I supposed to get instance? Do I set IThirst like this: @SubscribeEvent public void onClonePlayer(PlayerEvent.Clone player) { final IThirst originalPlayer = player.getOriginal().getCapability(TANCapabilities.THIRST, null); final IThirst entityPlayer = player.getEntityPlayer().getCapability(TANCapabilities.THIRST, null); this.oldPlayer = originalPlayer; this.newPlayer = entityPlayer; } and I have IThirst variables and in RespawnEvent I use it like this... @SubscribeEvent public void playerRespawn(net.minecraftforge.fml.common.gameevent.PlayerEvent.PlayerRespawnEvent event){ newPlayer.setThirst(oldPlayer.getThirst()); } I'm really not sure what to do anymore...
February 24, 20178 yr Author So something like this which I already had before: @SubscribeEvent public void onClonePlayer(PlayerEvent.Clone player) { final IThirst originalPlayer = player.getOriginal().getCapability(TANCapabilities.THIRST, null); final IThirst entityPlayer = player.getEntityPlayer().getCapability(TANCapabilities.THIRST, null); entityPlayer.setThirst(originalPlayer.getThirst()); } and this is in respawnEvent... @SubscribeEvent public void playerRespawn(net.minecraftforge.fml.common.gameevent.PlayerEvent.PlayerRespawnEvent event){ // final IThirst entityPlayer = event.player.getCapability(TANCapabilities.THIRST, null); IThirst thirstData = ThirstHelper.getThirstData(event.player); thirstData.setThirst(thirstData.getThirst()); } and it still doesn't work. I tried to get the thirst with the entityPlayer that is in comment here.
February 24, 20178 yr Author Adubbz told me to use this to send the packet to client IThirst thirstData = ThirstHelper.getThirstData(player); thirstData.setThirst(whatever); I used packet's before but it still wasn't working, this at least works if I for example put 5 in setThirst.
February 24, 20178 yr Author This is my packet: public class ThirstMessage implements IMessage { int thirst; public ThirstMessage() { } public ThirstMessage(int thirst) { this.thirst = thirst; } @Override public void fromBytes(ByteBuf buf) { thirst = buf.readInt(); } @Override public void toBytes(ByteBuf buf) { buf.writeInt(thirst); } public static class MessageHandler implements IMessageHandler<ThirstMessage, IMessage> { @Override public IMessage onMessage(ThirstMessage message, MessageContext ctx) { IThreadListener mainThread = Minecraft.getMinecraft(); EntityPlayer player = Minecraft.getMinecraft().player; mainThread.addScheduledTask(new Runnable() { @Override public void run() { final IThirst entityPlayer = player.getCapability(TANCapabilities.THIRST, null); entityPlayer.setThirst(message.thirst); } }); return null; } } } I registered it in my MainClass and the event: @SubscribeEvent public void playerRespawn(net.minecraftforge.fml.common.gameevent.PlayerEvent.PlayerRespawnEvent event){ // final IThirst entityPlayer = event.player.getCapability(TANCapabilities.THIRST, null); EntityPlayerMP player = (EntityPlayerMP) event.player; IThirst thirstData = ThirstHelper.getThirstData(event.player); MainClass.instance.sendTo(new ThirstMessage(thirstData.getThirst()), player); } The problem is to how should I get original players thirst level to set it in my packet without using fields, even if I put a number instead of thirstData.getThirst() I would still sometimes get full thirst.
February 24, 20178 yr You don't need the old player's thirst data after you've copied it to the new player in PlayeEvent.Clone, just use the new player's thirst data when sending the packet. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
February 24, 20178 yr Author yep that doesn't work... here is the repo ThirstMessage TANEvent RegisterMessage
February 24, 20178 yr Author Hmm... weird did you try killing yourself with less than max thirst couple of times? It doesn't happen every time, there is a chance to it works and to it doesn't. I removed FMLCommonHandler and fixed variable names instead of entityPlayer to clonedPlayer.
February 24, 20178 yr Author Looks like it was that, I killed myself around 15 times and it didn't happen. I noticed to the there is a chance when you join your world to the same thing happens so I just copied everything from PlayerRespawnEvent and put it in PlayerLoggedInEvent. Thanks for all the help! (I'm sorry if I didn't understand some stuff before)
February 24, 20178 yr Author Well good to I checked going through portals because the same thing is happening... I used EntityWorldJoinEvent... I really don't get it why ToughAsNails didn't handle all of this.
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.