mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-18 03:15:07 +00:00
Remove deprecated relic binding by name in favor of uuid
This commit is contained in:
1 parent
a2a0ba4275
commit
2dc50866a1
4 files changed
+17
-85
No files matched your search
@@ -11,7 +11,9 @@
|
||||
package vazkii.botania.api.item;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
@@ -20,19 +22,6 @@ import java.util.UUID;
|
||||
*/
|
||||
public interface IRelic {
|
||||
|
||||
/**
|
||||
* Binds to the player name passed in.
|
||||
*/
|
||||
@Deprecated
|
||||
public void bindToUsername(String playerName, ItemStack stack);
|
||||
|
||||
/**
|
||||
* Gets the username of the person this relic is bound to, or the empty String if the username field is empty.
|
||||
* You should not use this to determine if a relic is bound, use UUIDs instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public String getSoulbindUsername(ItemStack stack);
|
||||
|
||||
/**
|
||||
* Binds to the UUID passed in.
|
||||
*/
|
||||
@@ -41,6 +30,7 @@ public interface IRelic {
|
||||
/**
|
||||
* Gets the UUID of the person this relic is bound to, or null if a well-formed UUID could not be found
|
||||
*/
|
||||
@Nullable
|
||||
public UUID getSoulbindUUID(ItemStack stack);
|
||||
|
||||
/**
|
||||
|
||||
@@ -55,38 +55,23 @@ public class AesirRingRecipe extends IForgeRegistryEntry.Impl<IRecipe> implement
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack getCraftingResult(@Nonnull InventoryCrafting var1) {
|
||||
String soulbind = null;
|
||||
UUID soulbindUUID = null;
|
||||
boolean hasUUID = false;
|
||||
|
||||
for(int i = 0; i < var1.getSizeInventory(); i++) {
|
||||
ItemStack stack = var1.getStackInSlot(i);
|
||||
if(!stack.isEmpty()) {
|
||||
if(stack.getItem() instanceof IRelic) {
|
||||
if(((IRelic) stack.getItem()).hasUUID(stack)) {
|
||||
hasUUID = true;
|
||||
UUID bindUUID = ((IRelic) stack.getItem()).getSoulbindUUID(stack);
|
||||
if(soulbindUUID == null)
|
||||
soulbindUUID = bindUUID;
|
||||
else if(!soulbindUUID.equals(bindUUID))
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
else {
|
||||
String bind = ((IRelic) stack.getItem()).getSoulbindUsername(stack);
|
||||
if(soulbind == null)
|
||||
soulbind = bind;
|
||||
else if(!soulbind.equals(bind))
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
if(stack.getItem() instanceof IRelic && ((IRelic) stack.getItem()).hasUUID(stack)) {
|
||||
UUID bindUUID = ((IRelic) stack.getItem()).getSoulbindUUID(stack);
|
||||
if(soulbindUUID == null)
|
||||
soulbindUUID = bindUUID;
|
||||
else if(!soulbindUUID.equals(bindUUID))
|
||||
return ItemStack.EMPTY;
|
||||
} else return ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
ItemStack stack = new ItemStack(ModItems.aesirRing);
|
||||
if(hasUUID)
|
||||
((IRelic) ModItems.aesirRing).bindToUUID(soulbindUUID, stack);
|
||||
else
|
||||
((IRelic) ModItems.aesirRing).bindToUsername(soulbind, stack);
|
||||
((IRelic) ModItems.aesirRing).bindToUUID(soulbindUUID, stack);
|
||||
return stack;
|
||||
}
|
||||
|
||||
|
||||
@@ -62,9 +62,9 @@ public class ItemRelic extends ItemMod implements IRelic {
|
||||
if(!hasUUID(stack)) {
|
||||
addStringToTooltip(I18n.format("botaniamisc.relicUnbound"), list);
|
||||
} else {
|
||||
addStringToTooltip(I18n.format("botaniamisc.relicSoulbound", getSoulbindUsername(stack)), list);
|
||||
if(!getSoulbindUUID(stack).equals(Minecraft.getMinecraft().player.getUniqueID()))
|
||||
addStringToTooltip(I18n.format("botaniamisc.notYourSagittarius", getSoulbindUsername(stack)), list);
|
||||
addStringToTooltip(I18n.format("botaniamisc.notYourSagittarius"), list);
|
||||
else addStringToTooltip(I18n.format("botaniamisc.relicSoulbound", Minecraft.getMinecraft().player.getName()), list);
|
||||
}
|
||||
|
||||
if(stack.getItem() == ModItems.aesirRing)
|
||||
@@ -97,30 +97,11 @@ public class ItemRelic extends ItemMod implements IRelic {
|
||||
return;
|
||||
|
||||
boolean rightPlayer = true;
|
||||
if(hasUUID(stack)) {
|
||||
// Sync to username todo is this worth 'optimizing'?
|
||||
if (UsernameCache.containsUUID(getSoulbindUUID(stack))) {
|
||||
bindToUsername(UsernameCache.getLastKnownUsername(getSoulbindUUID(stack)), stack);
|
||||
} else {
|
||||
bindToUsername("", stack);
|
||||
}
|
||||
|
||||
// UUID trumps username
|
||||
rightPlayer = getSoulbindUUID(stack).equals(player.getUniqueID());
|
||||
} else {
|
||||
if ("".equals(getSoulbindUsername(stack))) {
|
||||
// New user
|
||||
bindToUUID(player.getUniqueID(), stack);
|
||||
// todo 1.12 broadcast advancement event for relic bind
|
||||
} else {
|
||||
if (player.getName().equals(getSoulbindUsername(stack))) {
|
||||
// Old relic, correct owner, convert to UUID
|
||||
bindToUUID(player.getUniqueID(), stack);
|
||||
} else {
|
||||
// Old relic, wrong owner, damage
|
||||
rightPlayer = false;
|
||||
}
|
||||
}
|
||||
if(!hasUUID(stack)) {
|
||||
bindToUUID(player.getUniqueID(), stack);
|
||||
} else if (!getSoulbindUUID(stack).equals(player.getUniqueID())) {
|
||||
rightPlayer = false;
|
||||
}
|
||||
|
||||
if(!rightPlayer && player.ticksExisted % 10 == 0 && (!(stack.getItem() instanceof ItemRelic) || ((ItemRelic) stack.getItem()).shouldDamageWrongPlayer()))
|
||||
@@ -128,27 +109,13 @@ public class ItemRelic extends ItemMod implements IRelic {
|
||||
}
|
||||
|
||||
public boolean isRightPlayer(EntityPlayer player, ItemStack stack) {
|
||||
if (hasUUID(stack)) {
|
||||
return getSoulbindUUID(stack).equals(player.getUniqueID());
|
||||
} else {
|
||||
return getSoulbindUsername(stack).equals(player.getName());
|
||||
}
|
||||
return hasUUID(stack) && getSoulbindUUID(stack).equals(player.getUniqueID());
|
||||
}
|
||||
|
||||
public static DamageSource damageSource() {
|
||||
return new DamageSource("botania-relic");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindToUsername(String playerName, ItemStack stack) {
|
||||
ItemNBTHelper.setString(stack, TAG_SOULBIND_NAME, playerName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSoulbindUsername(ItemStack stack) {
|
||||
return ItemNBTHelper.getString(stack, TAG_SOULBIND_NAME, "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindToUUID(UUID uuid, ItemStack stack) {
|
||||
ItemNBTHelper.setString(stack, TAG_SOULBIND_UUID, uuid.toString());
|
||||
|
||||
@@ -66,16 +66,6 @@ public abstract class ItemRelicBauble extends ItemBauble implements IRelic {
|
||||
return player instanceof EntityPlayer && dummy.isRightPlayer((EntityPlayer) player, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindToUsername(String playerName, ItemStack stack) {
|
||||
dummy.bindToUsername(playerName, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSoulbindUsername(ItemStack stack) {
|
||||
return dummy.getSoulbindUsername(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindToUUID(UUID uuid, ItemStack stack) {
|
||||
dummy.bindToUUID(uuid, stack);
|
||||
|
||||
Reference in new issue
Block a user