Posted June 13, 201411 yr im trying to have a variable that goes down every x ticks and is stored as nbt in the player. what is the proper function for this. (i read somewhere that it was onUpdate() but it must have been outdated) and how in the world do i set up a tick handler? here is my code: package com.sigurd4.Bioshock.entity; 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 class ExtendedPlayer implements IExtendedEntityProperties { public static final int EVE_WATCHER = 23; public static final int DRUNKNESS_WATCHER = 24; public int eveMax; public final static String EXT_PROP_NAME = "BioshockPlayer"; public final static String PLASMIDS_NAME = "plasmids"; public final static String TONICS_NAME = "tonics"; private final EntityPlayer player; private boolean plasmidsOldManWinter; private boolean plasmidsPeepingTom; private boolean plasmidsBuckingBronco; private boolean plasmidsCharge; private boolean plasmidsDevilsKiss; private boolean plasmidsIronsides; private boolean plasmidsMurderOfCrows; private boolean plasmidsPossession; private boolean plasmidsReturnToSender; private boolean plasmidsShockJockey; private boolean plasmidsUndertow; public ExtendedPlayer(EntityPlayer player) { this.player = player; this.eveMax = 200; this.setCurrentEve(this.eveMax); this.setDrunkness(0); } public void onUpdate() //this doesnt work!! { setDrunkness(getDrunkness()-1); System.out.println(getDrunkness()); } /** * Returns ExtendedPlayer properties for player * This method is for convenience only; it will make your code look nicer */ public static final ExtendedPlayer get(EntityPlayer player) { return (ExtendedPlayer) player.getExtendedProperties(EXT_PROP_NAME); } /** * Used to register these extended properties for the player during EntityConstructing event * This method is for convenience only; it makes my code look nicer. */ public static final void register(EntityPlayer player) { player.registerExtendedProperties(ExtendedPlayer.EXT_PROP_NAME, new ExtendedPlayer(player)); } @Override public void init(Entity arg0, World arg1) { } @Override public void loadNBTData(NBTTagCompound compound) { NBTTagCompound properties = (NBTTagCompound) compound.getTag(EXT_PROP_NAME); NBTTagCompound plasmids = (NBTTagCompound) properties.getTag(PLASMIDS_NAME); //NBTTagList tonics = (NBTTagList) properties.getTag(TONICS_NAME); this.player.getDataWatcher().updateObject(EVE_WATCHER, properties.getInteger("Eve")); this.player.getDataWatcher().updateObject(DRUNKNESS_WATCHER, properties.getInteger("Drunkness")); this.eveMax = properties.getInteger("EveMax"); this.plasmidsOldManWinter = plasmids.getBoolean("oldManWinter"); this.plasmidsPeepingTom = plasmids.getBoolean("peepingTom"); this.plasmidsBuckingBronco = plasmids.getBoolean("buckingBronco"); this.plasmidsCharge = plasmids.getBoolean("charge"); this.plasmidsDevilsKiss = plasmids.getBoolean("devilsKiss"); this.plasmidsIronsides = plasmids.getBoolean("ironsides"); this.plasmidsMurderOfCrows = plasmids.getBoolean("murderOfCrows"); this.plasmidsPossession = plasmids.getBoolean("possession"); this.plasmidsReturnToSender = plasmids.getBoolean("returnToSender"); this.plasmidsShockJockey = plasmids.getBoolean("shockJockey"); this.plasmidsUndertow = plasmids.getBoolean("undertow"); } @Override public void saveNBTData(NBTTagCompound compound) { NBTTagCompound properties = new NBTTagCompound(); NBTTagCompound plasmids = new NBTTagCompound(); NBTTagList tonics = new NBTTagList(); compound.setTag(EXT_PROP_NAME, properties); properties.setTag(PLASMIDS_NAME, plasmids); properties.setTag(TONICS_NAME, tonics); properties.setInteger("Eve", this.player.getDataWatcher().getWatchableObjectInt(EVE_WATCHER)); properties.setInteger("Drunkness", this.player.getDataWatcher().getWatchableObjectInt(DRUNKNESS_WATCHER)); properties.setInteger("EveMax", this.eveMax); plasmids.setBoolean("oldManWinter", this.plasmidsOldManWinter); plasmids.setBoolean("peepingTom", this.plasmidsPeepingTom); plasmids.setBoolean("buckingBronco", this.plasmidsBuckingBronco); plasmids.setBoolean("charge", this.plasmidsCharge); plasmids.setBoolean("devilsKiss", this.plasmidsDevilsKiss); plasmids.setBoolean("ironsides", this.plasmidsIronsides); plasmids.setBoolean("murderOfCrows", this.plasmidsMurderOfCrows); plasmids.setBoolean("possession", this.plasmidsPossession); plasmids.setBoolean("returnToSender", this.plasmidsReturnToSender); plasmids.setBoolean("shockJockey", this.plasmidsShockJockey); plasmids.setBoolean("undertow", this.plasmidsUndertow); } public final boolean consumeEve(int amount) { int eve = this.player.getDataWatcher().getWatchableObjectInt(EVE_WATCHER); boolean sufficient = amount <= eve; eve -= (amount < eve ? amount : eve); this.player.getDataWatcher().updateObject(EVE_WATCHER, eve); return sufficient; } public final int getMaxEve() { return eveMax; } public final int getCurrentEve() { return this.player.getDataWatcher().getWatchableObjectInt(EVE_WATCHER); } public final int getDrunkness() { return this.player.getDataWatcher().getWatchableObjectInt(DRUNKNESS_WATCHER); } public final void setCurrentEve(int amount) { this.player.getDataWatcher().updateObject(EVE_WATCHER, (amount < this.eveMax ? amount : this.eveMax)); } public final void setDrunkness(int amount) { this.player.getDataWatcher().updateObject(DRUNKNESS_WATCHER, amount); } public boolean hasPlasmid(String i) { boolean b = false; if(i=="oldManWinter"){b=this.plasmidsOldManWinter;} if(i=="peepingTom"){b=this.plasmidsPeepingTom;} if(i=="buckingBronco"){b=this.plasmidsBuckingBronco;} if(i=="charge"){b=this.plasmidsCharge;} if(i=="devilsKiss"){b=this.plasmidsDevilsKiss;} if(i=="ironsides"){b=this.plasmidsIronsides;} if(i=="murderOfCrows"){b=this.plasmidsMurderOfCrows;} if(i=="possession"){b=this.plasmidsPossession;} if(i=="returnToSender"){b=this.plasmidsReturnToSender;} if(i=="shockJockey"){b=this.plasmidsShockJockey;} if(i=="undertow"){b=this.plasmidsUndertow;} return b; } public void givePlasmid(String i, boolean b) { if(i=="oldManWinter"){b=this.plasmidsOldManWinter;} if(i=="peepingTom"){b=this.plasmidsPeepingTom;} if(i=="buckingBronco"){this.plasmidsBuckingBronco=b;} if(i=="charge"){this.plasmidsCharge=b;} if(i=="devilsKiss"){this.plasmidsDevilsKiss=b;} if(i=="ironsides"){this.plasmidsIronsides=b;} if(i=="murderOfCrows"){this.plasmidsMurderOfCrows=b;} if(i=="possession"){this.plasmidsPossession=b;} if(i=="returnToSender"){this.plasmidsReturnToSender=b;} if(i=="shockJockey"){this.plasmidsShockJockey=b;} if(i=="undertow"){this.plasmidsUndertow=b;} } } i dont know what to do and its hard to find any tutorials that are up to date. http://www.planetminecraft.com/member/sigurd4 I'm making the bioshock mod!
June 13, 201411 yr how in the world do i set up a tick handler? ... i dont know what to do and its hard to find any tutorials that are up to date. I've just drafted a tutorial on 1.7.2 event handling. There is a lot of information there, but it should explain the concepts, how to register handlers, and list of various available events. As diesieben07 advises, there is PlayerTickHandler (on FML event bus) available. Just create a counter there that you can test to see that so many ticks have gone by and you can use event.player to find the player and then you can call his NBT handling methods. Check out my tutorials here: http://jabelarminecraft.blogspot.com/
June 14, 201411 yr Author took a look at your tutorial, and it is pretty good, but there is one thing that i cant find there and makes me confused and that is where am i supposed to put this code? could you give me an example? http://www.planetminecraft.com/member/sigurd4 I'm making the bioshock mod!
June 14, 201411 yr Okay, I'm still planning to augment the tutorials with full github examples, although I did put a lot of instruction into the tutorial. I'll see if I can make a clearer summary though because I guess I do have a lot of information there. The basic idea is: 1) Create an event handling class, call it whatever you want. I give an example of such a class in the tutorial. 2) Put a method in it that follows the example in my tutorial. In needs to have the @SubscribeEvent annotation and the parameter must be the type of event you're trying to handle (I put lists of pretty much all known events in the tutorial). That method should do whatever you want when the event happens. 3) register the handling class to the event bus. This is done in your main class (or CommonProxy) in the init() method. I give examples of registering the class to the bus in my tutorial. That's pretty much it. Check out my tutorials here: http://jabelarminecraft.blogspot.com/
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.