Jump to content

Recommended Posts

Posted

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...

Posted

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.

Posted

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.

Posted

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.

Posted

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.

Posted

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.

Posted

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)

Posted

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.