Lambda Posted December 11, 2016 Posted December 11, 2016 Hey there, So I have an Item here that need to set a string in a TE ,the string will check if the bounded player is the same, and do x if it is. However, I'm having an issue with finding a way of accessing something that differentiates a player. Thanks, Quote Relatively new to modding. Currently developing: https://github.com/LambdaXV/DynamicGenerators
larsgerrits Posted December 11, 2016 Posted December 11, 2016 Best thing is to store the UUID of the player. You can get the UUID from a player using Entity#getUniqueID() . To save it to NBT, save the getLeastSignificantBits() and getMostSignificantBits result ( longs ). To recreate the UUID , use the constructor that accepts 2 longs (the most and least significant bits) which you saved to NBT. Quote Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support. 1.12 -> 1.13 primer by williewillus. 1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support. http://www.howoldisminecraft1710.today/
Lambda Posted December 11, 2016 Author Posted December 11, 2016 Okay, so like this: public long leastbit; public long mostbit; public UUID uuid = new UUID(leastbit, mostbit); @Override public void writeSyncableNBT(NBTTagCompound compound, NBTType type) { if(type != NBTType.SAVE_BLOCK) { compound.setLong("UUID.LEASTBIT", uuid.getLeastSignificantBits()); compound.setLong("UUID.MOSTBIT", uuid.getMostSignificantBits()); } super.writeSyncableNBT(compound, type); } @Override public void readSyncableNBT(NBTTagCompound compound, NBTType type) { if(type != NBTType.SAVE_BLOCK) { leastbit = compound.getLong("UUID.LEASTBIT"); mostbit = compound.getLong("UUID.MOSTBIT"); } super.readSyncableNBT(compound, type); } Quote Relatively new to modding. Currently developing: https://github.com/LambdaXV/DynamicGenerators
Lambda Posted December 11, 2016 Author Posted December 11, 2016 @Override public void readSyncableNBT(NBTTagCompound compound, NBTType type) { if(type != NBTType.SAVE_BLOCK) { uuid = new UUID(compound.getLong("UUID.LEASTBIT"), compound.getLong("UUID.MOSTBIT")); } super.readSyncableNBT(compound, type); } Quote Relatively new to modding. Currently developing: https://github.com/LambdaXV/DynamicGenerators
Lambda Posted December 11, 2016 Author Posted December 11, 2016 Ah, changed that, test works, but doesnt save, so something is wrong with my NBT still: public class TileEntityChargeStand extends TileEntityCrystalSearchBase { public final int MANA_PER_TICK = 50; public UUID uuid; public TileEntityChargeStand() { super("chargeStand"); } @Override public void updateEntity() { super.updateEntity(); if(!worldObj.isRemote) { EntityPlayer player = worldObj.getClosestPlayer(pos.getX(), pos.getY() + 1, pos.getZ(), 1, false); if (player != null) { if (player.getUniqueID() == uuid && uuid != null) { if (player.hasCapability(CapabilityMagic.MANA, null)) { if (storage.getManaStored() >= 0) { CapabilityManaData cap = player.getCapability(CapabilityMagic.MANA, null); cap.receiveManaInternal(MANA_PER_TICK, false); this.storage.extractMana(MANA_PER_TICK, false); } } } } } } @Override public void writeSyncableNBT(NBTTagCompound compound, NBTType type) { if(type != NBTType.SAVE_BLOCK) { compound.setUniqueId("ChargeUUID", uuid); } super.writeSyncableNBT(compound, type); } @Override public void readSyncableNBT(NBTTagCompound compound, NBTType type) { if(type != NBTType.SAVE_BLOCK) { uuid = compound.getUniqueId("ChargeUUID"); } super.readSyncableNBT(compound, type); } } Thanks. Quote Relatively new to modding. Currently developing: https://github.com/LambdaXV/DynamicGenerators
Lambda Posted December 11, 2016 Author Posted December 11, 2016 Ah didn't catch that. It saves though relog but not though restart. Quote Relatively new to modding. Currently developing: https://github.com/LambdaXV/DynamicGenerators
Recommended Posts
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.