It's pretty simple, and just returns the value of currentMana.
BUT, are you using the currentMana field, or are you actually using DataWatcher? Show your full IEEP class, as well as your full Item class. Use [ spoiler ] tags around large sections (such as code for an entire class).
BUT, are you using the currentMana field, or are you actually using DataWatcher? Show your full IEEP class, as well as your full Item class. Use [ spoiler ] tags around large sections (such as code for an entire class).
Ok, just a heads up, the class is called PlayerNetworkManager, and everything is in energy units, not mana. I just has my code listed as mana to avoid confusion.
Yep, your problem is you are only sending the chat message on the client side (world IS remote), BUT you never send any packets letting the client side know what values your player's IEEP has (such as current energy).
Quick Solution: Only send the message from the server side (i.e. add a '!' in front of 'world.isRemote').
Try putting more debug statements in your code - add the same println you have in loadFromNBT to replenishMana and getEnergy, but change the first part to tell you where it's being called from, e.g.:
public int getEnergy() {<br>System.out.println("Getting energy: " + this.currentEnergy + "/" + this.maxEnergy);<br>return currentEnergy;<br>}<br>
Then look at your console output and see what you can see.
I found this weird, because it sees that I have 50 energy, then sees that I have 0 energy. As it sees that I have 0 energy second, it outputs 0 energy to the chat.
EDIT: It outputs this EVERY time you right click the item.
Alright.
- In your EventHandler #onEntityConstructing, you register your properties twice; once using the static method from ExtendedPlayer, and once using the code from that static method directly. You only need one of those.
- Any particular reason you named your IEEP 'PlayerNetworkManager' and put it in the 'network' package? Seems.... odd.
- Your ItemQuantumGuide constructor is pointless - making an ItemStack in an Item constructor does absolutely nothing.
- The problem lies in your read/write NBT methods within your IEEP class: look carefully at the string you use to save your current and max energy, then compare it to what you use to load it. Hint: they are not the same xD
Thus, the server side tries to load non-existent variables and, not finding them, sets everything to zero; the client, meantime, doesn't load from NBT at all, or get synced from the server, so still has the initial values you set in the class constructor (0 and 50, respectively).
The Meaning of Life, the Universe, and Everything.
Join Date:
8/20/2014
Posts:
51
Location:
In The Cloud
Minecraft:
MESSpace
Member Details
I am MESSpace, and I shall answer ALL THE THINGS!!!
- I removed the second registry in the EventHandler
- I like to think of the quantum energy stored in a "Network" of sorts. I named it PlayerNetworkManager because it well... manages the player's "Network". Network package you ask? I put it there in case I add any other things that have to pertain to changes to the network. I sometimes like to create classes that act as aliases to some blocks of code such as outputting a message client side. If I make a class like this, I shall dub it NetworkAliases and put it in thee network package.
- The ItemQuantumGuide was a test to create a written book. It did not work.
- LOL I see what I did there! xD I just love it when I derp up my code and never notice it! I'll change it and make sure it works. EDIT: IT WORKS
Thanks for your help, I really appreciate it! I hope to continue using your awesome IEEP stuffs while creating my mod! Interesting story, the reason I'm creating this mod is because I accidentally deleted the workspace of a mod I had been working on previously. It wasn't too bad though, because as I was coding the mod, I kept wanting to add features that wouldn't really fit with the theme of the mod. By creating something that's a little less constrained, I can do all of the things I had in mind.
I don't know if you've already covered this in a previous post, but can you clarify how I go about packet handling in 1.8?
I can't find any information on what i'd have to do to register and send/recieve packets with forge in 1.8.
I'm working through your gui overlay tutorial at the moment but i'm stuck on what to do next, since I can't rely on the example code you reference on the forge wiki, and the packetpipeline code is outdated.
See the demo code - I do also have a 1.7.10 network tutorial, but I haven't updated it to reflect what I currently use in the demo.
Hey man, thanks for this topic. After being away from modding for over 1 year, I'm trying to do some stuff again and have a lot of catching up to do.
Your topic was one good source of information.
I post my mods, on GitHub if anyone is interested, but I still have a long way to update them.
Rollback Post to RevisionRollBack
Custom paintings! My latest project, still in BETA.
A small mod to improve your game, but keeping the vanilla flavour. For Minecraft 1.8.
Also check out my Redstone Jukebox mod, now updated to Minecraft 1.7.10!
Will you be doing any tutorials on how to add commands to a mod?
that's information I could use. would be nice to have a command to replenish mana as an example, so I can test different things on command.
All you need to to add a command is create a class extending CommandBase, implement all of the methods, and register it during FMLServerStartingEvent. Not much to it...
okay the command is registered properly, but I don't understand how to access the extendedplayer class inside the execute method so I can call my replenishmana method...?
I feel like it's on the tip of my tongue XD
All of the FML events that one would put in the main mod class use @Mod.EventHandler, NOT @SubscribeEvent - they are completely separate.
As for accessing your extended player properties, it's very simple once you have the EntityPlayer that you want, and is exactly the same as in all of the examples given in the tutorial:
ExtendedPlayer.get(player).someMethod();
In your CommandClass#process method, you get the player who sent the command like so:
So I'm trying to make a mod to handle a custom whitelist, where when a player logs in it checks a database to see if they have one of the required perks.
After looking around a bit, it seems like what I should be using is this:
public class ConnectionHandler extends FMLNetworkEvent {
public ConnectionHandler(INetHandler thing, Class type, NetworkManager manager) {
super(thing, type, manager);
}
@SubscribeEvent
public void onEvent(ServerConnectionFromClientEvent event) {
}
}
However this is giving me an error at the line with super: "The constructor FMLNetworkEvent(T thing, Class<T> type, NetworkManager manager) is not visible"
Am I doing something wrong here?
EDIT: aaaand nevermind. Not sure why I was extending FMLNetworkEvent there.
public class ConnectionHandler {
@SubscribeEvent
public void onEvent(ServerConnectionFromClientEvent event) {
}
}
I don't see any way to get the player uuid from this, which I need to check if they can join. Is it there and I'm just not seeing it, or do I need to use a different event?
Quote from coolAliasPlayerLoggedInEvent, on the FML bus.
PlayerLoggedInEvent is not cancellable as far as I can tell. I'd like to prevent them from logging in at all if they aren't in the database. Is there anything else that works?
PlayerLoggedInEvent is not cancellable as far as I can tell. I'd like to prevent them from logging in at all if they aren't in the database. Is there anything else that works?
You don't have to cancel it, you can kick them from the server directly.
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumBUT, are you using the currentMana field, or are you actually using DataWatcher? Show your full IEEP class, as well as your full Item class. Use [ spoiler ] tags around large sections (such as code for an entire class).
Ok, just a heads up, the class is called PlayerNetworkManager, and everything is in energy units, not mana. I just has my code listed as mana to avoid confusion.
PlayerNetworkManager.class
package messpace.QuantumWizardry.network; import ibxm.Player; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import java.lang.annotation.ElementType; import messpace.QuantumWizardry.common.CommonProxy; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.common.IExtendedEntityProperties; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.EntityEvent.EntityConstructing; import net.minecraftforge.event.entity.EntityJoinWorldEvent; import net.minecraftforge.event.entity.living.LivingFallEvent; import org.lwjgl.opengl.GL11; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.eventhandler.EventPriority; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.gameevent.PlayerEvent; import cpw.mods.fml.common.network.ByteBufUtils; import cpw.mods.fml.common.network.NetworkRegistry; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; public class PlayerNetworkManager implements IExtendedEntityProperties { public final static String EXT_PROP_NAME = "PlayerNetworkManager"; private final EntityPlayer player; private int currentEnergy, maxEnergy; public PlayerNetworkManager(EntityPlayer player) { this.player = player; this.currentEnergy = 0; this.maxEnergy = 50; } public static final void register(EntityPlayer player) { player.registerExtendedProperties(PlayerNetworkManager.EXT_PROP_NAME, new PlayerNetworkManager(player)); } public static final PlayerNetworkManager get(EntityPlayer player) { return (PlayerNetworkManager) player.getExtendedProperties(EXT_PROP_NAME); } @Override public void saveNBTData(NBTTagCompound compound) { NBTTagCompound properties = new NBTTagCompound(); properties.setInteger("CurrentEnergy", this.currentEnergy); properties.setInteger("MaxEnergy", this.maxEnergy); compound.setTag(EXT_PROP_NAME, properties); } @Override public void loadNBTData(NBTTagCompound compound) { NBTTagCompound properties = (NBTTagCompound) compound.getTag(EXT_PROP_NAME); this.currentEnergy = properties.getInteger("CurrentMana"); this.maxEnergy = properties.getInteger("MaxMana"); System.out.println("[TUT PROPS] Mana from NBT: " + this.currentEnergy + "/" + this.maxEnergy); } @Override public void init(Entity entity, World world) { } public boolean consumeEnergy(int amount) { boolean sufficient = amount <= this.currentEnergy; this.currentEnergy -= (amount < this.currentEnergy ? amount : this.currentEnergy); return sufficient; } public void addEnergy(int amount) { this.currentEnergy = this.currentEnergy + amount; } public int getEnergy() { return this.currentEnergy; } public void replenishEnergy() { this.currentEnergy = this.maxEnergy; } }package messpace.QuantumWizardry.items; import messpace.QuantumWizardry.network.PlayerNetworkManager; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.ChatComponentTranslation; import net.minecraft.world.World; public class ItemQuantumReader extends Item { public ItemQuantumReader() { super(); } @Override public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer player) { PlayerNetworkManager props = PlayerNetworkManager.get(player); int currentEnergy = props.getEnergy(); if(world.isRemote) { player.addChatMessage(new ChatComponentTranslation("Current Quantum Energy Detected:" + currentEnergy)); } return itemstack; } }Click The Achievement Below To See My Stuff!
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumQuick Solution: Only send the message from the server side (i.e. add a '!' in front of 'world.isRemote').
Item Class:
package messpace.QuantumWizardry.items; import messpace.QuantumWizardry.network.PlayerNetworkManager; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.ChatComponentTranslation; import net.minecraft.world.World; public class ItemQuantumReader extends Item { public ItemQuantumReader() { super(); } @Override public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer player) { PlayerNetworkManager props = PlayerNetworkManager.get(player); props.replenishEnergy(); int currentEnergy = props.getEnergy(); if(!world.isRemote) { player.addChatMessage(new ChatComponentTranslation("Current Quantum Energy Detected:" + currentEnergy)); } return itemstack; } }I've made no changes to the PlayerNetworkManager class.
Click The Achievement Below To See My Stuff!
-
View User Profile
-
View Posts
-
Send Message
Curse Premiumpublic int getEnergy() {<br>System.out.println("Getting energy: " + this.currentEnergy + "/" + this.maxEnergy);<br>return currentEnergy;<br>}<br>Then look at your console output and see what you can see.
EDIT: God I hate the forum editor. >.<
[19:23:25] [Client thread/INFO]: [messpace.QuantumWizardry.network.PlayerNetworkManager:getEnergy:108]: Getting energy: 50/50
[19:23:25] [Server thread/INFO]: [messpace.QuantumWizardry.network.PlayerNetworkManager:getEnergy:108]: Getting energy: 0/0
[19:23:25] [Client thread/INFO]: [CHAT] Current Quantum Energy Detected:0
I found this weird, because it sees that I have 50 energy, then sees that I have 0 energy. As it sees that I have 0 energy second, it outputs 0 energy to the chat.
EDIT: It outputs this EVERY time you right click the item.
Click The Achievement Below To See My Stuff!
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumThat screams 'problem with your code' to me - did you only register your extended properties on the client side? That's not good.
Also, it is very possible that you have code elsewhere impacting the energy amounts. You should check.
Also, if you want to get a better look at my code, I put it on my Github Page. The little achievement picture in my signature should take you there.
Click The Achievement Below To See My Stuff!
-
View User Profile
-
View Posts
-
Send Message
Curse Premium- In your EventHandler #onEntityConstructing, you register your properties twice; once using the static method from ExtendedPlayer, and once using the code from that static method directly. You only need one of those.
- Any particular reason you named your IEEP 'PlayerNetworkManager' and put it in the 'network' package? Seems.... odd.
- Your ItemQuantumGuide constructor is pointless - making an ItemStack in an Item constructor does absolutely nothing.
- The problem lies in your read/write NBT methods within your IEEP class: look carefully at the string you use to save your current and max energy, then compare it to what you use to load it. Hint: they are not the same xD
Thus, the server side tries to load non-existent variables and, not finding them, sets everything to zero; the client, meantime, doesn't load from NBT at all, or get synced from the server, so still has the initial values you set in the class constructor (0 and 50, respectively).
- I removed the second registry in the EventHandler
- I like to think of the quantum energy stored in a "Network" of sorts. I named it PlayerNetworkManager because it well... manages the player's "Network". Network package you ask? I put it there in case I add any other things that have to pertain to changes to the network. I sometimes like to create classes that act as aliases to some blocks of code such as outputting a message client side. If I make a class like this, I shall dub it NetworkAliases and put it in thee network package.
- The ItemQuantumGuide was a test to create a written book. It did not work.
- LOL I see what I did there! xD I just love it when I derp up my code and never notice it! I'll change it and make sure it works. EDIT: IT WORKS
Thanks for your help, I really appreciate it! I hope to continue using your awesome IEEP stuffs while creating my mod! Interesting story, the reason I'm creating this mod is because I accidentally deleted the workspace of a mod I had been working on previously. It wasn't too bad though, because as I was coding the mod, I kept wanting to add features that wouldn't really fit with the theme of the mod. By creating something that's a little less constrained, I can do all of the things I had in mind.
Click The Achievement Below To See My Stuff!
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumSee the demo code - I do also have a 1.7.10 network tutorial, but I haven't updated it to reflect what I currently use in the demo.
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumYour topic was one good source of information.
I post my mods, on GitHub if anyone is interested, but I still have a long way to update them.
Custom paintings! My latest project, still in BETA.

