Jump to content

Recommended Posts

Posted

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

Posted

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.

Posted

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;

}

 

}

 

 

 

Posted

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 ^_^

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.

×
×
  • Create New...

Important Information

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