Jump to content

Setting Variable Values When Using A Class That Extends IExtendEntityProperties


Recommended Posts

Posted

As the title states, I can't seem to do this. Either I am extremely tired and should try later, or I have just gone noob mode. I hope its the first option. And before you do start on the latter, I have getter/setter methods for the variables and they don't seem to work.

 

Therefore I am lost. Thanks for any help that may or may not come.

 

PlayerInformation class, the one that extends IExtendedEntityProperties:

package rpg.playerinfo;

import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.world.World;
import net.minecraftforge.common.IExtendedEntityProperties;

public final class PlayerInformation implements IExtendedEntityProperties {
    
public static final String IDENTIFIER = "minpg_playerinfo";

public static PlayerInformation forPlayer(Entity player) {
	return (PlayerInformation)player.getExtendedProperties(IDENTIFIER);
}

// called by the ASM hook in EntityPlayer.clonePlayer
public static void handlePlayerClone(EntityPlayer source, EntityPlayer target) {
	target.registerExtendedProperties(IDENTIFIER, source.getExtendedProperties(IDENTIFIER));
}

public static final int MAX_KARMA_VALUE = 99999999;

public boolean dirty = true;
public boolean hasClassBeenChosen = false;
public float karma = 0;
public byte[] eventAmounts = new byte[PlayerInformation.CountableKarmaEvent.values().length];
public String playersClass;
public int danris = 0;

private final EntityPlayer player;

public PlayerInformation(EntityPlayer player) {
	this.player = player;
}

@Override
public void init(Entity entity, World world) {
	// nothing for now
}

@Override
public void saveNBTData(NBTTagCompound nbtPlayer) {
	NBTTagCompound nbt = new NBTTagCompound();

	nbt.setString("playersClass", playersClass);
	nbt.setBoolean("hasClassBeenChosen", hasClassBeenChosen);
	nbt.setInteger("danris", danris);
	nbt.setFloat("karma", karma);

	NBTTagList eventList = new NBTTagList();
	for (int i = 0; i < eventAmounts.length; i++) {
		NBTTagCompound evtInfo = new NBTTagCompound();
		evtInfo.setByte("id", (byte)i);
		evtInfo.setByte("value", eventAmounts[i]);
		eventList.appendTag(evtInfo);
	}
	nbt.setTag("events", eventList);

	//nbtPlayer.setCompoundTag(IDENTIFIER, nbt);
	nbtPlayer.setCompoundTag(IDENTIFIER, player.getEntityData());
}

@Override
public void loadNBTData(NBTTagCompound playerNbt) {
	NBTTagCompound nbt = playerNbt.getCompoundTag(IDENTIFIER);

	playersClass = nbt.getString("playersClass");
	hasClassBeenChosen = nbt.getBoolean("hasClassBeenChosen");
	danris = nbt.getInteger("danris");
	karma = nbt.getFloat("karma");

	NBTTagList eventList = nbt.getTagList("events");
	for (int i = 0; i < eventList.tagCount(); i++) {
		NBTTagCompound evtInfo = (NBTTagCompound)eventList.tagAt(i);
		byte eventId = evtInfo.getByte("id");
		if (eventId >= 0 && eventId < eventAmounts.length) {
			eventAmounts[eventId] = evtInfo.getByte("value");
		}
	}
}

public boolean getHasClassBeenChosen() {
	return hasClassBeenChosen;
}

public boolean setHasClassBeenChosen(boolean hasClassBeenChosen) {
	if(this.hasClassBeenChosen != hasClassBeenChosen) {
		this.hasClassBeenChosen = hasClassBeenChosen;
		setDirty();
	}
	return this.hasClassBeenChosen;
}

public String getPlayersClass() {
	return playersClass;
}

public String setPlayersClass(String playersClass) {
	if(this.playersClass != playersClass) {
		this.playersClass = playersClass;
		setDirty();
	}

	return this.playersClass;
}

public String modifyPlayersClass(String classChangingTo) {
	return setPlayersClass(classChangingTo);
}

public float getKarma() {
	return karma;
}

public float setKarma(float karma) {
	if (this.karma != karma) {
		this.karma = karma;
		if (this.karma > MAX_KARMA_VALUE) {
			this.karma = MAX_KARMA_VALUE;
		}
		if (this.karma < -MAX_KARMA_VALUE) {
			this.karma = -MAX_KARMA_VALUE;
		}
		setDirty();
	}

	return this.karma;
}

public float modifyKarma(float modifier) {
	player.worldObj.playSoundAtEntity(player, "minepgkarma.karma" + (modifier < 0 ? "down" : "up"), 1, 1);

	return setKarma(karma + modifier);
}

public float modifyKarmaWithMax(float modifier, float max) {
	if (karma < max) {
		modifyKarma(modifier);
	}

	return karma;
}

public float modifyKarmaWithMin(float modifier, float min) {
	if (karma > min) {
		modifyKarma(modifier);
	}

	return karma;
}

public byte getEventAmount(CountableKarmaEvent event) {
	return eventAmounts[event.ordinal()];
}

public boolean setEventAmount(CountableKarmaEvent event, int amount) {
	if (amount < event.getMaxCount() && eventAmounts[event.ordinal()] != amount) {
		eventAmounts[event.ordinal()] = (byte)amount;
		setDirty();
		return true;
	} else {
		return false;
	}
}

public boolean increaseEventAmount(PlayerInformation.CountableKarmaEvent event) {
	return setEventAmount(event, eventAmounts[event.ordinal()] + 1);
}

public static enum CountableKarmaEvent {
	PIGMEN_ATTACK(1), CREATE_SNOWGOLEM(2), CREATE_IRONGOLEM(3);

