Jump to content

Display a Gui if values of IEEPs are empty ore null


ItsAMysteriousYT

Recommended Posts

Im trying to opena GuiScreen only when several values in my IEEP's are not set or empty. I register my IEEPs as usual in EntityConstructing event and then check using playerTickEvent wether the gui should open or not. Unfortunately thegui opens every time (But the player always is the same, i logged in to my MC-Account). Also i don't think that this is beeing caused by any saving errors in my IEEP's...

 

This is my Code:

 

The loadFromNBT & saveToNBT methods:

 

 

@Override

public void saveNBTData(NBTTagCompound compound) {

NBTTagCompound properties = new NBTTagCompound();

 

// Saving the players name,gender & health

properties.setString("Name", this.name);

properties.setString("Surname", this.surname);

properties.setString("Gender", EnumGender.toString(this.gender));

properties.setDouble("Waterlevel", this.water);

properties.setDouble("Peevalue", this.pee_value);

properties.setDouble("Poopvalue", this.poop_value);

properties.setDouble("Energy", this.energy);

properties.setFloat("Money", this.money);

 

// Saving all the counters

properties.setDouble("Time_Waterless", this.timeWaterless);

properties.setDouble("WaterMessage_Time", this.waterlowmessagetime);

properties.setBoolean("Tutorial_Done", this.doneTutorial);

 

// Saving the players cars -> for-loop through list of car entity-ids

compound.setTag(EXT_PROP_NAME, properties);

}

 

@Override

public void loadNBTData(NBTTagCompound compound) {

NBTTagCompound tag = compound.getCompoundTag(EXT_PROP_NAME);

System.out.println("Succesfully loaded tag");

// Loading the players name,gender & health

this.name = tag.getString("Name");

System.out.println("Setting name to:" + tag.getString("Name"));

 

this.surname = tag.getString("Surname");

this.gender = EnumGender.getFromString(tag.getString("Gender"));

this.water = tag.getDouble("Waterlevel");

this.pee_value = tag.getDouble("Peevalue");

this.poop_value = tag.getDouble("Poopvalue");

this.energy = tag.getDouble("Energy");

this.money = tag.getFloat("Money");

 

// Saving all the counters

this.timeWaterless = tag.getInteger("Time_Waterless");

this.waterlowmessagetime = tag.getInteger("WaterMessage_Time");

this.doneTutorial = tag.getBoolean("Tutorial_Done");

 

}

 

 

 

The two events in my CommonHandler:

 

 

@SubscribeEvent

public void updateRealLifeProps(PlayerTickEvent event) {

tickrun++;

if (RLMPlayerProps.get(event.player) != null) {

RLMPlayerProps props = RLMPlayerProps.get(event.player);

props.circleOfLife();

if (props.name.isEmpty() || props.surname.isEmpty() || props.gender == null) {

System.out.println("Now opening Gui because: " + String.valueOf(props.name.isEmpty())

+ String.valueOf(props.surname.isEmpty()) + String.valueOf(props.gender == null));

if (event.side.isServer()&&tickrun>3) {

BlockPos p = event.player.getPosition();

event.player.openGui(RealLifeMod.instance, GuiModInit.ID, event.player.worldObj, p.getX(), p.getY(),

p.getZ());

}

}

}

 

}

 

@SubscribeEvent

public void onEntityConstructing(EntityConstructing event) {

if (event.entity instanceof EntityPlayer)

if (RLMPlayerProps.get((EntityPlayer) event.entity) == null) {

RLMPlayerProps.register((EntityPlayer) event.entity);

System.out.println("Succesfully registered RLMProps");

 

}

 

}

 

 

 

 

Thanks in Advice & Happy New Year!!

Link to comment
Share on other sites

What's the console output from your System.out.println statements? Are those values still empty / null? I assume you set those values from the GUI, but that's client-side only, so are you sending packets to the server to set the actual data there?

 

Btw, you don't need to pass the block position coordinates to open the GUI if you are not going to be using them for anything.

Link to comment
Share on other sites

Yea, im sending a setPropertiesPackage from the Gui. This is my Packet:

 

 

package itsamysterious.mods.reallifemod.core.packets;

 

import io.netty.buffer.ByteBuf;

import itsamysterious.mods.reallifemod.core.lifesystem.RLMPlayerProps;

import net.minecraftforge.fml.common.network.ByteBufUtils;

import net.minecraftforge.fml.common.network.simpleimpl.IMessage;

 

public class SetPropertiesPackage implements IMessage{

public String gender;

public String name;

public String surname;

public int id;

 

public SetPropertiesPackage(){}

 

public SetPropertiesPackage(int id, String name, String surname, String gender) {

this.name = name;

this.surname = surname;

this.gender = gender;

this.id = id;

}

 

@Override

public void fromBytes(ByteBuf buf) {

name = ByteBufUtils.readUTF8String(buf);

surname = ByteBufUtils.readUTF8String(buf);

gender = ByteBufUtils.readUTF8String(buf);

id=buf.readInt();

}

 

@Override

public void toBytes(ByteBuf buf) {

        ByteBufUtils.writeUTF8String(buf, name);

        ByteBufUtils.writeUTF8String(buf, surname);

        ByteBufUtils.writeUTF8String(buf, gender);

        buf.writeInt(id);

}

 

}

 

 

 

 

And this is the handler:

 

 

package itsamysterious.mods.reallifemod.core.packets;

 

import itsamysterious.mods.reallifemod.RealLifeMod;

import itsamysterious.mods.reallifemod.core.RealLifeMod_Items;

import itsamysterious.mods.reallifemod.core.lifesystem.RLMPlayerProps;

import itsamysterious.mods.reallifemod.core.lifesystem.enums.EnumGender;

import net.minecraft.client.Minecraft;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.entity.player.EntityPlayerMP;

import net.minecraft.util.IThreadListener;

import net.minecraft.world.World;

import net.minecraft.world.WorldServer;

import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;

import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;

 

public class SetPropertiesHandler implements IMessageHandler<SetPropertiesPackage, SetPropertiesPackage> {

 

public SetPropertiesHandler() {

}

 

@Override

public SetPropertiesPackage onMessage(final SetPropertiesPackage message, final MessageContext ctx) {

IThreadListener mainThread = (WorldServer) ctx.getServerHandler().playerEntity.worldObj;

mainThread.addScheduledTask(new Runnable() {

@Override

public void run() {

EntityPlayerMP player = ctx.getServerHandler().playerEntity;

RLMPlayerProps props = RLMPlayerProps.get(player);

if (props == null) {

System.out.println("Properties are NULL!!");

}

props.name = message.name;

props.surname = message.surname;

props.gender = EnumGender.getFromString(message.gender);

//RealLifeMod.network.sendTo(new PropertiesSetPackage(), player);

}

});

return null;

}

 

}

 

 

 

Link to comment
Share on other sites

Short update - the handler now looks like this:

 

 

package itsamysterious.mods.reallifemod.core.packets;

 

import itsamysterious.mods.reallifemod.RealLifeMod;

import itsamysterious.mods.reallifemod.core.RealLifeMod_Items;

import itsamysterious.mods.reallifemod.core.lifesystem.RLMPlayerProps;

import itsamysterious.mods.reallifemod.core.lifesystem.enums.EnumGender;

import net.minecraft.client.Minecraft;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.entity.player.EntityPlayerMP;

import net.minecraft.util.IThreadListener;

import net.minecraft.world.World;

import net.minecraft.world.WorldServer;

import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;

import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;

 

public class SetPropertiesHandler implements IMessageHandler<SetPropertiesPackage, SetPropertiesPackage> {

 

public SetPropertiesHandler() {

}

 

@Override

public SetPropertiesPackage onMessage(final SetPropertiesPackage message, final MessageContext ctx) {

IThreadListener mainThread = (WorldServer) ctx.getServerHandler().playerEntity.worldObj;

mainThread.addScheduledTask(new Runnable() {

@Override

public void run() {

EntityPlayerMP player = ctx.getServerHandler().playerEntity;

RLMPlayerProps.get(player).name = message.name;

RLMPlayerProps.get(player).surname = message.surname;

RLMPlayerProps.get(player).gender = EnumGender.getFromString(message.gender);

System.out.println(RLMPlayerProps.get(player).name+" "+RLMPlayerProps.get(player).surname+" "+RLMPlayerProps.get(player).gender.toString());

}

});

return null;

}

 

}

 

 

 

 

