mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-18 03:15:07 +00:00
Baubles now generate a random UUID and use it to create attributes for the attribute map. Fixes the Ring of Odin visually killing the player when removed. Closes #720
This commit is contained in:
1 parent
11332ae4ad
commit
893cf4dc07
5 files changed
+39
-12
No files matched your search
@@ -11,6 +11,7 @@
|
||||
package vazkii.botania.common.item.equipment.bauble;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
@@ -34,6 +35,8 @@ import cpw.mods.fml.relauncher.SideOnly;
|
||||
public abstract class ItemBauble extends ItemMod implements IBauble, ICosmeticAttachable {
|
||||
|
||||
private static final String TAG_HASHCODE = "playerHashcode";
|
||||
private static final String TAG_BAUBLE_UUID_MOST = "baubleUUIDMost";
|
||||
private static final String TAG_BAUBLE_UUID_LEAST = "baubleUUIDLeast";
|
||||
private static final String TAG_COSMETIC_ITEM = "cosmeticItem";
|
||||
|
||||
public ItemBauble(String name) {
|
||||
@@ -169,12 +172,25 @@ public abstract class ItemBauble extends ItemMod implements IBauble, ICosmeticAt
|
||||
public boolean doesContainerItemLeaveCraftingGrid(ItemStack p_77630_1_) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static UUID getBaubleUUID(ItemStack stack) {
|
||||
long most = ItemNBTHelper.getLong(stack, TAG_BAUBLE_UUID_MOST, 0);
|
||||
if(most == 0) {
|
||||
UUID uuid = UUID.randomUUID();
|
||||
ItemNBTHelper.setLong(stack, TAG_BAUBLE_UUID_MOST, uuid.getMostSignificantBits());
|
||||
ItemNBTHelper.setLong(stack, TAG_BAUBLE_UUID_LEAST, uuid.getLeastSignificantBits());
|
||||
return getBaubleUUID(stack);
|
||||
}
|
||||
|
||||
long least = ItemNBTHelper.getLong(stack, TAG_BAUBLE_UUID_LEAST, 0);
|
||||
return new UUID(most, least);
|
||||
}
|
||||
|
||||
public int getLastPlayerHashcode(ItemStack stack) {
|
||||
public static int getLastPlayerHashcode(ItemStack stack) {
|
||||
return ItemNBTHelper.getInt(stack, TAG_HASHCODE, 0);
|
||||
}
|
||||
|
||||
public void setLastPlayerHashcode(ItemStack stack, int hash) {
|
||||
public static void setLastPlayerHashcode(ItemStack stack, int hash) {
|
||||
ItemNBTHelper.setInt(stack, TAG_HASHCODE, hash);
|
||||
}
|
||||
|
||||
|
||||
@@ -23,19 +23,22 @@ public abstract class ItemBaubleModifier extends ItemBauble {
|
||||
|
||||
public ItemBaubleModifier(String name) {
|
||||
super(name);
|
||||
fillModifiers(attributes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEquippedOrLoadedIntoWorld(ItemStack stack, EntityLivingBase player) {
|
||||
attributes.clear();
|
||||
fillModifiers(attributes, stack);
|
||||
player.getAttributeMap().applyAttributeModifiers(attributes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUnequipped(ItemStack stack, EntityLivingBase player) {
|
||||
attributes.clear();
|
||||
fillModifiers(attributes, stack);
|
||||
player.getAttributeMap().removeAttributeModifiers(attributes);
|
||||
}
|
||||
|
||||
abstract void fillModifiers(Multimap<String, AttributeModifier> attributes);
|
||||
abstract void fillModifiers(Multimap<String, AttributeModifier> attributes, ItemStack stack);
|
||||
|
||||
}
|
||||
@@ -47,8 +47,8 @@ public class ItemKnockbackBelt extends ItemBaubleModifier implements IBaubleRend
|
||||
}
|
||||
|
||||
@Override
|
||||
void fillModifiers(Multimap<String, AttributeModifier> attributes) {
|
||||
attributes.put(SharedMonsterAttributes.knockbackResistance.getAttributeUnlocalizedName(), new AttributeModifier(new UUID(2745708 /** Random number **/, 43743), "Bauble modifier", 1, 0));
|
||||
void fillModifiers(Multimap<String, AttributeModifier> attributes, ItemStack stack) {
|
||||
attributes.put(SharedMonsterAttributes.knockbackResistance.getAttributeUnlocalizedName(), new AttributeModifier(getBaubleUUID(stack), "Bauble modifier", 1, 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -42,7 +42,6 @@ public class ItemAesirRing extends ItemRelicBauble implements IWireframeCoordina
|
||||
|
||||
public ItemAesirRing() {
|
||||
super(LibItemNames.AESIR_RING);
|
||||
fillModifiers(attributes);
|
||||
GameRegistry.addRecipe(new AesirRingRecipe());
|
||||
RecipeSorter.register("botania:aesirRing", AesirRingRecipe.class, Category.SHAPELESS, "");
|
||||
}
|
||||
@@ -64,16 +63,21 @@ public class ItemAesirRing extends ItemRelicBauble implements IWireframeCoordina
|
||||
|
||||
@Override
|
||||
public void onEquippedOrLoadedIntoWorld(ItemStack stack, EntityLivingBase player) {
|
||||
attributes.clear();
|
||||
fillModifiers(attributes, stack);
|
||||
player.getAttributeMap().applyAttributeModifiers(attributes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUnequipped(ItemStack stack, EntityLivingBase player) {
|
||||
attributes.clear();
|
||||
fillModifiers(attributes, stack);
|
||||
player.getAttributeMap().removeAttributeModifiers(attributes);
|
||||
}
|
||||
|
||||
void fillModifiers(Multimap<String, AttributeModifier> attributes) {
|
||||
attributes.put(SharedMonsterAttributes.maxHealth.getAttributeUnlocalizedName(), new AttributeModifier(new UUID(2756708 /** Random number **/, 43873), "Bauble modifier", 20, 0));
|
||||
|
||||
void fillModifiers(Multimap<String, AttributeModifier> attributes, ItemStack stack) {
|
||||
attributes.put(SharedMonsterAttributes.maxHealth.getAttributeUnlocalizedName(), new AttributeModifier(getBaubleUUID(stack), "Bauble modifier", 20, 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -51,7 +51,6 @@ public class ItemOdinRing extends ItemRelicBauble {
|
||||
|
||||
public ItemOdinRing() {
|
||||
super(LibItemNames.ODIN_RING);
|
||||
fillModifiers(attributes);
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
|
||||
@@ -90,16 +89,21 @@ public class ItemOdinRing extends ItemRelicBauble {
|
||||
|
||||
@Override
|
||||
public void onEquippedOrLoadedIntoWorld(ItemStack stack, EntityLivingBase player) {
|
||||
attributes.clear();
|
||||
fillModifiers(attributes, stack);
|
||||
player.getAttributeMap().applyAttributeModifiers(attributes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUnequipped(ItemStack stack, EntityLivingBase player) {
|
||||
attributes.clear();
|
||||
fillModifiers(attributes, stack);
|
||||
player.getAttributeMap().removeAttributeModifiers(attributes);
|
||||
}
|
||||
|
||||
void fillModifiers(Multimap<String, AttributeModifier> attributes) {
|
||||
attributes.put(SharedMonsterAttributes.maxHealth.getAttributeUnlocalizedName(), new AttributeModifier(new UUID(2755708 /** Random number **/, 43843), "Bauble modifier", 20, 0));
|
||||
|
||||
void fillModifiers(Multimap<String, AttributeModifier> attributes, ItemStack stack) {
|
||||
attributes.put(SharedMonsterAttributes.maxHealth.getAttributeUnlocalizedName(), new AttributeModifier(getBaubleUUID(stack), "Bauble modifier", 20, 0));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user