From a GUI screen, just use Minecraft.getMinecraft().thePlayer - it is always the client player that opened the screen
As long as your values were synced to the client (which they should be since you are using DataWatcher), then they can be accessed via the standard IEEP type call : YourExtendedPropsClass.get(mc.thePlayer).getWhateverValue().
I'm calling addTP() in an Event that has a !event.world.isRemote
Thanks for the help. I'll check your response tomorrow!
EDIT: I fixed my problem. For some reason, this.maxTP = 0, so when I checked if the amount being added was greater than max, it would default to 0
(IE: datawatcher.update(TP_WATCHER, ((amount + tp) > this.maxTP ? this.maxTP : (amount + tp)));
(amount + tp) was greater than this.maxTP (0), so it kept updating it to 0...
edit: Never mind i fixed my issues. Im still learning NBT and IEEP. and realized i only need 1 Identifier. and just put my Currency along with the bed coords together.
So what is happening is Player can save and Load data properly in-game. when death occurs, it saves normal.
but for some reason when you log out, then back in. Only PlayerBed successfully loads its data while playercol fails to load its data.
these are both separate classes. if there is anything else you need me to paste. let me know.
server log error
[20:31:01] [Server thread/ERROR] [FML]: Failed to load extended properties for Col. This is a mod issue.
loaded NBT data - PLAYERBED{bedCoordX:-246,bedCoordY:64,bedCoordZ:146,}
java.lang.ClassCastException: net.minecraft.nbt.NBTTagInt cannot be cast to net.minecraft.nbt.NBTTagCompound
at net.teamsao.mcsao.player.playerextendedprop.PlayerCol.loadNBTData(PlayerCol.java:96)
at net.minecraft.entity.Entity.readFromNBT(Entity.java:1642)
playercol loadnbtdata and playerbed data:
playerCOl
@Override
public void loadNBTData(NBTTagCompound compound) {
NBTTagCompound properties = (NBTTagCompound)compound.getTag(COL_AMOUNT);
this.col_amount = properties.getDouble("colAmount");
System.out.println("loaded NBT data - PLAYERCOL" + properties);
Trying to make a tick event to check armor and allow player to fly. I read what you said about not ticks because there are easier methods, but it would not let me end the flying once I unequipped the armor.
If there is an easier method can you tell me otherwise i'd like to know what i need to add or change to the code below to make it work.
public class PlayerTickHandler {
@SubscribeEvent
public void onPlayerTick(World world, EntityPlayer player, ItemStack itemStack) {
if (player.getCurrentArmor(3) != null) {
ItemStack helmet = player.getCurrentArmor(3);
Trying to make a tick event to check armor and allow player to fly. I read what you said about not ticks because there are easier methods, but it would not let me end the flying once I unequipped the armor.
If there is an easier method can you tell me otherwise i'd like to know what i need to add or change to the code below to make it work.
Nope, that is the only way to do it, since the armor does not receive an update tick once it is removed / broken.
Then why isnt the tick handler working? Is there fixs to be made? thats the whole class
Because you cannot add parameters to event methods: the only parameter is the event.
@SubscribeEvent
public void onPlayerTick(PlayerTickEvent event) {
// player: event.player
// world: event.player.worldObj
// itemstack: use any of player methods (e.g., player.getHeldItem,player.getCurrentArmor, etc)
}
Because you cannot add parameters to event methods: the only parameter is the event.
@SubscribeEvent
public void onPlayerTick(PlayerTickEvent event) {
// player: event.player
// world: event.player.worldObj
// itemstack: use any of player methods (e.g., player.getHeldItem,player.getCurrentArmor, etc)
}
sorry for being a pain but im still learning and i tend to miss the small things. sadly that didnt work. Did you mean like this?
Make sure you are using server commands, as I believe the default commands run client side only.
I believe i've registered the commands using server commands:
@EventHandler
public void serverStart(FMLServerStartingEvent event) {
MinecraftServer server = MinecraftServer.getServer();
// Gets current server
ICommandManager command = server.getCommandManager();
// Gets the command manager to use for server
Oh, I just saw your Main class... yeah, that's not how it's done buddy. @EventHandler is for FML events such as FMLPreInitializationEvent, which are used in the main class during mod initialization.
@SubscribeEvent is for Forge events (and game events from FML, such as KeyInputEvent) - please read a tutorial on how to set up the main mod class, as well as the tutorial in the first post about Forge Events.
Is it possible to make a IExtendedEntityProperties but for a world (or a group of world: overworld, nether and end) like IExtendedWorldProperties? Because I would like to make a list of all the teams name in the server.
You're looking for a class called 'WorldSavedData'.
Both. You append NBTTagCompound elements to the List, and then you store the list in the original tag compound.
Here is an example of an inventory saving ItemStacks in an NBTTagList. You can store anything you like in the NBTTagCompounds going into the list - they do not have to be ItemStacks.
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumAs long as your values were synced to the client (which they should be since you are using DataWatcher), then they can be accessed via the standard IEEP type call : YourExtendedPropsClass.get(mc.thePlayer).getWhateverValue().
Yas it works
Well, everything except the actual point system :SI'm still getting:2014-09-01 21:15:59 [INFO] [STDOUT] [ExtendedPlayer] TP: 0 | Sum of amount + TP: 12014-09-01 21:15:59 [INFO] [STDOUT] [ExtendedPlayer] CurrentTP: 0I'm calling addTP() in an Event that has a !event.world.isRemoteThanks for the help. I'll check your response tomorrow!EDIT: I fixed my problem. For some reason, this.maxTP = 0, so when I checked if the amount being added was greater than max, it would default to 0
(IE: datawatcher.update(TP_WATCHER, ((amount + tp) > this.maxTP ? this.maxTP : (amount + tp)));
(amount + tp) was greater than this.maxTP (0), so it kept updating it to 0...
:3
So what is happening is Player can save and Load data properly in-game. when death occurs, it saves normal.
but for some reason when you log out, then back in. Only PlayerBed successfully loads its data while playercol fails to load its data.
these are both separate classes. if there is anything else you need me to paste. let me know.
server log error
loaded NBT data - PLAYERBED{bedCoordX:-246,bedCoordY:64,bedCoordZ:146,}
java.lang.ClassCastException: net.minecraft.nbt.NBTTagInt cannot be cast to net.minecraft.nbt.NBTTagCompound
at net.teamsao.mcsao.player.playerextendedprop.PlayerCol.loadNBTData(PlayerCol.java:96)
at net.minecraft.entity.Entity.readFromNBT(Entity.java:1642)
playercol loadnbtdata and playerbed data:
playerCOl
@Override
public void loadNBTData(NBTTagCompound compound) {
NBTTagCompound properties = (NBTTagCompound)compound.getTag(COL_AMOUNT);
this.col_amount = properties.getDouble("colAmount");
System.out.println("loaded NBT data - PLAYERCOL" + properties);
}
PlayerSAO
@Override
public void loadNBTData(NBTTagCompound compound) {
NBTTagCompound properties = (NBTTagCompound)compound.getTag(EXT_PROP_NAME);
this.overWorldX = properties.getInteger("bedCoordX");
this.overWorldY = properties.getInteger("bedCoordY");
this.overWorldZ = properties.getInteger("bedCoordZ");
System.out.println("loaded NBT data - PLAYERBED" + properties);
}
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumIf there is an easier method can you tell me otherwise i'd like to know what i need to add or change to the code below to make it work.
public class PlayerTickHandler {
@SubscribeEvent
public void onPlayerTick(World world, EntityPlayer player, ItemStack itemStack) {
if (player.getCurrentArmor(3) != null) {
ItemStack helmet = player.getCurrentArmor(3);
if (helmet.getItem() == RebornMod.head_phones)
{
player.fallDistance = 0.0F;
player.capabilities.allowFlying = true;
}
}
else{
player.capabilities.allowFlying = false;
}
}
}
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumNope, that is the only way to do it, since the armor does not receive an update tick once it is removed / broken.
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumBecause you cannot add parameters to event methods: the only parameter is the event.
@SubscribeEvent public void onPlayerTick(PlayerTickEvent event) { // player: event.player // world: event.player.worldObj // itemstack: use any of player methods (e.g., player.getHeldItem,player.getCurrentArmor, etc) }sorry for being a pain but im still learning and i tend to miss the small things. sadly that didnt work. Did you mean like this?
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent.PlayerTickEvent;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
public class PlayerTickHandler {
@SubscribeEvent
public void onPlayerTick(PlayerTickEvent event) {
if (event.player.getCurrentArmor(3) != null) {
ItemStack helmet = event.player.getCurrentArmor(3);
if (helmet.getItem() == RebornMod.head_phones)
{
event.player.fallDistance = 0.0F;
event.player.capabilities.allowFlying = true;
}
}
else{
event.player.capabilities.allowFlying = false;
}
}
}
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumI tried to follow them, however it seems i got something wrong. It seems that my saveNBTData & loadNBTData are not working/not being called at all! :/
Any idea what i could've missed? Couldnt find the answer in google/forums.
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumDid you register your extended properties on entity constructing?
I believe i did.
// MC1.7.10
@EventHandler
public void onEntityConstructing(EntityConstructing event) {
if (event.entity instanceof EntityPlayer
&& ExtendedPlayer.get((EntityPlayer) event.entity) == null)
ExtendedPlayer.register((EntityPlayer) event.entity);
}
For some odd reason not only NBT methodes are not called, but also get(EntityPlayer) returns null all the time
Source/github: Main, CMDEvents, ExtendedPlayer
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumI believe i've registered the commands using server commands:
@EventHandler
public void serverStart(FMLServerStartingEvent event) {
MinecraftServer server = MinecraftServer.getServer();
// Gets current server
ICommandManager command = server.getCommandManager();
// Gets the command manager to use for server
ServerCommandManager serverCommand = ((ServerCommandManager) command);
serverCommand.registerCommand(new CMDEvents());
}
-
View User Profile
-
View Posts
-
Send Message
Curse Premium@SubscribeEvent is for Forge events (and game events from FML, such as KeyInputEvent) - please read a tutorial on how to set up the main mod class, as well as the tutorial in the first post about Forge Events.
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumYou're looking for a class called 'WorldSavedData'.
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumUse NBTTagList, which stores NBTTagCompounds. Take a look at any inventory's read/write NBT methods to see an example.
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumHere is an example of an inventory saving ItemStacks in an NBTTagList. You can store anything you like in the NBTTagCompounds going into the list - they do not have to be ItemStacks.