I thougt - setting the name of the props directly from the player would be better than just setting them for an instance ^_^

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

    • Let me try and help you with love spells, traditional healing, native healing, fortune telling, witchcraft, psychic readings, black magic, voodoo, herbalist healing, or any other service your may desire within the realm of african native healing, the spirits and the ancestors. I am a sangoma and healer. I could help you to connect with the ancestors , interpret dreams, diagnose illness through divination with bones, and help you heal both physical and spiritual illness. We facilitate the deepening of your relationship to the spirit world and the ancestors. Working in partnership with one\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’s ancestors is a gift representing a close link with the spirit realm as a mediator between the worlds.*   Witchdoctors, or sorcerers, are often purveyors of mutis and charms that cause harm to people. we believe that we are here for only one purpose, to heal through love and compassion.*   African people share a common understanding of the importance of ancestors in daily life. When they have lost touch with their ancestors, illness may result or bad luck. Then a traditional healer, or sangoma, is sought out who may prescribe herbs, changes in lifestyle, a career change, or changes in relationships. The client may also be told to perform a ceremony or purification ritual to appease the ancestors.*   Let us solve your problems using powerful African traditional methods. We believe that our ancestors and spirits give us enlightenment, wisdom, divine guidance, enabling us to overcome obstacles holding your life back. Our knowledge has been passed down through centuries, being refined along the way from generation to generation. We believe in the occult, the paranormal, the spirit world, the mystic world.*   The services here are based on the African Tradition Value system/religion,where we believe the ancestors and spirits play a very important role in society. The ancestors and spirits give guidance and counsel in society. They could enable us to see into the future and give solutions to the problems affecting us. We use rituals, divination, spells, chants and prayers to enable us tackle the task before us.*   I have experience in helping and guiding many people from all over the world. My psychic abilities may help you answer and resolve many unanswered questions
    • Let me try and help you with love spells, traditional healing, native healing, fortune telling, witchcraft, psychic readings, black magic, voodoo, herbalist healing, or any other service your may desire within the realm of african native healing, the spirits and the ancestors. I am a sangoma and healer. I could help you to connect with the ancestors , interpret dreams, diagnose illness through divination with bones, and help you heal both physical and spiritual illness. We facilitate the deepening of your relationship to the spirit world and the ancestors. Working in partnership with one\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’s ancestors is a gift representing a close link with the spirit realm as a mediator between the worlds.*   Witchdoctors, or sorcerers, are often purveyors of mutis and charms that cause harm to people. we believe that we are here for only one purpose, to heal through love and compassion.*   African people share a common understanding of the importance of ancestors in daily life. When they have lost touch with their ancestors, illness may result or bad luck. Then a traditional healer, or sangoma, is sought out who may prescribe herbs, changes in lifestyle, a career change, or changes in relationships. The client may also be told to perform a ceremony or purification ritual to appease the ancestors.*   Let us solve your problems using powerful African traditional methods. We believe that our ancestors and spirits give us enlightenment, wisdom, divine guidance, enabling us to overcome obstacles holding your life back. Our knowledge has been passed down through centuries, being refined along the way from generation to generation. We believe in the occult, the paranormal, the spirit world, the mystic world.*   The services here are based on the African Tradition Value system/religion,where we believe the ancestors and spirits play a very important role in society. The ancestors and spirits give guidance and counsel in society. They could enable us to see into the future and give solutions to the problems affecting us. We use rituals, divination, spells, chants and prayers to enable us tackle the task before us.*   I have experience in helping and guiding many people from all over the world. My psychic abilities may help you answer and resolve many unanswered questions
    • Let me try and help you with love spells, traditional healing, native healing, fortune telling, witchcraft, psychic readings, black magic, voodoo, herbalist healing, or any other service your may desire within the realm of african native healing, the spirits and the ancestors. I am a sangoma and healer. I could help you to connect with the ancestors , interpret dreams, diagnose illness through divination with bones, and help you heal both physical and spiritual illness. We facilitate the deepening of your relationship to the spirit world and the ancestors. Working in partnership with one\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’s ancestors is a gift representing a close link with the spirit realm as a mediator between the worlds.*   Witchdoctors, or sorcerers, are often purveyors of mutis and charms that cause harm to people. we believe that we are here for only one purpose, to heal through love and compassion.*   African people share a common understanding of the importance of ancestors in daily life. When they have lost touch with their ancestors, illness may result or bad luck. Then a traditional healer, or sangoma, is sought out who may prescribe herbs, changes in lifestyle, a career change, or changes in relationships. The client may also be told to perform a ceremony or purification ritual to appease the ancestors.*   Let us solve your problems using powerful African traditional methods. We believe that our ancestors and spirits give us enlightenment, wisdom, divine guidance, enabling us to overcome obstacles holding your life back. Our knowledge has been passed down through centuries, being refined along the way from generation to generation. We believe in the occult, the paranormal, the spirit world, the mystic world.*   The services here are based on the African Tradition Value system/religion,where we believe the ancestors and spirits play a very important role in society. The ancestors and spirits give guidance and counsel in society. They could enable us to see into the future and give solutions to the problems affecting us. We use rituals, divination, spells, chants and prayers to enable us tackle the task before us.*   I have experience in helping and guiding many people from all over the world. My psychic abilities may help you answer and resolve many unanswered questions
    • Let me try and help you with love spells, traditional healing, native healing, fortune telling, witchcraft, psychic readings, black magic, voodoo, herbalist healing, or any other service your may desire within the realm of african native healing, the spirits and the ancestors. I am a sangoma and healer. I could help you to connect with the ancestors , interpret dreams, diagnose illness through divination with bones, and help you heal both physical and spiritual illness. We facilitate the deepening of your relationship to the spirit world and the ancestors. Working in partnership with one\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’s ancestors is a gift representing a close link with the spirit realm as a mediator between the worlds.*   Witchdoctors, or sorcerers, are often purveyors of mutis and charms that cause harm to people. we believe that we are here for only one purpose, to heal through love and compassion.*   African people share a common understanding of the importance of ancestors in daily life. When they have lost touch with their ancestors, illness may result or bad luck. Then a traditional healer, or sangoma, is sought out who may prescribe herbs, changes in lifestyle, a career change, or changes in relationships. The client may also be told to perform a ceremony or purification ritual to appease the ancestors.*   Let us solve your problems using powerful African traditional methods. We believe that our ancestors and spirits give us enlightenment, wisdom, divine guidance, enabling us to overcome obstacles holding your life back. Our knowledge has been passed down through centuries, being refined along the way from generation to generation. We believe in the occult, the paranormal, the spirit world, the mystic world.*   The services here are based on the African Tradition Value system/religion,where we believe the ancestors and spirits play a very important role in society. The ancestors and spirits give guidance and counsel in society. They could enable us to see into the future and give solutions to the problems affecting us. We use rituals, divination, spells, chants and prayers to enable us tackle the task before us.*   I have experience in helping and guiding many people from all over the world. My psychic abilities may help you answer and resolve many unanswered questions
    • Let me try and help you with love spells, traditional healing, native healing, fortune telling, witchcraft, psychic readings, black magic, voodoo, herbalist healing, or any other service your may desire within the realm of african native healing, the spirits and the ancestors. I am a sangoma and healer. I could help you to connect with the ancestors , interpret dreams, diagnose illness through divination with bones, and help you heal both physical and spiritual illness. We facilitate the deepening of your relationship to the spirit world and the ancestors. Working in partnership with one\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’s ancestors is a gift representing a close link with the spirit realm as a mediator between the worlds.*   Witchdoctors, or sorcerers, are often purveyors of mutis and charms that cause harm to people. we believe that we are here for only one purpose, to heal through love and compassion.*   African people share a common understanding of the importance of ancestors in daily life. When they have lost touch with their ancestors, illness may result or bad luck. Then a traditional healer, or sangoma, is sought out who may prescribe herbs, changes in lifestyle, a career change, or changes in relationships. The client may also be told to perform a ceremony or purification ritual to appease the ancestors.*   Let us solve your problems using powerful African traditional methods. We believe that our ancestors and spirits give us enlightenment, wisdom, divine guidance, enabling us to overcome obstacles holding your life back. Our knowledge has been passed down through centuries, being refined along the way from generation to generation. We believe in the occult, the paranormal, the spirit world, the mystic world.*   The services here are based on the African Tradition Value system/religion,where we believe the ancestors and spirits play a very important role in society. The ancestors and spirits give guidance and counsel in society. They could enable us to see into the future and give solutions to the problems affecting us. We use rituals, divination, spells, chants and prayers to enable us tackle the task before us.*   I have experience in helping and guiding many people from all over the world. My psychic abilities may help you answer and resolve many unanswered questions
  • Topics

×
×
  • Create New...

Important Information

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