Jump to content

Recommended Posts

Posted

My NBTTagCompound isn't working with SMP. It will edit everyone's properties.

Also the player chat message only sends to the last person to log in.

 

Attatching my mod project files to use for reference. It's a lot of code to post on here and would be better understood if ran on server and opened with eclipse.

 

^ Not letting me upload [ Can't access upload files ], any other place to upload? If not here is the extended property file:

 

package com.MyOwnHarem.mod.mmoworld.properties.stats;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;

import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.packet.Packet250CustomPayload;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.world.World;
import net.minecraftforge.common.IExtendedEntityProperties;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.network.PacketDispatcher;
import cpw.mods.fml.common.network.Player;

public class MiningStatProperty implements IExtendedEntityProperties {
public static final String EXT_PROP_NAME = "MiningStat";

private static EntityPlayer player;

private static int miningXP;

public MiningStatProperty(EntityPlayer player) {
	this.player = player;
	this.miningXP = 0;
}

public static final void register(EntityPlayer player) {
	player.registerExtendedProperties(EXT_PROP_NAME, new MiningStatProperty(player));
}

public void addMiningXP(int amount) {
	this.miningXP += amount;

	player.addChatMessage(EnumChatFormatting.GREEN + "You have gained " + amount + " of XP for Mining!");
	player.addChatMessage(EnumChatFormatting.DARK_GREEN + "You now have " + this.miningXP + " of XP in Mining");

	this.sync();
}

public static final MiningStatProperty get(EntityPlayer player) {
	return (MiningStatProperty) player.getExtendedProperties(EXT_PROP_NAME);
}

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

	properties.setInteger("MiningXP", this.miningXP);

	compound.setTag(EXT_PROP_NAME, properties);
}

@Override
public void loadNBTData(NBTTagCompound compound) {
	NBTTagCompound properties = (NBTTagCompound) compound.getTag(EXT_PROP_NAME);

	this.miningXP = properties.getInteger("MiningXP");
}

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

}

public void sync() {
	ByteArrayOutputStream bos = new ByteArrayOutputStream(;
	DataOutputStream outputStream = new DataOutputStream(bos);

	try {
		outputStream.writeInt(this.miningXP);
	} catch (Exception e) {
		e.printStackTrace();
		return;
	}

	Packet250CustomPayload packet = new Packet250CustomPayload("mmoworld", bos.toByteArray());

	if (FMLCommonHandler.instance().getEffectiveSide().isServer()) {
		// EntityPlayerMP playerMP = (EntityPlayerMP) player; 
		// PacketDispatcher.sendPacketToPlayer(packet, (Player) player1);
		// [ Gives ClassCastException: net.minecraft.client.entity.EntityClientPlayerMP cannot be cast to net.minecraft.entity.player.EntityPlayerMP ]



		PacketDispatcher.sendPacketToPlayer(packet, (Player) player);
	}
}
}

 

Posted

Mmmmm~  Static properties. <3

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Mmmmm~  Static properties. <3

 

Obviously sarcasm, and obviously a solution/alternative way of doing this. Care to inform or "Support" instead of that sarcasm that doesn't really help anyone. I'm trying to learn, Don't bring me up to your level.

Posted

You have static properties.

private static EntityPlayer player;
private static int miningXP;

 

If you don't know why I'm telling you this, you don't have a basic grasp of Java (or any programming language, to be blunt) and that is a base requirement of getting help on this board:

 

Modder Support

 

This is the support section for those modding with Forge. Help with modding goes in here, however, please keep in mind that this is not a Java school. You are expected to have basic knowledge of Java before posting here.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

I do know java, quite well actually and I do know what static means and why youd say that. The issue wasnt that I didnt know, the issue was the rude reply, true better than none, but could have been done nicer without sarcasm.

 

Btw, from what I do know of java, static is only 1 instance or things like variables and methods can be used without instantiating.

 

And thank you for replying again even though I myself was a little rude as well.

Posted

The reason I get a little sarcastic is because people using static for inherently not-static purposes has happened four times in the last two days and several more times in the past.  90% of the time people don't understand what I mean when I say "why are you using static here?" because they don't know what they're doing.

 

And rather than try and supply copy-paste solutions, I'm forcing people to think.  Doing so means they learn things, even if it makes me look like an asshole.

 

It also means I don't have to do as much work to get a better result.

 

And I'm all about efficiency.  And I don't care what people think about me.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Well I do appreciate your help. I dont ask for code, but I honestly thought you were talking about the register and get methods being static, never even noticed the variables were static. And because you helped point it out, I noticed and that wws the solution. Thank you for all your help! =o)

Posted

Well I do appreciate your help. I dont ask for code, but I honestly thought you were talking about the register and get methods being static, never even noticed the variables were static. And because you helped point it out, I noticed and that wws the solution. Thank you for all your help! =o)

 

Hence "static properties" not "static methods" and quoting the two in question. :)

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

The whole class is a custom property, and the register method is the only new initialization of it. So I thought thats what you meant by static properties, and ive never heard anyone call variables properties. But now that this is solved I shall lock it cause it's just spam now.

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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