Jump to content

Reading string from PlayerInformation (extends IExtendedEntityProperties)


Mew

Recommended Posts

When I read the string via my connection handler class inside the playerLoggedIn() method (connection handler class extends IConnectionHandler), it reads the string as it should be. But when I try to read the string from any of my items, addInformation() methods, the string returns as either null, or "".

 

So either A) how do I fix this, or, B) what am I doing wrong?

 

Code for PlayerInformation:

package rpg.playerinfo;

import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.world.World;
import net.minecraftforge.common.IExtendedEntityProperties;

public final class PlayerInformation implements IExtendedEntityProperties {

    public static enum CountableKarmaEvent {
        PIGMEN_ATTACK(1), CREATE_SNOWGOLEM(2), CREATE_IRONGOLEM(3);

        private final int maxCount;

        private CountableKarmaEvent(int maxCount) {
            this.maxCount = maxCount;
        }

        public int getMaxCount() {
            return maxCount;
        }
    }

    public static final String IDENTIFIER = "minepg_playerinfo";

    public static final int MAX_KARMA_VALUE = 99999999;

    public static PlayerInformation forPlayer(Entity player) {
        return (PlayerInformation) player.getExtendedProperties(IDENTIFIER);
    }

    // called by the ASM hook in EntityPlayer.clonePlayer
    public static void handlePlayerClone(EntityPlayer source,
            EntityPlayer target) {
        target.registerExtendedProperties(IDENTIFIER,
                source.getExtendedProperties(IDENTIFIER));
    }

    public boolean dirty = true;
    private float karma = 0;
    public byte[] eventAmounts = new byte[PlayerInformation.CountableKarmaEvent
            .values().length];
    private String playersClass;
    private int danris = 0;

    private final EntityPlayer player;

    public PlayerInformation(EntityPlayer player) {
        this.player = player;
    }

    public int getCurrency() {
        return danris;
    }

    public byte getEventAmount(CountableKarmaEvent event) {
        return eventAmounts[event.ordinal()];
    }

    public float getKarma() {
        return karma;
    }

    public String getPlayersClass() {
        return playersClass;
    }

    public boolean increaseEventAmount(
            PlayerInformation.CountableKarmaEvent event) {
        return setEventAmount(event, eventAmounts[event.ordinal()] + 1);
    }

    @Override
    public void init(Entity entity, World world) {

    }

    @Override
    public void loadNBTData(NBTTagCompound playerNbt) {
        NBTTagCompound nbt = playerNbt.getCompoundTag(IDENTIFIER);

        playersClass = nbt.getString("playersClass");

        System.out
                .println("Debug message. If this has been printed to the console then NBTData has been read.");
        danris = nbt.getInteger("danris");
        karma = nbt.getFloat("karma");

        NBTTagList eventList = nbt.getTagList("events");
        for (int i = 0; i < eventList.tagCount(); i++) {
            NBTTagCompound evtInfo = (NBTTagCompound) eventList.tagAt(i);
            byte eventId = evtInfo.getByte("id");
            if (eventId >= 0 && eventId < eventAmounts.length) {
                eventAmounts[eventId] = evtInfo.getByte("value");
            }
        }
    }

    public float modifyKarma(float modifier) {
        player.worldObj.playSoundAtEntity(player, "minepg.karma"
                + (modifier < 0 ? "down" : "up"), 1, 1);

        return setKarma(karma + modifier);
    }

    public float modifyKarmaWithMax(float modifier, float max) {
        if (karma < max) {
            modifyKarma(modifier);
        }

        return karma;
    }

    public float modifyKarmaWithMin(float modifier, float min) {
        if (karma > min) {
            modifyKarma(modifier);
        }

        return karma;
    }

    @Override
    public void saveNBTData(NBTTagCompound compound) {
        NBTTagCompound nbt = new NBTTagCompound();

        nbt.setString("playersClass", playersClass);
        nbt.setInteger("danris", danris);
        nbt.setFloat("karma", karma);

        NBTTagList eventList = new NBTTagList();
        for (int i = 0; i < eventAmounts.length; i++) {
            NBTTagCompound evtInfo = new NBTTagCompound();
            evtInfo.setByte("id", (byte) i);
            evtInfo.setByte("value", eventAmounts[i]);
            eventList.appendTag(evtInfo);
        }
        nbt.setTag("events", eventList);

        compound.setCompoundTag(IDENTIFIER, nbt);
    }

    public int setCurrency(int danris) {
        if (this.danris != danris) {
            this.danris = danris;
            setDirty();
        }
        if (this.danris > 999999) {
            this.danris = 999999;
            setDirty();
        }
        return this.danris;
    }

    /**
     * marks that this needs to be resend to the client
     */
    public void setDirty() {
        dirty = true;
    }