	private final int maxCount;

	private CountableKarmaEvent(int maxCount) {
		this.maxCount = maxCount;
	}

	public int getMaxCount() {
		return maxCount;
	}
}

public int getCurrency() {
	return danris;
}

public int setCurrency(int danris) {
	if(this.danris != danris) {
		this.danris = danris;
		setDirty();
	}
	if(this.danris > 999999) {
		this.danris = 999999;
		setDirty();
	}
	return this.danris;
}

/**
 * marks that this needs to be resend to the client
 */
public void setDirty() {
	dirty = true;
}
}

-Mew

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

Posted
  On 5/10/2013 at 10:26 AM, diesieben07 said:

Define "do not work".

Please post some code.

(Without that I think you might have a client/server-sync problem).

 

sorry...

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

Posted

Never mind.. I am such an idiot. I was tired after all. Although now it seems to reset the data on re-entry to the world...

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

Posted
  On 5/11/2013 at 7:41 AM, diesieben07 said:

Are your readToNBT / writeToNBT methods writing the stuff that needs to be saved?

 

Yes they are. Check out the github repo at https://github.com/ModderPenguin/MinePG, it has all my code for my mod...

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

Posted

I don't just, "Copy and Paste". I actually build my own (even if it does look similar) and read through accesible files to find out what everything does. but it still doesn't really seem to help me.

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

Posted
  On 5/15/2013 at 9:35 AM, diesieben07 said:

I doubt that.

Examples:

1) CountableKarmaEvent: You don't even use that, do you?

2) PlayerInformation.handlePlayerClone: Read the comment on that method. Do you even know what ASM is?

3) MobSpawnerTransformer: 1 to 1 copy.

4) MinePGTransformer: 1 to 1 copy

5) Packet System: 1 to 1 copy

6) Sound System: copied and slightly changed

7) HudOverlayhandler: 1 to 1 copy

[nobbc]8)[/nobbc] Generic/KarmaEventHandler: 1 to 1 copy

9) MinePGUtil: 1 to 1 copy

 

You are totally not copying our code.

 

Yeah, but that won't be released. I am going to change it around. That was to just get me started. And yes, I'm pretty sure I use the Karma event. I have karma in the mod. I'm sorry if seem like I am copying your code, I am just using that as a base to then change and build of to fit my purposes.

 

