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:
WayofTime 2021-01-12 08:27:47 -05:00
parent 8d9319e271
commit 7f2c40a1c4
114 changed files with 962 additions and 218 deletions

View file

@ -14,6 +14,7 @@ import net.minecraft.item.crafting.IRecipeSerializer;
import net.minecraft.potion.Effect;
import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.ColorHandlerEvent;
import net.minecraftforge.client.event.ModelRegistryEvent;
import net.minecraftforge.client.model.ModelLoaderRegistry;
import net.minecraftforge.client.model.generators.ItemModelProvider;
@ -56,6 +57,7 @@ import wayoftime.bloodmagic.core.registry.AlchemyArrayRegistry;
import wayoftime.bloodmagic.core.registry.OrbRegistry;
import wayoftime.bloodmagic.impl.BloodMagicAPI;
import wayoftime.bloodmagic.impl.BloodMagicCorePlugin;
import wayoftime.bloodmagic.loot.GlobalLootModifier;
import wayoftime.bloodmagic.network.BloodMagicPacketHandler;
import wayoftime.bloodmagic.potion.BloodMagicPotions;
import wayoftime.bloodmagic.ritual.ModRituals;
@ -110,6 +112,8 @@ public class BloodMagic
BloodMagicBlocks.CONTAINERS.register(modBus);
BloodMagicEntityTypes.ENTITY_TYPES.register(modBus);
GlobalLootModifier.GLM.register(modBus);
BloodMagicRecipeSerializers.RECIPE_SERIALIZERS.register(modBus);
// Register the setup method for modloading
@ -120,6 +124,7 @@ public class BloodMagic
modBus.addListener(this::processIMC);
// Register the doClientStuff method for modloading
modBus.addListener(this::doClientStuff);
modBus.addListener(this::registerColors);
modBus.addListener(this::loadModels);
modBus.addListener(this::gatherData);
@ -244,6 +249,11 @@ public class BloodMagic
Elements.registerElements();
}
private void registerColors(final ColorHandlerEvent.Item event)
{
ClientEvents.colorHandlerEvent(event);
}
private void enqueueIMC(final InterModEnqueueEvent event)
{
// some example code to dispatch IMC to another mod

View file

@ -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;
}
}
}

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -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() + ")")));
});
}
}
}

View file

@ -11,6 +11,7 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemModelsProperties;
import net.minecraft.item.ItemStack;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.ColorHandlerEvent;
import net.minecraftforge.client.event.ModelRegistryEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.DeferredWorkQueue;
@ -19,6 +20,7 @@ import net.minecraftforge.fml.client.registry.RenderingRegistry;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import wayoftime.bloodmagic.BloodMagic;
import wayoftime.bloodmagic.anointment.AnointmentColor;
import wayoftime.bloodmagic.api.compat.IMultiWillTool;
import wayoftime.bloodmagic.client.model.MimicColor;
import wayoftime.bloodmagic.client.render.alchemyarray.BeaconAlchemyCircleRenderer;
@ -64,6 +66,11 @@ public class ClientEvents
ScreenManager.registerFactory(BloodMagicBlocks.ALCHEMY_TABLE_CONTAINER.get(), ScreenAlchemyTable::new);
}
public static void colorHandlerEvent(ColorHandlerEvent.Item event)
{
event.getItemColors().register(new AnointmentColor(), BloodMagicItems.MELEE_DAMAGE_ANOINTMENT.get(), BloodMagicItems.SILK_TOUCH_ANOINTMENT.get(), BloodMagicItems.FORTUNE_ANOINTMENT.get());
}
@SuppressWarnings("deprecation")
public static void initClientEvents(FMLClientSetupEvent event)
{

View file

@ -3,6 +3,7 @@ package wayoftime.bloodmagic.common.data;
import net.minecraft.block.Block;
import net.minecraft.data.DataGenerator;
import net.minecraft.item.Item;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.generators.ItemModelBuilder;
import net.minecraftforge.client.model.generators.ItemModelProvider;
import net.minecraftforge.client.model.generators.ModelFile;
@ -90,6 +91,11 @@ public class GeneratorItemModels extends ItemModelProvider
registerBlockModel(BloodMagicBlocks.SHAPED_CHARGE.get());
registerBlockModel(BloodMagicBlocks.DEFORESTER_CHARGE.get());
registerMultiLayerItem(BloodMagicItems.SLATE_VIAL.get(), modLoc("item/alchemic_vial"), modLoc("item/alchemic_ribbon"));
registerMultiLayerItem(BloodMagicItems.MELEE_DAMAGE_ANOINTMENT.get(), modLoc("item/alchemic_vial"), modLoc("item/alchemic_liquid"), modLoc("item/alchemic_ribbon"));
registerMultiLayerItem(BloodMagicItems.SILK_TOUCH_ANOINTMENT.get(), modLoc("item/alchemic_vial"), modLoc("item/alchemic_liquid"), modLoc("item/alchemic_ribbon"));
registerMultiLayerItem(BloodMagicItems.FORTUNE_ANOINTMENT.get(), modLoc("item/alchemic_vial"), modLoc("item/alchemic_liquid"), modLoc("item/alchemic_ribbon"));
}
private void registerCustomFullTexture(Block block, String texturePath)
@ -113,7 +119,21 @@ public class GeneratorItemModels extends ItemModelProvider
private void registerBasicItem(Item item)
{
String path = item.getRegistryName().getPath();
singleTexture(path, mcLoc("item/handheld"), "layer0", modLoc("item/" + path));
singleTexture(path, mcLoc("item/generated"), "layer0", modLoc("item/" + path));
}
private void registerMultiLayerItem(Item item, ResourceLocation... locations)
{
String path = item.getRegistryName().getPath();
ItemModelBuilder builder = getBuilder(path).parent(getExistingFile(mcLoc("item/generated")));
// ModelFile model = withExistingParent(path, mcLoc("item/handheld"));
for (int i = 0; i < locations.length; i++)
{
builder.texture("layer" + i, locations[i]);
}
builder.assertExistence();
}
private void registerToggleableItem(Item item)

