Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

starwarsmace

Members
  • Joined

  • Last visited

Everything posted by starwarsmace

  1. Welll actually I am sure that everything is being saved and read. Because when my friend put the code. Even though static is a bad way of doing things it saved it and loaded the numbers fine. And there was no syncing being changed there. So it must be my variable is not initialized or something?
  2. It is not. My friend is using that for some reason. But the way I was trying to do it, why isnt that working.
  3. This might be it. player.distanceWalkedModified/0.6 The reason for the 0.6 being divided is because it says distanceWalkedModified and is modified by it being multiplied by 0.6. So I just revert it to the original thing.
  4. This tutorial should help. http://www.minecraftforum.net/forums/mapping-and-modding/mapping-and-modding-tutorials/1571589-modding-animation-guide
  5. To save the players data after death and after reloging into the world. Its seems like it has something to do when I initalize the variable.
  6. Ok I went and saw what it is. And that is totally not what we want. So how can we do it so that variales not static?
  7. Getters and setters would be better right? <---- I dont know why I said that. And also how does the EntityGoldMine.goldmath work. Doesnt it make a new object and then take goldmath (which is 0 because its a new object) and then deletes the object. Or does it not work like that?
  8. Well I have just got some code from a friend. And it works but I have NO idea how. EntityGoldMine public class EntityGoldMine extends EntityLiving{ public int level; public int effeciancy; public int capacity; public static int full; public int tick; public boolean isUpgrading; public static int goldMath; public String name; public EntityGoldMine(World p_i1582_1_) { super(p_i1582_1_); } public void setOwnerName(String par1){ this.name=par1; } public void entityInit(){ this.effeciancy=1; this.level=1; this.capacity=500; this.full=0; this.tick=0; this.isUpgrading=false; super.entityInit(); } protected void applyEntityAttributes() { super.applyEntityAttributes(); this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(30.0D); } public boolean canDespawn(){ return false; } public void writeEntityToNBT(NBTTagCompound tag) { super.writeEntityToNBT(tag); tag.setInteger("Level", this.level); tag.setInteger("Effeciany", this.effeciancy); tag.setInteger("Capacity", this.capacity); tag.setInteger("Full",this.full); tag.setString("Owner", this.name); } public void readEntityFromNBT(NBTTagCompound tag) { super.readEntityFromNBT(tag); this.level=tag.getInteger("Level"); this.effeciancy=tag.getInteger("Effeciany"); this.capacity=tag.getInteger("Capacity"); this.full=tag.getInteger("Full"); this.name=tag.getString("Owner"); } public void onEntityUpdate(){ switch(level){ case 1:this.capacity=500; this.effeciancy=1; break; case 2:this.capacity=1000; this.effeciancy=3; } if(this.worldObj.isRemote==true){ if(this.full<this.capacity){ if(this.isUpgrading==false){ tick++; } if(tick==20){ this.full++; this.tick=0; } } } super.onEntityUpdate(); } public void collect(EntityPlayer par1){ EntityPlayer player=par1; ExtendedPlayer data=ExtendedPlayer.get(player); data.changeResources(1, this.full); System.out.println("The button has been pressed!"); this.goldMath = goldMath + full; this.full=0; } protected boolean interact(EntityPlayer player) { player.openGui(ClashOfCraft.instance, 20, player.worldObj, (int)this.getEntityId(), (int)player.posY,(int) player.posZ); return true; } ExtendedPlayer And this is the part I find wierd in here he says { this.player = player; this.elixer=0; this.gold=EntityGoldMine.goldMath; this.gold_storage=0; this.elixer_storage=0; } How the heck does EntityGoldMine.goldMath work????? Doesnt that make a new object and take it from there. But somehow it works Anyone know how.
  9. Hello guys. Well I found something out. I call my init everytime the class is called. And I say in my init that the variable is equel to 0. Is there a way to call the gold=0 only the first time the player enters the world and then later keep it as is?
  10. I added some gold to my extended properties and I saw the change. And then I exited the world and then came back on and it was gone. To check this I was using a gui could it be I didn't sync it when I reloged. Ill go check with the console and see if that changes anything. Nope it wasnt a syncing problem the console didn't show it saved either.
  11. I added some gold to my extended properties and I saw the change. And then I exited the world and then came back on and it was gone. To check this I was using a gui could it be I didn't sync it when I reloged. Ill go check with the console and see if that changes anything.
  12. That's what he already asked you to do... no one can help you if you don't show your code. Sorry. @SubscribeEvent public void onEntityConstructing(EntityConstructing event){ if (event.entity instanceof EntityPlayer && ExtendedPlayer.get((EntityPlayer) event.entity) == null){ ExtendedPlayer.register((EntityPlayer) event.entity); } } @SubscribeEvent public void onLivingDeathEvent(LivingDeathEvent event){ } // we already have this event, but we need to modify it some @SubscribeEvent public void onEntityJoinWorld(EntityJoinWorldEvent event){ } @SubscribeEvent public void onClone(PlayerEvent.Clone event) { NBTTagCompound temp = new NBTTagCompound(); event.original.getExtendedProperties(ExtendedPlayer.EXT_PROP_NAME).saveNBTData(temp); event.entityPlayer.getExtendedProperties(ExtendedPlayer.EXT_PROP_NAME).loadNBTData(temp); ExtendedPlayer.sync(event.entityPlayer); } }
  13. No it does not save when I exit the world and rejoin. I can show the event handler if you want again.
  14. There is a network registry.
  15. Here ublic class ExtendedPlayer implements IExtendedEntityProperties { public final static String EXT_PROP_NAME = "ExtendedPlayer"; private final EntityPlayer player; private int gold; private int elixer; private int gold_storage; private int elixer_storage; private boolean flag; public ExtendedPlayer(EntityPlayer player) { this.player = player; this.elixer=0; this.gold=0; this.gold_storage=0; this.elixer_storage=0; this.flag=false; } @Override public void init(Entity entity, World world) { } @Override public void saveNBTData(NBTTagCompound properties) { NBTTagCompound compound = new NBTTagCompound(); compound.setInteger("Elixer",this.elixer); compound.setInteger("Gold", this.gold); compound.setInteger("Gold_Storage", this.gold_storage); compound.setInteger("Elixer_Storage", this.elixer_storage); compound.setBoolean("Flag", this.flag); properties.setTag(EXT_PROP_NAME, compound); } @Override public void loadNBTData(NBTTagCompound properties) { NBTTagCompound compound = (NBTTagCompound) properties.getCompoundTag(EXT_PROP_NAME); this.gold=compound.getInteger("Gold"); this.elixer=compound.getInteger("Elixer"); this.gold_storage=compound.getInteger("Gold_Storage"); this.elixer_storage=compound.getInteger("Elixer_Storage"); this.flag=compound.getBoolean("Flag"); } public static final void register(EntityPlayer player) { player.registerExtendedProperties(ExtendedPlayer.EXT_PROP_NAME, new ExtendedPlayer(player)); } public static final ExtendedPlayer get(EntityPlayer player) { return (ExtendedPlayer) player.getExtendedProperties(EXT_PROP_NAME); } public void changeResources(int id,int change){ if (id==0){ this.elixer=elixer+change; } if(id==1){ this.gold=gold+change; } } public void changeStorage(int id,int change){ if (id==0){ this.elixer_storage=change; } if(id==1){ this.gold_storage=change; } } public int getResources(int id){ int resource = 0; if (id==0){ resource=this.elixer; } if(id==1){ resource=this.gold; } return resource; } public int getStorage(int id){ int resource=0; if (id==0){ resource=this.elixer_storage; } if(id==1){ resource=this.gold_storage; } return resource; } public void changeFlag(boolean par1){ this.flag=par1; } public boolean getFlag(){ return this.flag; } public static void sync(EntityPlayer player) { ClashOfCraft.packetPipeline.sendTo(new SyncPlayerPropsPacket(player), (EntityPlayerMP) player); } }
  16. That is because it being on called on the client side and the server side. You have to check if it is on the client side with if(world.isRemote).
  17. Oh.................... Oops. Well I tried this. And it still didn't work when I killed myself.
  18. But didn't I use a load function in which I get the compund tag which I set back in my save function?
  19. Wait in this : public void saveNBTData(NBTTagCompound properties) { NBTTagCompound compound = new NBTTagCompound(); compound.setInteger("Elixer",this.elixer); compound.setInteger("Gold", this.gold); compound.setInteger("Gold_Storage", this.gold_storage); compound.setInteger("Elixer_Storage", this.elixer_storage); compound.setBoolean("Flag", this.flag); compound.setTag(EXT_PROP_NAME, compound); } I save it to the compound I make. And properties is just a parameter name right?
  20. Not sure what you mean. Can you explain more? Thanks.
  21. a)Youre right. b) oh yeah. That make sense. Corrected code public void onUpdate(ItemStack p_77663_1_, World world, Entity entity, int p_77663_4_, boolean flag) { if(flag){ world.spawnParticle("portal", entity.posX + 1, entity.posY, entity.posZ, 1.0D, 1.0D, 1.0D); } }
  22. Extended Player: public class ExtendedPlayer implements IExtendedEntityProperties { public final static String EXT_PROP_NAME = "ExtendedPlayer"; private final EntityPlayer player; private int gold; private int elixer; private int gold_storage; private int elixer_storage; private boolean flag; public ExtendedPlayer(EntityPlayer player) { this.player = player; this.elixer=0; this.gold=0; this.gold_storage=0; this.elixer_storage=0; this.flag=false; } @Override public void init(Entity entity, World world) { } @Override public void saveNBTData(NBTTagCompound properties) { NBTTagCompound compound = new NBTTagCompound(); compound.setInteger("Elixer",this.elixer); compound.setInteger("Gold", this.gold); compound.setInteger("Gold_Storage", this.gold_storage); compound.setInteger("Elixer_Storage", this.elixer_storage); compound.setBoolean("Flag", this.flag); compound.setTag(EXT_PROP_NAME, compound); } @Override public void loadNBTData(NBTTagCompound properties) { NBTTagCompound compound = (NBTTagCompound) properties.getCompoundTag(EXT_PROP_NAME); this.gold=compound.getInteger("Gold"); this.elixer=compound.getInteger("Elixer"); this.gold_storage=compound.getInteger("Gold_Storage"); this.elixer_storage=compound.getInteger("Elixer_Storage"); this.flag=compound.getBoolean("Flag"); } public static final void register(EntityPlayer player) { player.registerExtendedProperties(ExtendedPlayer.EXT_PROP_NAME, new ExtendedPlayer(player)); } public static final ExtendedPlayer get(EntityPlayer player) { return (ExtendedPlayer) player.getExtendedProperties(EXT_PROP_NAME); } public void changeResources(int id,int change){ if (id==0){ this.elixer=elixer+change; } if(id==1){ this.gold=gold+change; } } public void changeStorage(int id,int change){ if (id==0){ this.elixer_storage=change; } if(id==1){ this.gold_storage=change; } } public int getResources(int id){ int resource = 0; if (id==0){ resource=this.elixer; } if(id==1){ resource=this.gold; } return resource; } public int getStorage(int id){ int resource=0; if (id==0){ resource=this.elixer_storage; } if(id==1){ resource=this.gold_storage; } return resource; } public void changeFlag(boolean par1){ this.flag=par1; } public boolean getFlag(){ return this.flag; } public static void sync(EntityPlayer player) { ClashOfCraft.packetPipeline.sendTo(new SyncPlayerPropsPacket(player), (EntityPlayerMP) player); } } Event Handler: public class RegularEventHandler { // public boolean collect; // public EntityPlayer player; @SubscribeEvent public void onEntityConstructing(EntityConstructing event){ if (event.entity instanceof EntityPlayer && ExtendedPlayer.get((EntityPlayer) event.entity) == null){ ExtendedPlayer.register((EntityPlayer) event.entity); } } @SubscribeEvent public void onLivingDeathEvent(LivingDeathEvent event){ } // we already have this event, but we need to modify it some @SubscribeEvent public void onEntityJoinWorld(EntityJoinWorldEvent event){ } @SubscribeEvent public void onClone(PlayerEvent.Clone event) { NBTTagCompound temp = new NBTTagCompound(); event.original.getExtendedProperties(ExtendedPlayer.EXT_PROP_NAME).saveNBTData(temp); event.entityPlayer.getExtendedProperties(ExtendedPlayer.EXT_PROP_NAME).loadNBTData(temp); ExtendedPlayer.sync(event.entityPlayer); } }

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.