I am not 100% percent sure what it is, but I am fairly certain it is to do with core mod transformers. Which is another topic I would like to learn about...

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

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

    • Short Term Loans Online: A Reliable Source of Fast Cash   If you are experiencing financial difficulties, you don't have to worry about this challenge. This is the quickest and best method for handling financial catastrophes. You can pick short term loans online without reluctance, and you can apply for the payday loan you want online and have it the same day without any issues. With two to four weeks to repay the loan, you may often borrow between $100 and $1000 without having to offer any collateral.   As implied by the title, those with bad credit histories—defaults, arrears, foreclosure, late or missed payments, judgments against you, insolvency or IVA, etc.—are welcome to apply for online short term loans without having to go through any challenging procedures. Interest rates are a bit high in comparison to other loans. A thorough internet search can be used to determine the greatest rate for a financed loan.   You don't have to waste your precious time searching the internet for short term funding payday loans. In just a few minutes, you can apply for the finance you desire by completing a brief online application. The lender will approve the loan once he has verified that you have provided accurate information on this brief form. This loan is carefully deposited into your bank account in the least amount of time. You can utilize the money in a number of ways without running into any problems. Usually, the money can be used to settle debts like credit card balances, overdue bank overdrafts, tuition or school fees for children, energy bills, housing costs, and more.   Loans Lucre makes it simple to apply for short term loans online, so there's no need to drive across town. Additionally, you won't have to wait weeks for a response from us. Additionally, having bad credit shouldn't be a deal-breaker. We evaluate your entire financial history rather than just your FICO score. We approve many debtors who had been rejected by banks.   Once you are approved, Loans Lucre puts your online installment loans directly into your bank account, giving you instant access to your funds. The repayment plan is broken down into simple, reasonably priced monthly installments. Loans Lucre also rejects rollovers. Instead, we help borrowers get back on track when they encounter difficulties with the repayment process. Borrowers who regularly make their payments on time are eligible for lower annual percentage rates (APRs) on their subsequent these loans. That is truly win-win!   You will be communicating with the lender whether you apply for online personal loans through a cash advance broker or directly from the lender. The cost and duration of the transaction will be increased by any third parties you deal with through the direct lender. This will lead to a faulty perception of the "instant approval" of your payday loan, in addition to raising the cost of your transaction. When asking for a payday loan, it is therefore essential that you work with a trustworthy direct lender; a lender with a solid online reputation and satisfied clients is a wise choice.   You can apply for a short term loans online through internet platforms in addition to conventional lenders. A quicker and more convenient application process is frequently provided by these platforms. In the end, it is feasible to get a $500 loan with low credit or no credit at all, but it will need effort and careful evaluation of your financial possibilities. The lender's requirements will always determine approval, so be careful to give accurate information and look into several lenders to determine which one best suit your needs. https://loanslucre.com/  
    • Apply For Fast Cash Loans Online Today To Get Money Right Away   Do you have to deal with your money issues right away? You don't need to go anywhere because you can get fast cash loans online with just a computer and an internet connection. This suggests that you don't need to waste any time applying for these loans. All you have to do is fill out the form accurately and submit it to the lender online. They will check it and determine whether to approve the loan within the specified time frame. The money is moved to your bank account shortly after approval.   The same-day financing loan facility offers the most beneficial cash assistance in quantities ranging from $100 to $1000, with a flexible payback period of 2-4 weeks from the date of acceptance. You can use the borrowed funds to cover your child's tuition or school fees, small vacation expenses, past credit card payments, laundry costs, minor house repairs, your mother's checkups, and other emergencies.   To be qualified for same day funding loans, you must meet specific conditions regardless of your credit score—fair or low. A valid proof of domicile and proof of residence for the last 12 months, a current bank account with an SSN, being employed permanently with a monthly wage of at least $1000, and being at least eighteen years of age are prerequisites. If you satisfy the qualifications, you can apply for same-day payday loans directly without undergoing a credit check if you have bankruptcy, CCJs, IVAs, foreclosure, arrears, or defaults. As a result, getting a loan is fairly easy in the current credit market.   You must complete an application with information about your bank account and job in order to apply for a fast cash loan online from a physical payday lender. You also need to provide the lender with postdated checks that will be deposited on the scheduled repayment date. In return, you get paid right away.   Applicants can apply for same day payday loans at any time, from the comfort of their homes, eliminating the need to travel across town to a payday loan outlet. However, online payday lenders do not frequently provide same-day loans. Instead, payouts are made straight into borrowers' bank accounts via the Automated Clearing House (ACH) system; processing for this method takes at least one business day.   You must think about if you can pay back the loan in full within the allotted time because same day payday loans may have payback periods as little as one week or ten days. If you are unable to pay the full amount due, the lender might accept a token payment from you. The remaining sum will be restructured as a rollover, which is a new loan with fresh interest and administrative costs and the same short payback period. After a few rollovers, a significant number of little payday loans accumulate to the point that debtors still owe more than they originally borrowed, even after making consistent payments for months or years.   You should be ready to submit the required paperwork and supporting proof when applying for a payday loans online same day with bad credit. Usually, lenders will evaluate your present financial state, work status, and loan-repayment capacity. Many lenders specialize in bad credit loans and are willing to take on the risk of lending to those with poor credit, despite the difficulties presented by a low credit score. This implies that you are not automatically denied a loan because of poor credit or no credit at all. https://nuevacash.com/
    • I have removed stevekunglib and it is still crashing again https://pastebin.com/9vE8pji0
    • It looks like an issue with stevekunglib or a mod requiring it
  • Topics

×
×
  • Create New...

Important Information

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