View file

@ -342,8 +342,15 @@ public class GeneratorLanguage extends LanguageProvider
add("tooltip.bloodmagic.livingarmour.extraExtraInfo", "&9-Hold shift + M for progress info-");
add("tooltip.bloodmagic.slate_vial", "A glass vial infused with a simple slate");
add("chat.bloodmagic.living_upgrade_level_increase", "%s has leveled up to %d");
// Anointments. Doesn't have any spelling to be pedantic about.
add("anointment.bloodmagic.melee_damage", "Whetstone");
add("anointment.bloodmagic.silk_touch", "Soft Touch");
add("anointment.bloodmagic.fortune", "Fortunate");
// Guide
add("guide.bloodmagic.name", "Sanguine Scientiem");
add("guide.bloodmagic.landing_text", "\"It is my dear hope that by holding this tome in your hands, I may impart the knowledge of the lost art that is Blood Magic\"$(br)$(o)- Magus Arcana$()");
@ -522,6 +529,12 @@ public class GeneratorLanguage extends LanguageProvider
addItem(BloodMagicItems.LIVING_TOME, "Living Armour Upgrade Tome");
// Anointment Items
addItem(BloodMagicItems.SLATE_VIAL, "Slate-infused Vial");
addItem(BloodMagicItems.MELEE_DAMAGE_ANOINTMENT, "Honing Oil");
addItem(BloodMagicItems.SILK_TOUCH_ANOINTMENT, "Soft Coating");
addItem(BloodMagicItems.FORTUNE_ANOINTMENT, "Fortuna Extract");
// Alchemy Items
addItem(BloodMagicItems.PLANT_OIL, "Plant Oil");

View file

