BloodMagic/src/main/java/WayofTime/bloodmagic/util/helper/BindableHelper.java

50 lines
1.7 KiB
Java
Raw Normal View History

package WayofTime.bloodmagic.util.helper;
import WayofTime.bloodmagic.core.data.Binding;
import WayofTime.bloodmagic.util.Constants;
import WayofTime.bloodmagic.event.ItemBindEvent;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
2017-08-15 21:30:48 -07:00
public class BindableHelper {
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());
}
/**
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
*/
2017-08-15 21:30:48 -07:00
public static void setItemOwnerName(ItemStack stack, String ownerName) {
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
*/
2017-08-15 21:30:48 -07:00
public static void setItemOwnerUUID(ItemStack stack, String ownerUUID) {
stack = NBTHelper.checkNBT(stack);
stack.getTagCompound().setString(Constants.NBT.OWNER_UUID, ownerUUID);
}
}