2018-02-15 18:49:01 -08:00
|
|
|
package WayofTime.bloodmagic.util.helper;
|
2015-10-29 20:22:14 -07:00
|
|
|
|
2018-02-27 16:59:51 -08:00
|
|
|
import WayofTime.bloodmagic.core.data.Binding;
|
2018-02-15 18:49:01 -08:00
|
|
|
import WayofTime.bloodmagic.util.Constants;
|
|
|
|
import WayofTime.bloodmagic.event.ItemBindEvent;
|
2015-10-29 20:22:14 -07:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2018-02-27 16:59:51 -08:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2015-12-28 20:13:11 -08:00
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
public class BindableHelper {
|
2018-02-27 16:59:51 -08:00
|
|
|
|
|
|
|
public static void applyBinding(ItemStack stack, EntityPlayer player) {
|
|
|
|
Binding binding = new Binding(player.getGameProfile().getId(), player.getGameProfile().getName());
|
|
|
|
applyBinding(stack, binding);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void applyBinding(ItemStack stack, Binding binding) {
|
|
|
|
if (!stack.hasTagCompound())
|
|
|
|
stack.setTagCompound(new NBTTagCompound());
|
|
|
|
|
|
|
|
stack.getTagCompound().setTag("binding", binding.serializeNBT());
|
|
|
|
}
|
|
|
|
|
2015-10-29 20:22:14 -07:00
|
|
|
/**
|
2016-03-16 18:41:06 -04:00
|
|
|
* Sets the Owner Name of the item without checking if it is already bound.
|
|
|
|
* Also bypasses {@link ItemBindEvent}.
|
2017-08-15 21:30:48 -07:00
|
|
|
*
|
|
|
|
* @param stack - The ItemStack to bind
|
|
|
|
* @param ownerName - The username to bind the ItemStack to
|
2016-02-03 23:14:26 -08:00
|
|
|
*/
|
2017-08-15 21:30:48 -07:00
|
|
|
public static void setItemOwnerName(ItemStack stack, String ownerName) {
|
2016-02-03 23:14:26 -08:00
|
|
|
stack = NBTHelper.checkNBT(stack);
|
|
|
|
|
|
|
|
stack.getTagCompound().setString(Constants.NBT.OWNER_NAME, ownerName);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-03-16 18:41:06 -04:00
|
|
|
* Sets the Owner UUID of the item without checking if it is already bound.
|
|
|
|
* Also bypasses {@link ItemBindEvent}.
|
2017-08-15 21:30:48 -07:00
|
|
|
*
|
|
|
|
* @param stack - The ItemStack to bind
|
|
|
|
* @param ownerUUID - The UUID to bind the ItemStack to
|
2016-02-03 23:14:26 -08:00
|
|
|
*/
|
2017-08-15 21:30:48 -07:00
|
|
|
public static void setItemOwnerUUID(ItemStack stack, String ownerUUID) {
|
2016-02-03 23:14:26 -08:00
|
|
|
stack = NBTHelper.checkNBT(stack);
|
|
|
|
|
|
|
|
stack.getTagCompound().setString(Constants.NBT.OWNER_UUID, ownerUUID);
|
|
|
|
}
|
2015-10-29 20:22:14 -07:00
|
|
|
}
|