Jump to content

Problem with minecraft.thePlayer


faraddox

Recommended Posts

GuiScreen:

[spoiler=NESGuiScreen]

public class NESGui extends GuiScreen {
....
public NESGui (EntityPlayer _player) {
        player = _player;
        LOG("Drawing gui for " + player.getName());
    }
....
}

 

 

GuiHandler:

[spoiler=NESGuiHandler]

package com.faraddox.nes.gui;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.network.IGuiHandler;

/**
* Created by faraddox on 27.10.2016.
*/
public class NESGuiHandler implements IGuiHandler {

    public static final int NESGUI_ID = 0;

    @Override
    public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
        return null;
    }

    @Override
    public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
        switch (ID) {
            case NESGUI_ID:
                return new NESGui(player);
        }
        return null;
    }
}

 

 

and key handler (client side of course)

[spoiler=NESKeyHandler]

package com.faraddox.nes.event;

import com.faraddox.nes.NES;
import com.faraddox.nes.gui.NESGui;
import com.faraddox.nes.gui.NESGuiHandler;
import com.faraddox.nes.proxy.ClientProxy;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.settings.KeyBinding;
import net.minecraftforge.client.event.MouseEvent;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.InputEvent;
import org.lwjgl.input.Keyboard;

/**
* Created by faraddox on 27.10.2016.
*/
public class NESKeyEventHandler {

    public static KeyBinding openGuiKey = new KeyBinding("nes.openGuiKey", Keyboard.KEY_K, "nes.gui");

    @SubscribeEvent(priority = EventPriority.NORMAL, receiveCanceled = true)
    public void onEvent(InputEvent event) {
        if (openGuiKey.isPressed()) {
            Minecraft.getMinecraft().thePlayer.openGui(
                    NES.instance,
                    NESGuiHandler.NESGUI_ID,
                    Minecraft.getMinecraft().theWorld,
                    0, 0, 0
            );
        }

    }

    @SubscribeEvent
    public void onWheelRotated(MouseEvent event) {
        GuiScreen gui = Minecraft.getMinecraft().currentScreen;
        if (gui instanceof NESGui && event.getDwheel() != 0)
            ((NESGui)gui).scroll(event);
    }
}

 

 

For some reason my player data on Minecraft.getMinecraft().thePlayer is all defined as 0 (default). Doesn't matter, if i use constructor to link player or just use mc.thePlayer in GuiScreen.

I have my own command to show data in chat. If i use it, all data is shown and all OK, it's not only zeros.

Mod,  that adds skill system (WIP, 1.10.2)

https://github.com/faraddox/NotEnoughSkills

Link to comment
Share on other sites

You haven't really shown how you're storing or retrieving your data, but it sounds like you're not syncing it to the client. Commands are run on the server side (unless you register them with

ClientCommandHandler

), so a command would show the server's copy of the data rather than the client's.

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

You haven't really shown how you're storing or retrieving your data, but it sounds like you're not syncing it to the client. Commands are run on the server side (unless you register them with

ClientCommandHandler

), so a command would show the server's copy of the data rather than the client's.

Is syncing important if i test it just in singleplayer?

Mod,  that adds skill system (WIP, 1.10.2)

https://github.com/faraddox/NotEnoughSkills

Link to comment
Share on other sites

Yes, even in singleplayer there's a client and a server involved.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

Take a look at http://mcforge.readthedocs.io/, it is the documentation of Forge, including networking.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

But it is strange.. If every event is handling on both side, i must have same player on client side..

I have my own capability on player. Will it be different on client side and server side in singleplayer? In core of capabilities are NBT tags, as i understand. Does they sync or not? And if events handling on both side, as i say before, these tags in my capability must be same on bother side without syncing, i think.

Mod,  that adds skill system (WIP, 1.10.2)

https://github.com/faraddox/NotEnoughSkills

Link to comment
Share on other sites

But it is strange.. If every event is handling on both side, i must have same player on client side..

I have my own capability on player. Will it be different on client side and server side in singleplayer? In core of capabilities are NBT tags, as i understand. Does they sync or not? And if events handling on both side, as i say before, these tags in my capability must be same on bother side without syncing, i think.

 

Single player is just a server with one player online.

 

The client and server will each have their own

EntityPlayer

instance, each of which will have its own instance of your capability.

 

Capabilities are only written to NBT when they're being saved to the disk. They're not automatically synced, you need to sync them yourself.

 

Only the server will save and load capability data from the disk, the client will always have the default data for your capability unless it's synced from the server.

 

If an event is fired on both sides (not all events are) you should be able to make changes to the capability data on both sides; but this won't be reliable if the client never had the correct data in the first place. As an example, let's say that your capability stores a single number and a player has the number 2 stored. When an event is fired that adds 5 to this number, the server's new value will be 7 (2 + 5) but the client's new value will be 5 (0 + 5).

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

But it is strange.. If every event is handling on both side, i must have same player on client side..

I have my own capability on player. Will it be different on client side and server side in singleplayer? In core of capabilities are NBT tags, as i understand. Does they sync or not? And if events handling on both side, as i say before, these tags in my capability must be same on bother side without syncing, i think.

 

Single player is just a server with one player online.

 

The client and server will each have their own

EntityPlayer

instance, each of which will have its own instance of your capability.

 

Capabilities are only written to NBT when they're being saved to the disk. They're not automatically synced, you need to sync them yourself.

 

Only the server will save and load capability data from the disk, the client will always have the default data for your capability unless it's synced from the server.

 

If an event is fired on both sides (not all events are) you should be able to make changes to the capability data on both sides; but this won't be reliable if the client never had the correct data in the first place. As an example, let's say that your capability stores a single number and a player has the number 2 stored. When an event is fired that adds 5 to this number, the server's new value will be 7 (2 + 5) but the client's new value will be 5 (0 + 5).

Understood. And then, when i should sync data? On player joining and handling each event that changes this data?

Mod,  that adds skill system (WIP, 1.10.2)

https://github.com/faraddox/NotEnoughSkills

Link to comment
Share on other sites

Understood. And then, when i should sync data? On player joining and handling each event that changes this data?

 

The capability itself should sync its data whenever it changes, including when it's loaded from NBT.

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

Understood. And then, when i should sync data? On player joining and handling each event that changes this data?

 

The capability itself should sync its data whenever it changes, including when it's loaded from NBT.

Thank you again) I wrote data sync, and after some tests, crashes (cause i used setInt(index, value) instead of writeInt(value)) it's working:

[spoiler=Screenshot of gui with data, i got from server]

39d59e6403.ndefined

 

 

Mod,  that adds skill system (WIP, 1.10.2)

https://github.com/faraddox/NotEnoughSkills

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.