A small mod to improve your game, but keeping the vanilla flavour. For Minecraft 1.8.

Also check out my Redstone Jukebox mod, now updated to Minecraft 1.7.10!
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumAll you need to to add a command is create a class extending CommandBase, implement all of the methods, and register it during FMLServerStartingEvent. Not much to it...
ex:
@SubscribeEvent<br> public void serverStartEvent(FMLServerStartingEvent event)<br> {<br> event.registerServerCommand(new CommandThatDoesSomething() );<br> }<br>I hate this forum editor now :/
EDIT2: I think you should actually use EventHandler and not SubscribeEvent...
Art by me: [email protected]
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumAll of the FML events that one would put in the main mod class use @Mod.EventHandler, NOT @SubscribeEvent - they are completely separate.
As for accessing your extended player properties, it's very simple once you have the EntityPlayer that you want, and is exactly the same as in all of the examples given in the tutorial:
In your CommandClass#process method, you get the player who sent the command like so:
After looking around a bit, it seems like what I should be using is this:
public ConnectionHandler(INetHandler thing, Class type, NetworkManager manager) {
super(thing, type, manager);
}
@SubscribeEvent
public void onEvent(ServerConnectionFromClientEvent event) {
}
}
However this is giving me an error at the line with super: "The constructor FMLNetworkEvent(T thing, Class<T> type, NetworkManager manager) is not visible"
Am I doing something wrong here?
EDIT: aaaand nevermind. Not sure why I was extending FMLNetworkEvent there.
public class ConnectionHandler {
@SubscribeEvent
public void onEvent(ServerConnectionFromClientEvent event) {
}
}
I don't see any way to get the player uuid from this, which I need to check if they can join. Is it there and I'm just not seeing it, or do I need to use a different event?
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumPlayerLoggedInEvent is not cancellable as far as I can tell. I'd like to prevent them from logging in at all if they aren't in the database. Is there anything else that works?
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumYou don't have to cancel it, you can kick them from the server directly.