@ -217,6 +217,12 @@ public class BloodMagicItems
public static final RegistryObject<Item> SALTPETER = BASICITEMS.register("saltpeter", () -> new ItemBase());
public static final RegistryObject<Item> PLANT_OIL = BASICITEMS.register("plantoil", () -> new ItemBase());
// Anointments
public static final RegistryObject<Item> SLATE_VIAL = ITEMS.register("slate_vial", () -> new ItemBase(16, "slate_vial"));
public static final RegistryObject<Item> MELEE_DAMAGE_ANOINTMENT = ITEMS.register("melee_anointment", () -> new ItemAnointmentProvider(BloodMagic.rl("melee_damage"), 0xFF0000, 1, 128));
public static final RegistryObject<Item> SILK_TOUCH_ANOINTMENT = ITEMS.register("silk_touch_anointment", () -> new ItemAnointmentProvider(BloodMagic.rl("silk_touch"), 0x00B0FF, 1, 256));
public static final RegistryObject<Item> FORTUNE_ANOINTMENT = ITEMS.register("fortune_anointment", () -> new ItemAnointmentProvider(BloodMagic.rl("fortune"), 3381504, 1, 128));
// Fragments
public static final RegistryObject<Item> IRON_FRAGMENT = BASICITEMS.register("ironfragment", () -> new ItemBase());
public static final RegistryObject<Item> GOLD_FRAGMENT = BASICITEMS.register("goldfragment", () -> new ItemBase());

View file

@ -4,22 +4,35 @@ import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.SwordItem;
import net.minecraft.particles.ParticleTypes;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.SoundEvents;
import net.minecraft.world.World;
import net.minecraftforge.common.ToolType;
import wayoftime.bloodmagic.BloodMagic;
import wayoftime.bloodmagic.anointment.Anointment;
import wayoftime.bloodmagic.anointment.AnointmentData;
import wayoftime.bloodmagic.anointment.AnointmentHolder;
import wayoftime.bloodmagic.core.AnointmentRegistrar;
public class ItemAnointmentProvider extends Item
{
public Anointment anointment;
// public Anointment anointment;
public ResourceLocation anointRL;
private int colour;
private int level;
private int maxDamage;
public ItemAnointmentProvider(Anointment anointment)
public ItemAnointmentProvider(ResourceLocation anointRL, int colour, int level, int maxDamage)
{
super(new Item.Properties().maxStackSize(16).group(BloodMagic.TAB));
this.anointment = anointment;
this.anointRL = anointRL;
this.colour = colour;
this.level = level;
this.maxDamage = maxDamage;
// this.anointment = anointment;
}
@Override
@ -27,7 +40,6 @@ public class ItemAnointmentProvider extends Item
{
ItemStack stack = player.getHeldItem(hand);
ItemStack weaponStack = player.getHeldItem(hand == Hand.MAIN_HAND ? Hand.OFF_HAND : Hand.MAIN_HAND);
// if (world.isRemote && !unusable)
// {
// Vector3d vec = player.getLookVec();
@ -50,7 +62,45 @@ public class ItemAnointmentProvider extends Item
{
if (!weaponStack.isEmpty() && isItemValidForApplication(weaponStack))
{
ToolType d;
AnointmentHolder holder = AnointmentHolder.fromItemStack(weaponStack);
if (holder == null)
{
holder = new AnointmentHolder();
}
if (holder.applyAnointment(weaponStack, AnointmentRegistrar.ANOINTMENT_MAP.get(anointRL), new AnointmentData(level, 0, maxDamage)))
{
// if (world instanceof ServerWorld)
{
SoundEvent soundevent = SoundEvents.ITEM_BOTTLE_EMPTY;
world.playSound(null, player.getPosition(), soundevent, SoundCategory.BLOCKS, 1.0F, 1.0F);
}
stack.shrink(1);
holder.toItemStack(weaponStack);
return ActionResult.resultSuccess(stack);
}
}
} else
{
if (!weaponStack.isEmpty() && isItemValidForApplication(weaponStack))
{
AnointmentHolder holder = AnointmentHolder.fromItemStack(weaponStack);
if (holder == null)
{
holder = new AnointmentHolder();
}
if (holder.canApplyAnointment(weaponStack, AnointmentRegistrar.ANOINTMENT_MAP.get(anointRL), new AnointmentData(level, 0, maxDamage)))
{
boolean flag1 = false;
double d0 = (double) (colour >> 16 & 255) / 255.0D;
double d1 = (double) (colour >> 8 & 255) / 255.0D;
double d2 = (double) (colour >> 0 & 255) / 255.0D;
for (int i = 0; i < 16; i++)
{
world.addParticle(flag1 ? ParticleTypes.AMBIENT_ENTITY_EFFECT
: ParticleTypes.ENTITY_EFFECT, player.getPosXRandom(0.3D), player.getPosYRandom(), player.getPosZRandom(0.3D), d0, d1, d2);
}
}
}
}
@ -71,4 +121,9 @@ public class ItemAnointmentProvider extends Item
{
return stack.getItem() instanceof SwordItem;
}
public int getColor()
{
return colour;
}
}

View file

@ -23,7 +23,17 @@ public class ItemBase extends Item
public ItemBase(String desc)
{
super(new Item.Properties().maxStackSize(64).group(BloodMagic.TAB));
this(64, desc);
}
public ItemBase(int stackSize)
{
this(stackSize, "");
}
public ItemBase(int stackSize, String desc)
{
super(new Item.Properties().maxStackSize(stackSize).group(BloodMagic.TAB));
this.desc = desc;
}

View file

@ -39,6 +39,8 @@ public class AlchemyTableRecipeProvider implements ISubRecipeProvider
AlchemyTableRecipeBuilder.alchemyTable(new ItemStack(BloodMagicItems.COAL_SAND.get(), 4), 400, 200, 1).addIngredient(Ingredient.fromItems(Items.COAL)).addIngredient(Ingredient.fromItems(Items.COAL)).addIngredient(Ingredient.fromItems(Items.FLINT)).build(consumer, BloodMagic.rl(basePath + "sand_coal"));
AlchemyTableRecipeBuilder.alchemyTable(new ItemStack(BloodMagicItems.BASIC_CUTTING_FLUID.get()), 1000, 200, 1).addIngredient(Ingredient.fromItems(BloodMagicItems.PLANT_OIL.get())).addIngredient(Ingredient.fromTag(Tags.Items.DUSTS_REDSTONE)).addIngredient(Ingredient.fromTag(Tags.Items.GUNPOWDER)).addIngredient(Ingredient.fromItems(Items.SUGAR)).addIngredient(Ingredient.fromTag(BloodMagicTags.DUST_COAL)).addIngredient(Ingredient.fromStacks(new ItemStack(Items.POTION))).build(consumer, BloodMagic.rl(basePath + "basic_cutting_fluid"));
AlchemyTableRecipeBuilder.alchemyTable(new ItemStack(BloodMagicItems.SLATE_VIAL.get(), 8), 500, 200, 1).addIngredient(Ingredient.fromItems(BloodMagicItems.SLATE.get())).addIngredient(Ingredient.fromTag(Tags.Items.GLASS)).addIngredient(Ingredient.fromTag(Tags.Items.GLASS)).addIngredient(Ingredient.fromTag(Tags.Items.GLASS)).addIngredient(Ingredient.fromTag(Tags.Items.GLASS)).addIngredient(Ingredient.fromTag(Tags.Items.GLASS)).build(consumer, BloodMagic.rl(basePath + "slate_vial"));
}
}

