Jump to content

getOriginal [1.10.2]


Terrails

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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.