Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

  • 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 by Terrails

  • Author

What exactly do you mean by copy it over, so I use the IThirst instance and need to copy it over but how?

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

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

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

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

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.

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

  • 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)

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

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.