View file

@ -8,8 +8,6 @@ import java.util.function.Supplier;
import com.google.common.base.Charsets;
import com.google.common.io.Resources;
import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.entity.ai.attributes.Attributes;
import net.minecraft.util.ResourceLocation;
import wayoftime.bloodmagic.BloodMagic;
import wayoftime.bloodmagic.anointment.Anointment;
@ -45,14 +43,23 @@ public class AnointmentRegistrar
return def;
}).get();
public static final AnointmentRegistryObject<Anointment> ANOINTMENT_MELEE_DAMAGE = ANOINTMENTS.register("melee_damage", () -> parseDefinition("melee_damage").withAttributeProvider((stats, attributeMap, uuid, upgrade, level) -> {
// attributeMap.put(Attributes.KNOCKBACK_RESISTANCE, new AttributeModifier(uuid, "KB Modifier", upgrade.getBonusValue("kb", level).doubleValue(), AttributeModifier.Operation.ADDITION));
attributeMap.put(Attributes.ATTACK_DAMAGE, new AttributeModifier(uuid, "Damage", upgrade.getBonusValue("damage", level).intValue(), AttributeModifier.Operation.ADDITION));
}));
// public static final AnointmentRegistryObject<Anointment> ANOINTMENT_MELEE_DAMAGE = ANOINTMENTS.register("melee_damage", () -> parseDefinition("melee_damage").withAttributeProvider((stats, attributeMap, uuid, upgrade, level) -> {
// attributeMap.put(Attributes.ATTACK_DAMAGE, new AttributeModifier(uuid, "Weapon modifier", upgrade.getBonusValue("damage", level).intValue(), AttributeModifier.Operation.ADDITION));
// }).setConsumeOnAttack());
public static final AnointmentRegistryObject<Anointment> ANOINTMENT_MELEE_DAMAGE = ANOINTMENTS.register("melee_damage", () -> parseDefinition("melee_damage").withDamageProvider((player, weapon, damage, holder, attacked, anoint, level) -> {
return anoint.getBonusValue("damage", level).doubleValue();
}).setConsumeOnAttack());
public static final AnointmentRegistryObject<Anointment> ANOINTMENT_SILK_TOUCH = ANOINTMENTS.register("silk_touch", () -> new Anointment(BloodMagic.rl("silk_touch")).setConsumeOnHarvest());
public static final AnointmentRegistryObject<Anointment> ANOINTMENT_FORTUNE = ANOINTMENTS.register("fortune", () -> new Anointment(BloodMagic.rl("fortune")).setConsumeOnHarvest());
public static void register()
{
registerAnointment(ANOINTMENT_MELEE_DAMAGE.get());
registerAnointment(ANOINTMENT_SILK_TOUCH.get());
registerAnointment(ANOINTMENT_FORTUNE.get());
// Registry.register(UPGRADES, UPGRADE_ARROW_PROTECT.getKey(), UPGRADE_ARROW_PROTECT);
// Registry.register(UPGRADES, UPGRADE_ARROW_SHOT.getKey(), UPGRADE_ARROW_SHOT);
// Registry.register(UPGRADES, UPGRADE_CRITICAL_STRIKE.getKey(), UPGRADE_CRITICAL_STRIKE);

View file

@ -0,0 +1,16 @@
package wayoftime.bloodmagic.loot;
import net.minecraft.loot.LootConditionType;
import net.minecraft.loot.conditions.MatchTool;
import net.minecraft.util.registry.Registry;
import wayoftime.bloodmagic.BloodMagic;
public class BloodMagicLootConditions
{
public static final LootConditionType INVERTED = Registry.register(Registry.LOOT_CONDITION_TYPE, BloodMagic.rl("testing"), new LootConditionType(new MatchTool.Serializer()));
static
{
}
}

View file

@ -0,0 +1,149 @@
package wayoftime.bloodmagic.loot;
import java.util.List;
import javax.annotation.Nonnull;
import com.google.gson.JsonObject;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.enchantment.Enchantments;
import net.minecraft.item.ItemStack;
import net.minecraft.loot.LootContext;
import net.minecraft.loot.LootParameterSets;
import net.minecraft.loot.LootParameters;
import net.minecraft.loot.LootTable;
import net.minecraft.loot.conditions.ILootCondition;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.loot.GlobalLootModifierSerializer;
import net.minecraftforge.common.loot.LootModifier;
import net.minecraftforge.fml.RegistryObject;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import wayoftime.bloodmagic.BloodMagic;
import wayoftime.bloodmagic.anointment.AnointmentHolder;
import wayoftime.bloodmagic.core.AnointmentRegistrar;
public class GlobalLootModifier
{
public static final DeferredRegister<GlobalLootModifierSerializer<?>> GLM = DeferredRegister.create(ForgeRegistries.LOOT_MODIFIER_SERIALIZERS, BloodMagic.MODID);
public static final RegistryObject<SilkTouchTestModifier.Serializer> SILKTOUCH = GLM.register("silk_touch_bamboo", SilkTouchTestModifier.Serializer::new);
public static final RegistryObject<FortuneModifier.Serializer> FORTUNE = GLM.register("fortune", FortuneModifier.Serializer::new);
private static class SilkTouchTestModifier extends LootModifier
{
public SilkTouchTestModifier(ILootCondition[] conditionsIn)
{
super(conditionsIn);
// System.out.println("Registering silk touch modifier");
}
@Nonnull
@Override
public List<ItemStack> doApply(List<ItemStack> generatedLoot, LootContext context)
{
// System.out.println("Testing to see if we gotta check it~");
ItemStack ctxTool = context.get(LootParameters.TOOL);
// return early if silk-touch is already applied (otherwise we'll get stuck in
// an infinite loop).
if (EnchantmentHelper.getEnchantments(ctxTool).containsKey(Enchantments.SILK_TOUCH))
return generatedLoot;
AnointmentHolder holder = AnointmentHolder.fromItemStack(ctxTool);
if (holder == null || holder.getAnointmentLevel(AnointmentRegistrar.ANOINTMENT_SILK_TOUCH.get()) <= 0)
{
return generatedLoot;
}
ItemStack fakeTool = ctxTool.copy();
fakeTool.addEnchantment(Enchantments.SILK_TOUCH, 1);
LootContext.Builder builder = new LootContext.Builder(context);
builder.withParameter(LootParameters.TOOL, fakeTool);
LootContext ctx = builder.build(LootParameterSets.BLOCK);
LootTable loottable = context.getWorld().getServer().getLootTableManager().getLootTableFromLocation(context.get(LootParameters.BLOCK_STATE).getBlock().getLootTable());
return loottable.generate(ctx);
}
private static class Serializer extends GlobalLootModifierSerializer<SilkTouchTestModifier>
{
@Override
public SilkTouchTestModifier read(ResourceLocation name, JsonObject json, ILootCondition[] conditionsIn)
{
return new SilkTouchTestModifier(conditionsIn);
}
@Override
public JsonObject write(SilkTouchTestModifier instance)
{
return makeConditions(instance.conditions);
}
}
}
private static class FortuneModifier extends LootModifier
{
public FortuneModifier(ILootCondition[] conditionsIn)
{
super(conditionsIn);
// System.out.println("Registering silk touch modifier");
}
// List<ItemStack> bufferList = new ArrayList<ItemStack>();
@Nonnull
@Override
public List<ItemStack> doApply(List<ItemStack> generatedLoot, LootContext context)
{
ItemStack ctxTool = context.get(LootParameters.TOOL);
// return early if silk-touch is already applied (otherwise we'll get stuck in
// an infinite loop).
if (ctxTool.getTag() != null && ctxTool.getTag().getBoolean("bloodmagic:checked_fortune"))
{
return generatedLoot;
}
if (EnchantmentHelper.getEnchantments(ctxTool).containsKey(Enchantments.SILK_TOUCH))
return generatedLoot;
AnointmentHolder holder = AnointmentHolder.fromItemStack(ctxTool);
if (holder == null)
{
return generatedLoot;
}
int additionalFortune = holder.getAnointmentLevel(AnointmentRegistrar.ANOINTMENT_FORTUNE.get());
if (additionalFortune <= 0)
{
return generatedLoot;
}
if (holder.getAnointmentLevel(AnointmentRegistrar.ANOINTMENT_SILK_TOUCH.get()) > 0)
{
return generatedLoot;
}
ItemStack fakeTool = ctxTool.copy();
fakeTool.getOrCreateTag().putBoolean("bloodmagic:checked_fortune", true);
int baseFortuneLevel = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, ctxTool);
fakeTool.addEnchantment(Enchantments.FORTUNE, baseFortuneLevel + additionalFortune);
LootContext.Builder builder = new LootContext.Builder(context);
builder.withParameter(LootParameters.TOOL, fakeTool);
LootContext ctx = builder.build(LootParameterSets.BLOCK);
LootTable loottable = context.getWorld().getServer().getLootTableManager().getLootTableFromLocation(context.get(LootParameters.BLOCK_STATE).getBlock().getLootTable());
return loottable.generate(ctx);
}
private static class Serializer extends GlobalLootModifierSerializer<FortuneModifier>
{
@Override
public FortuneModifier read(ResourceLocation name, JsonObject json, ILootCondition[] conditionsIn)
{
return new FortuneModifier(conditionsIn);
}
@Override
public JsonObject write(FortuneModifier instance)
{
return makeConditions(instance.conditions);
}
}
}
}

View file

@ -26,6 +26,7 @@ import net.minecraftforge.event.entity.living.LivingEvent.LivingJumpEvent;
import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
import net.minecraftforge.event.entity.living.LivingHealEvent;
import net.minecraftforge.event.entity.living.LivingHurtEvent;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.entity.player.PlayerXpEvent;
@ -35,11 +36,13 @@ import net.minecraftforge.eventbus.api.EventPriority;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import wayoftime.bloodmagic.BloodMagic;
import wayoftime.bloodmagic.anointment.AnointmentHolder;
import wayoftime.bloodmagic.common.block.BloodMagicBlocks;
import wayoftime.bloodmagic.common.item.BloodOrb;
import wayoftime.bloodmagic.common.item.IBindable;
import wayoftime.bloodmagic.common.item.IBloodOrb;
import wayoftime.bloodmagic.common.item.ItemExperienceBook;
import wayoftime.bloodmagic.core.AnointmentRegistrar;
import wayoftime.bloodmagic.core.LivingArmorRegistrar;
import wayoftime.bloodmagic.core.data.Binding;
import wayoftime.bloodmagic.core.data.SoulNetwork;
@ -135,6 +138,16 @@ public class GenericHandler
double additionalDamage = LivingUtil.getAdditionalDamage(sourcePlayer, mainWeapon, living, event.getAmount());
event.setAmount((float) (event.getAmount() + additionalDamage));
}
ItemStack heldStack = sourcePlayer.getHeldItemMainhand();
AnointmentHolder holder = AnointmentHolder.fromItemStack(heldStack);
if (holder != null)
{
double additionalDamage = holder.getAdditionalDamage(sourcePlayer, heldStack, event.getAmount(), living);
event.setAmount((float) (event.getAmount() + additionalDamage));
}
}
if (living instanceof PlayerEntity)
@ -165,6 +178,16 @@ public class GenericHandler
LivingUtil.applyNewExperience(sourcePlayer, LivingArmorRegistrar.UPGRADE_SPRINT_ATTACK.get(), event.getAmount());
}
}
ItemStack heldStack = sourcePlayer.getHeldItemMainhand();
AnointmentHolder holder = AnointmentHolder.fromItemStack(heldStack);
// AnointmentHolder holder = AnointmentHolder.fromPlayer(sourcePlayer, Hand.MAIN_HAND);
// System.out.println("Checking consumption. Holder is: " + holder);
if (holder != null && holder.consumeAnointmentDurabilityOnHit(heldStack, EquipmentSlotType.MAINHAND))
{
holder.toItemStack(heldStack);
}
}
if (living instanceof PlayerEntity)
@ -475,6 +498,22 @@ public class GenericHandler
player.addPotionEffect(new EffectInstance(Effects.HASTE, mineTime, LivingArmorRegistrar.UPGRADE_DIGGING.get().getBonusValue("speed_level", stats.getLevel(LivingArmorRegistrar.UPGRADE_DIGGING.get().getKey())).intValue(), true, false));
}
}
ItemStack heldStack = player.getHeldItemMainhand();
AnointmentHolder holder = AnointmentHolder.fromItemStack(heldStack);
if (holder != null)
{
if (holder.getAnointmentLevel(AnointmentRegistrar.ANOINTMENT_SILK_TOUCH.get()) >= 1)
{
int bonusLevel = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, player.getHeldItemMainhand());
int exp = event.getState().getExpDrop(event.getWorld(), event.getPos(), bonusLevel, holder.getAnointmentLevel(AnointmentRegistrar.ANOINTMENT_SILK_TOUCH.get()));
event.setExpToDrop(exp);
}
if (holder.consumeAnointmentDurabilityOnHarvest(heldStack, EquipmentSlotType.MAINHAND))
holder.toItemStack(heldStack);
}
}
}
@ -497,4 +536,12 @@ public class GenericHandler
}
}
}
@SubscribeEvent
public void appendTooltip(ItemTooltipEvent event)
{
ItemStack stack = event.getItemStack();
AnointmentHolder holder = AnointmentHolder.fromItemStack(stack);
AnointmentHolder.appendAnointmentTooltip(holder, event.getToolTip());
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 316 B

View file

@ -0,0 +1,11 @@
{
"type": "bloodmagic:fortune",
"conditions": [
{
"condition": "minecraft:match_tool",
"predicate": {
}
}
]
}

View file

@ -0,0 +1,11 @@
{
"type": "bloodmagic:silk_touch_bamboo",
"conditions": [
{
"condition": "minecraft:match_tool",
"predicate": {
}
}
]
}

View file

@ -0,0 +1,7 @@
{
"replace": false,
"entries": [
"bloodmagic:silk_touch_bamboo",
"bloodmagic:fortune"
]
}