    public boolean setEventAmount(CountableKarmaEvent event, int amount) {
        if (amount < event.getMaxCount()
                && eventAmounts[event.ordinal()] != amount) {
            eventAmounts[event.ordinal()] = (byte) amount;
            setDirty();
            return true;
        } else
            return false;
    }

    public float setKarma(float karma) {
        if (this.karma != karma) {
            this.karma = karma;
            if (this.karma > MAX_KARMA_VALUE) {
                this.karma = MAX_KARMA_VALUE;
            }
            if (this.karma < -MAX_KARMA_VALUE) {
                this.karma = -MAX_KARMA_VALUE;
            }
            setDirty();
        }

        return this.karma;
    }

    public String setPlayersClass(String playersClass) {
        if (this.playersClass != playersClass) {
            this.playersClass = playersClass;
            setDirty();
        }

        return this.playersClass;
    }
}

 

Code for ConnectionHandler:

package rpg.comm;

import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.network.INetworkManager;
import net.minecraft.network.NetLoginHandler;
import net.minecraft.network.packet.NetHandler;
import net.minecraft.network.packet.Packet1Login;
import net.minecraft.server.MinecraftServer;
import rpg.RPG;
import rpg.enums.EnumGui;
import rpg.network.packet.PacketUpdatePlayersClassName;
import rpg.playerinfo.PlayerInformation;
import rpg.sounds.SoundLoader;
import cpw.mods.fml.common.network.IConnectionHandler;
import cpw.mods.fml.common.network.Player;

public class ConnectionHandler implements IConnectionHandler {

    @Override
    public void clientLoggedIn(NetHandler clientHandler,
            INetworkManager manager, Packet1Login login) {
    }

    @Override
    public void connectionClosed(INetworkManager manager) {
    }

    @Override
    public void connectionOpened(NetHandler netClientHandler,
            MinecraftServer server, INetworkManager manager) {
    }

    @Override
    public void connectionOpened(NetHandler netClientHandler, String server,
            int port, INetworkManager manager) {
    }

    @Override
    public String connectionReceived(NetLoginHandler netHandler,
            INetworkManager manager) {
        return null;
    }

    @Override
    public void playerLoggedIn(Player player, NetHandler netHandler,
            INetworkManager manager) {
        PlayerInformation playerInfo = PlayerInformation
                .forPlayer((EntityPlayerMP) player);
        if (playerInfo.getPlayersClass().equals("")) {
            ((EntityPlayerMP) player).openGui(RPG.instance,
                    EnumGui.LoreStartingPage.getIndex(),
                    ((EntityPlayerMP) player).worldObj, 0, 0, 0);
        } else {
            ((EntityPlayerMP) player)
                    .sendChatToPlayer("<Mysterious Voice> Welcome back master "
                            + playerInfo.getPlayersClass());
            new PacketUpdatePlayersClassName().sendToServer();
        }

        if (SoundLoader.didSoundsLoad == true) {
            ((EntityPlayerMP) player)
                    .sendChatToPlayer("[MinePG Sound Loader] Loaded Sounds Successfully");
        } else if (SoundLoader.didSoundsLoad == false) {
            ((EntityPlayerMP) player)
                    .sendChatToPlayer("[MinePG Sound Loader] Failed to load one or more sounds");
        }
    }
}

 

Code for an item's addInformation() method:

@Override
    @SuppressWarnings({ "rawtypes", "unchecked" })
    public void addInformation(ItemStack par1ItemStack, EntityPlayer player,
            List par3List, boolean par4) {
        PlayerInformation playerInfo = PlayerInformation.forPlayer(player);
        // Checks the players class and colored item name
        // accordingly
        if (playerInfo.getPlayersClass() == "Warrior"
                && player.experienceLevel >= 1) {
            par3List.add("Class: §AWarrior");
            par3List.add("Level: §A1");
        } else if (playerInfo.getPlayersClass() == "Warrior"
                && player.experienceLevel != 1) {
            par3List.add("Class: §AWarrior");
            par3List.add("Level: §41");
        } else if (playerInfo.getPlayersClass() != "Warrior"
                && player.experienceLevel == 1) {
            par3List.add("Class: §4Warrior");
            par3List.add("Level: §A1");
        } else {
            par3List.add("Class: §4Warrior");
            par3List.add("Level: §41");
        }
    }

 

[sIDE NOTE]

As the code for the addInformation() method is above, it returns as "", but if I use the proper .equals("String here"), it returns as null.

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

Link to comment
Share on other sites

So I would need to make a packet that first, got the data needed, then second, sent the data to the client, and thirdly, take the received data to a String variable inside the item class, and lastly, do what I was doing before?

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

Link to comment
Share on other sites

I can't quite figure it out... I will try again a bit later. but any pointers in the right direction would be helpful.

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

Link to comment
Share on other sites

Bump for no particular reason.

 

Except for the fact that diesieben07 seems to be the only one who really helps me... Can anyone else be of assistance?

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

Link to comment
Share on other sites

Once again I am bumping this so that the great diesieben07 can see this and finish off the help he started giving.

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

Link to comment
Share on other sites

Thats the thing, your point in the right direction was good, I just didn't quite get what the packet should contain, and how to obtain the string from the packet :/

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

Link to comment
Share on other sites

Uhh, what system? Just so you know, you haven't updated the Github repo for questology in a mater of months therefore anything added in that time is not known about. So I don't think that system is in there....

 

And I don't get how I retrieve the string from the packet from inside the item class. How do I set it? Its confusing me :/

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

Link to comment
Share on other sites

BUMP

 

And can you give me an example?

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • OLXTOTO - Bandar Togel Online Dan Slot Terbesar Di Indonesia OLXTOTO telah lama dikenal sebagai salah satu bandar online terkemuka di Indonesia, terutama dalam pasar togel dan slot. Dengan reputasi yang solid dan pengalaman bertahun-tahun, OLXTOTO menawarkan platform yang aman dan andal bagi para penggemar perjudian daring. DAFTAR OLXTOTO DISINI DAFTAR OLXTOTO DISINI DAFTAR OLXTOTO DISINI Beragam Permainan Togel Sebagai bandar online terbesar di Indonesia, OLXTOTO menawarkan berbagai macam permainan togel. Mulai dari togel Singapura, togel Hongkong, hingga togel Sidney, pemain memiliki banyak pilihan untuk mencoba keberuntungan mereka. Dengan sistem yang transparan dan hasil yang adil, OLXTOTO memastikan bahwa setiap taruhan diproses dengan cepat dan tanpa keadaan. Slot Online Berkualitas Selain togel, OLXTOTO juga menawarkan berbagai permainan slot online yang menarik. Dari slot klasik hingga slot video modern, pemain dapat menemukan berbagai opsi permainan yang sesuai dengan preferensi mereka. Dengan grafis yang memukau dan fitur bonus yang menggiurkan, pengalaman bermain slot di OLXTOTO tidak akan pernah membosankan. Keamanan dan Kepuasan Pelanggan Terjamin Keamanan dan kepuasan pelanggan merupakan prioritas utama di OLXTOTO. Mereka menggunakan teknologi enkripsi terbaru untuk melindungi data pribadi dan keuangan para pemain. Tim dukungan pelanggan yang ramah dan responsif siap membantu pemain dengan setiap pertanyaan atau masalah yang mereka hadapi. Promosi dan Bonus Menarik OLXTOTO sering menawarkan promosi dan bonus menarik kepada para pemainnya. Mulai dari bonus selamat datang hingga bonus deposit, pemain memiliki kesempatan untuk meningkatkan kemenangan mereka dengan memanfaatkan berbagai penawaran yang tersedia. Penutup Dengan reputasi yang solid, beragam permainan berkualitas, dan komitmen terhadap keamanan dan kepuasan pelanggan, OLXTOTO tetap menjadi salah satu pilihan utama bagi para pecinta judi online di Indonesia. Jika Anda mencari pengalaman berjudi yang menyenangkan dan terpercaya, OLXTOTO layak dipertimbangkan.
    • I have been having a problem with minecraft forge. Any version. Everytime I try to launch it it always comes back with error code 1. I have tried launching from curseforge, from the minecraft launcher. I have also tried resetting my computer to see if that would help. It works on my other computer but that one is too old to run it properly. I have tried with and without mods aswell. Fabric works, optifine works, and MultiMC works aswell but i want to use forge. If you can help with this issue please DM on discord my # is Haole_Dawg#6676
    • Add the latest.log (logs-folder) with sites like https://paste.ee/ and paste the link to it here  
    • I have no idea how a UI mod crashed a whole world but HUGE props to you man, just saved me +2 months of progress!  
    • So i know for a fact this has been asked before but Render stuff troubles me a little and i didnt find any answer for recent version. I have a custom nausea effect. Currently i add both my nausea effect and the vanilla one for the effect. But the problem is that when I open the inventory, both are listed, while I'd only want mine to show up (both in the inv and on the GUI)   I've arrived to the GameRender (on joined/net/minecraft/client) and also found shaders on client-extra/assets/minecraft/shaders/post and client-extra/assets/minecraft/shaders/program but I'm lost. I understand that its like a regular screen, where I'd render stuff "over" the game depending on data on the server, but If someone could point to the right client and server classes that i can read to see how i can manage this or any tip would be apreciated
  • Topics

×
×
  • Create New...

Important Information

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