Rewrite IBindable to provide an object instead of storing 2 strings
This commit is contained in:
parent
941173dbf4
commit
2a43e53842
47 changed files with 416 additions and 510 deletions
|
@ -1,9 +1,26 @@
|
|||
package WayofTime.bloodmagic.iface;
|
||||
|
||||
import WayofTime.bloodmagic.util.Constants;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public interface IActivatable {
|
||||
boolean getActivated(ItemStack stack);
|
||||
|
||||
ItemStack setActivatedState(ItemStack stack, boolean activated);
|
||||
default boolean getActivated(ItemStack stack) {
|
||||
return !stack.isEmpty() && stack.hasTagCompound() && stack.getTagCompound().getBoolean(Constants.NBT.ACTIVATED);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
default ItemStack setActivatedState(ItemStack stack, boolean activated) {
|
||||
if (!stack.isEmpty()) {
|
||||
if (!stack.hasTagCompound())
|
||||
stack.setTagCompound(new NBTTagCompound());
|
||||
|
||||
stack.getTagCompound().setBoolean(Constants.NBT.ACTIVATED, activated);
|
||||
}
|
||||
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,37 +1,28 @@
|
|||
package WayofTime.bloodmagic.iface;
|
||||
|
||||
import WayofTime.bloodmagic.util.Constants;
|
||||
import WayofTime.bloodmagic.core.data.Binding;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Implement this interface on any Item that can be bound to a player.
|
||||
*/
|
||||
public interface IBindable {
|
||||
|
||||
/**
|
||||
* Gets the username of the Item's owner. Usually for display, such as in
|
||||
* the tooltip.
|
||||
* Gets an object that stores who this item is bound to.
|
||||
* <p>
|
||||
* If the item is not bound, this will be null.
|
||||
*
|
||||
* @param stack - The owned ItemStack
|
||||
* @return - The username of the Item's owner
|
||||
* @return - The binding object
|
||||
*/
|
||||
default String getOwnerName(ItemStack stack) {
|
||||
return !stack.isEmpty() && stack.hasTagCompound() ? stack.getTagCompound().getString(Constants.NBT.OWNER_NAME) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the UUID of the Item's owner.
|
||||
* <p>
|
||||
* If the item is not bound, this will be null.
|
||||
*
|
||||
* @param stack - The owned ItemStack
|
||||
* @return - The UUID of the Item's owner
|
||||
*/
|
||||
default String getOwnerUUID(ItemStack stack) {
|
||||
return !stack.isEmpty() && stack.hasTagCompound() ? stack.getTagCompound().getString(Constants.NBT.OWNER_UUID) : null;
|
||||
@Nullable
|
||||
default Binding getBinding(ItemStack stack) {
|
||||
Binding binding = Binding.fromStack(stack);
|
||||
return !stack.isEmpty() && binding != null ? binding : null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue