Added most of the rest of the Anointment framework and a few more items.
Includes a Fortune, Silk Touch, and +damage Anointment.
This commit is contained in:
parent
8d9319e271
commit
7f2c40a1c4
114 changed files with 962 additions and 218 deletions
|
@ -5,9 +5,12 @@ import java.util.ArrayList;
|
|||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
|
@ -22,11 +25,14 @@ import net.minecraft.entity.LivingEntity;
|
|||
import net.minecraft.entity.ai.attributes.Attribute;
|
||||
import net.minecraft.entity.ai.attributes.AttributeModifier;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.EquipmentSlotType;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.nbt.ListNBT;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.Util;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraftforge.registries.ForgeRegistryEntry;
|
||||
import wayoftime.bloodmagic.core.living.LivingStats;
|
||||
import wayoftime.bloodmagic.core.living.LivingUpgrade;
|
||||
import wayoftime.bloodmagic.core.living.LivingUpgrade.Level;
|
||||
|
||||
@JsonAdapter(Anointment.Deserializer.class)
|
||||
|
@ -36,9 +42,12 @@ public class Anointment extends ForgeRegistryEntry<Anointment>
|
|||
|
||||
private final ResourceLocation key;
|
||||
// private final Set<ResourceLocation> incompatible;
|
||||
private String translationKey = null;
|
||||
private final Map<String, Bonus> bonuses;
|
||||
private IAttributeProvider attributeProvider;
|
||||
private IDamageProvider damageProvider;
|
||||
private boolean consumeOnAttack = false;
|
||||
private boolean consumeOnHarvest = false;
|
||||
|
||||
public Anointment(ResourceLocation key)
|
||||
{
|
||||
|
@ -62,7 +71,7 @@ public class Anointment extends ForgeRegistryEntry<Anointment>
|
|||
if (modifiers.isEmpty() || level == 0)
|
||||
return 0;
|
||||
|
||||
return modifiers.get(level - 1);
|
||||
return level <= modifiers.size() ? modifiers.get(level - 1) : modifiers.get(modifiers.size() - 1);
|
||||
}
|
||||
|
||||
public ResourceLocation getKey()
|
||||
|
@ -76,6 +85,120 @@ public class Anointment extends ForgeRegistryEntry<Anointment>
|
|||
return key.toString();
|
||||
}
|
||||
|
||||
public boolean applyAnointment(AnointmentHolder holder, ItemStack stack, int level)
|
||||
{
|
||||
if (level < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
IAttributeProvider prov = this.getAttributeProvider();
|
||||
if (prov == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
Multimap<Attribute, AttributeModifier> modifiers = HashMultimap.create();
|
||||
modifiers.putAll(stack.getItem().getAttributeModifiers(EquipmentSlotType.MAINHAND, stack));
|
||||
|
||||
this.getAttributeProvider().handleAttributes(holder, modifiers, UUID.nameUUIDFromBytes(this.getKey().toString().getBytes()), this, level);
|
||||
|
||||
for (Entry<Attribute, AttributeModifier> entry : modifiers.entries())
|
||||
{
|
||||
stack.addAttributeModifier(entry.getKey(), entry.getValue(), EquipmentSlotType.MAINHAND);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean removeAnointment(AnointmentHolder holder, ItemStack stack, EquipmentSlotType slot)
|
||||
{
|
||||
IAttributeProvider provider = this.getAttributeProvider();
|
||||
if (provider != null)
|
||||
{
|
||||
Multimap<Attribute, AttributeModifier> modifiers = HashMultimap.create();
|
||||
this.getAttributeProvider().handleAttributes(holder, modifiers, UUID.nameUUIDFromBytes(this.getKey().toString().getBytes()), this, 1);
|
||||
|
||||
if (stack.hasTag() && stack.getTag().contains("AttributeModifiers", 9))
|
||||
{
|
||||
// multimap = HashMultimap.create();
|
||||
ListNBT listnbt = stack.getTag().getList("AttributeModifiers", 10);
|
||||
List<Integer> removeList = new ArrayList<Integer>();
|
||||
|
||||
for (int i = 0; i < listnbt.size(); i++)
|
||||
{
|
||||
CompoundNBT compoundnbt = listnbt.getCompound(i);
|
||||
if (!compoundnbt.contains("Slot", 8) || compoundnbt.getString("Slot").equals(slot.getName()))
|
||||
{
|
||||
Optional<Attribute> optional = Registry.ATTRIBUTE.getOptional(ResourceLocation.tryCreate(compoundnbt.getString("AttributeName")));
|
||||
if (optional.isPresent())
|
||||
{
|
||||
AttributeModifier attributemodifier = AttributeModifier.read(compoundnbt);
|
||||
if (attributemodifier != null && attributemodifier.getID().getLeastSignificantBits() != 0L && attributemodifier.getID().getMostSignificantBits() != 0L)
|
||||
{
|
||||
for (Entry<Attribute, AttributeModifier> entry : modifiers.entries())
|
||||
{
|
||||
if (entry.getKey().equals(optional.get()) && entry.getValue().getID().equals(attributemodifier.getID()))
|
||||
{
|
||||
removeList.add(i);
|
||||
}
|
||||
}
|
||||
// multimap.put(optional.get(), attributemodifier);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int index : removeList)
|
||||
{
|
||||
listnbt.remove(index);
|
||||
}
|
||||
|
||||
if (removeList.size() >= 1)
|
||||
{
|
||||
stack.getTag().put("AttributeModifiers", listnbt);
|
||||
if (listnbt.isEmpty())
|
||||
{
|
||||
stack.getTag().remove("AttributeModifiers");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// for (Entry<Attribute, AttributeModifier> entry : modifiers.entries())
|
||||
// {
|
||||
//
|
||||
// }
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getTranslationKey()
|
||||
{
|
||||
return translationKey == null ? translationKey = Util.makeTranslationKey("anointment", key) : translationKey;
|
||||
}
|
||||
|
||||
public Anointment setConsumeOnAttack()
|
||||
{
|
||||
this.consumeOnAttack = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean consumeOnAttack()
|
||||
{
|
||||
return this.consumeOnAttack;
|
||||
}
|
||||
|
||||
public Anointment setConsumeOnHarvest()
|
||||
{
|
||||
this.consumeOnHarvest = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean consumeOnHarvest()
|
||||
{
|
||||
return this.consumeOnHarvest;
|
||||
}
|
||||
|
||||
public Anointment withAttributeProvider(IAttributeProvider attributeProvider)
|
||||
{
|
||||
this.attributeProvider = attributeProvider;
|
||||
|
@ -105,7 +228,7 @@ public class Anointment extends ForgeRegistryEntry<Anointment>
|
|||
|
||||
public interface IDamageProvider
|
||||
{
|
||||
double getAdditionalDamage(PlayerEntity player, ItemStack weapon, double damage, LivingStats stats, LivingEntity attacked, LivingUpgrade upgrade, int level);
|
||||
double getAdditionalDamage(PlayerEntity player, ItemStack weapon, double damage, AnointmentHolder holder, LivingEntity attacked, Anointment anoint, int level);
|
||||
}
|
||||
|
||||
public static class Bonus
|
||||
|
@ -162,4 +285,5 @@ public class Anointment extends ForgeRegistryEntry<Anointment>
|
|||
return upgrade;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
package wayoftime.bloodmagic.anointment;
|
||||
|
||||
import net.minecraft.client.renderer.color.IItemColor;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import wayoftime.bloodmagic.common.item.ItemAnointmentProvider;
|
||||
|
||||
public class AnointmentColor implements IItemColor
|
||||
{
|
||||
@Override
|
||||
public int getColor(ItemStack stack, int layer)
|
||||
{
|
||||
if (layer == 1 && stack.getItem() instanceof ItemAnointmentProvider)
|
||||
{
|
||||
return ((ItemAnointmentProvider) stack.getItem()).getColor();
|
||||
}
|
||||
|
||||
return 0xFFFFFF;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package wayoftime.bloodmagic.anointment;
|
||||
|
||||
public class AnointmentData
|
||||
{
|
||||
private int level;
|
||||
private int damage;
|
||||
private int maxDamage;
|
||||
|
||||
public AnointmentData(int level, int damage, int maxDamage)
|
||||
{
|
||||
this.level = level;
|
||||
this.damage = damage;
|
||||
this.maxDamage = maxDamage;
|
||||
}
|
||||
|
||||
public int getLevel()
|
||||
{
|
||||
return this.level;
|
||||
}
|
||||
|
||||
public int getDamage()
|
||||
{
|
||||
return this.damage;
|
||||
}
|
||||
|
||||
public int getMaxDamage()
|
||||
{
|
||||
return this.maxDamage;
|
||||
}
|
||||
|
||||
public void damage(int amount)
|
||||
{
|
||||
this.damage = Math.min(damage + amount, maxDamage);
|
||||
}
|
||||
|
||||
public boolean isMaxDamage()
|
||||
{
|
||||
return damage >= maxDamage;
|
||||
}
|
||||
|
||||
public String getDamageString()
|
||||
{
|
||||
return "" + (maxDamage - damage) + "/" + maxDamage;
|
||||
}
|
||||
}
|
|
@ -1,15 +1,25 @@
|
|||
package wayoftime.bloodmagic.anointment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.EquipmentSlotType;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.nbt.ListNBT;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import wayoftime.bloodmagic.anointment.Anointment.IDamageProvider;
|
||||
import wayoftime.bloodmagic.core.AnointmentRegistrar;
|
||||
import wayoftime.bloodmagic.util.Constants;
|
||||
|
||||
|
@ -27,6 +37,116 @@ public class AnointmentHolder
|
|||
this(Maps.newHashMap());
|
||||
}
|
||||
|
||||
// Returns true if the anointment is applied successfully.
|
||||
public boolean applyAnointment(ItemStack stack, Anointment anointment, AnointmentData data)
|
||||
{
|
||||
if (canApplyAnointment(stack, anointment, data))
|
||||
{
|
||||
anointments.put(anointment, data);
|
||||
anointment.applyAnointment(this, stack, data.getLevel());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean canApplyAnointment(ItemStack stack, Anointment anointment, AnointmentData data)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public int getAnointmentLevel(Anointment anointment)
|
||||
{
|
||||
if (anointments.containsKey(anointment))
|
||||
{
|
||||
return anointments.get(anointment).getLevel();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public boolean consumeAnointmentDurabilityOnHit(ItemStack weaponStack, EquipmentSlotType type)
|
||||
{
|
||||
// System.out.println("Attempting consumption");
|
||||
boolean didConsume = false;
|
||||
List<Anointment> removedAnointments = new ArrayList<Anointment>();
|
||||
for (Entry<Anointment, AnointmentData> entry : anointments.entrySet())
|
||||
{
|
||||
Anointment annointment = entry.getKey();
|
||||
if (annointment.consumeOnAttack())
|
||||
{
|
||||
AnointmentData data = entry.getValue();
|
||||
data.damage(1);
|
||||
didConsume = true;
|
||||
if (data.isMaxDamage())
|
||||
{
|
||||
removedAnointments.add(annointment);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (Anointment anointment : removedAnointments)
|
||||
{
|
||||
removeAnointment(weaponStack, type, anointment);
|
||||
}
|
||||
|
||||
return didConsume;
|
||||
}
|
||||
|
||||
public boolean consumeAnointmentDurabilityOnHarvest(ItemStack weaponStack, EquipmentSlotType type)
|
||||
{
|
||||
boolean didConsume = false;
|
||||
List<Anointment> removedAnointments = new ArrayList<Anointment>();
|
||||
for (Entry<Anointment, AnointmentData> entry : anointments.entrySet())
|
||||
{
|
||||
Anointment annointment = entry.getKey();
|
||||
if (annointment.consumeOnHarvest())
|
||||
{
|
||||
AnointmentData data = entry.getValue();
|
||||
data.damage(1);
|
||||
didConsume = true;
|
||||
if (data.isMaxDamage())
|
||||
{
|
||||
removedAnointments.add(annointment);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (Anointment anointment : removedAnointments)
|
||||
{
|
||||
removeAnointment(weaponStack, type, anointment);
|
||||
}
|
||||
|
||||
return didConsume;
|
||||
}
|
||||
|
||||
// Called when the specified anointment is to be removed. Occurs if the
|
||||
// anointment runs out of uses or if removed via another source.
|
||||
public boolean removeAnointment(ItemStack weaponStack, EquipmentSlotType type, Anointment anointment)
|
||||
{
|
||||
anointments.remove(anointment);
|
||||
anointment.removeAnointment(this, weaponStack, type);
|
||||
return true;
|
||||
}
|
||||
|
||||
public Map<Anointment, AnointmentData> getAnointments()
|
||||
{
|
||||
return ImmutableMap.copyOf(anointments);
|
||||
}
|
||||
|
||||
public double getAdditionalDamage(PlayerEntity player, ItemStack weapon, double damage, LivingEntity attacked)
|
||||
{
|
||||
double additionalDamage = 0;
|
||||
for (Entry<Anointment, AnointmentData> entry : anointments.entrySet())
|
||||
{
|
||||
IDamageProvider prov = entry.getKey().getDamageProvider();
|
||||
if (prov != null)
|
||||
{
|
||||
additionalDamage += prov.getAdditionalDamage(player, weapon, damage, this, attacked, entry.getKey(), entry.getValue().getLevel());
|
||||
}
|
||||
}
|
||||
return additionalDamage;
|
||||
}
|
||||
|
||||
public CompoundNBT serialize()
|
||||
{
|
||||
CompoundNBT compound = new CompoundNBT();
|
||||
|
@ -39,7 +159,7 @@ public class AnointmentHolder
|
|||
anoint.putInt("max_damage", v.getMaxDamage());
|
||||
statList.add(anoint);
|
||||
});
|
||||
compound.put("upgrades", statList);
|
||||
compound.put("anointments", statList);
|
||||
//
|
||||
// compound.putInt("maxPoints", maxPoints);
|
||||
|
||||
|
@ -52,7 +172,6 @@ public class AnointmentHolder
|
|||
statList.forEach(tag -> {
|
||||
if (!(tag instanceof CompoundNBT))
|
||||
return;
|
||||
|
||||
Anointment anoint = AnointmentRegistrar.ANOINTMENT_MAP.getOrDefault(new ResourceLocation(((CompoundNBT) tag).getString("key")), Anointment.DUMMY);
|
||||
// LivingUpgrade upgrade = LivingArmorRegistrar.UPGRADE_MAP.getOrDefault(new ResourceLocation(((CompoundNBT) tag).getString("key")), LivingUpgrade.DUMMY);
|
||||
if (anoint == Anointment.DUMMY)
|
||||
|
@ -116,32 +235,25 @@ public class AnointmentHolder
|
|||
holder.toItemStack(heldItem);
|
||||
}
|
||||
|
||||
public static class AnointmentData
|
||||
public static void appendAnointmentTooltip(AnointmentHolder holder, List<ITextComponent> tooltip)
|
||||
{
|
||||
private int level;
|
||||
private int damage;
|
||||
private int maxDamage;
|
||||
|
||||
public AnointmentData(int level, int damage, int maxDamage)
|
||||
if (holder != null)
|
||||
{
|
||||
this.level = level;
|
||||
this.damage = damage;
|
||||
this.maxDamage = maxDamage;
|
||||
}
|
||||
// System.out.println("Holder is not null. Size: " + holder.getAnointments().size());
|
||||
// if (trainable)
|
||||
// tooltip.add(new TranslationTextComponent("tooltip.bloodmagic.livingarmour.upgrade.points", stats.getUsedPoints(), stats.getMaxPoints()).mergeStyle(TextFormatting.GOLD));
|
||||
|
||||
public int getLevel()
|
||||
{
|
||||
return this.level;
|
||||
}
|
||||
holder.getAnointments().forEach((k, v) -> {
|
||||
|
||||
public int getDamage()
|
||||
{
|
||||
return this.damage;
|
||||
}
|
||||
|
||||
public int getMaxDamage()
|
||||
{
|
||||
return this.maxDamage;
|
||||
// if (k.getLevel(v.intValue()) <= 0)
|
||||
// return;
|
||||
boolean sneaking = Screen.hasShiftDown();
|
||||
// if (!InputUtil.isKeyPressed(MinecraftClient.getInstance().getWindow().getHandle(), 340) || k.getNextRequirement(v) == 0)
|
||||
if (!sneaking)
|
||||
tooltip.add(new TranslationTextComponent("%s %s", new TranslationTextComponent(k.getTranslationKey()), new TranslationTextComponent("enchantment.level." + v.getLevel())));
|
||||
else
|
||||
tooltip.add(new TranslationTextComponent("%s %s", new TranslationTextComponent(k.getTranslationKey()), (": (" + v.getDamageString() + ")")));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue