Class LootModifier

java.lang.Object
io.github.vampirestudios.vampirelib.loot.LootModifier
All Implemented Interfaces:
IGlobalLootModifier

public abstract class LootModifier extends Object implements IGlobalLootModifier
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final net.minecraft.world.level.storage.loot.predicates.LootItemCondition[]
     

    Fields inherited from interface io.github.vampirestudios.vampirelib.loot.IGlobalLootModifier

    DIRECT_CODEC, LOOT_CONDITIONS_CODEC
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    LootModifier(net.minecraft.world.level.storage.loot.predicates.LootItemCondition[] conditionsIn)
    Constructs a LootModifier.
  • Method Summary

    Modifier and Type
    Method
    Description
    final @NotNull it.unimi.dsi.fastutil.objects.ObjectArrayList<net.minecraft.world.item.ItemStack>
    apply(it.unimi.dsi.fastutil.objects.ObjectArrayList<net.minecraft.world.item.ItemStack> generatedLoot, net.minecraft.world.level.storage.loot.LootContext context)
     
    protected static <T extends LootModifier>
    com.mojang.datafixers.Products.P1<com.mojang.serialization.codecs.RecordCodecBuilder.Mu<T>,net.minecraft.world.level.storage.loot.predicates.LootItemCondition[]>
    codecStart(com.mojang.serialization.codecs.RecordCodecBuilder.Instance<T> instance)
    Simplifies codec creation, especially if no other fields are added:
    protected abstract @NotNull it.unimi.dsi.fastutil.objects.ObjectArrayList<net.minecraft.world.item.ItemStack>
    doApply(it.unimi.dsi.fastutil.objects.ObjectArrayList<net.minecraft.world.item.ItemStack> generatedLoot, net.minecraft.world.level.storage.loot.LootContext context)
    Applies the modifier to the generated loot (all loot conditions have already been checked and have returned true).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface io.github.vampirestudios.vampirelib.loot.IGlobalLootModifier

    codec
  • Field Details

    • conditions

      protected final net.minecraft.world.level.storage.loot.predicates.LootItemCondition[] conditions
  • Constructor Details

    • LootModifier

      protected LootModifier(net.minecraft.world.level.storage.loot.predicates.LootItemCondition[] conditionsIn)
      Constructs a LootModifier.
      Parameters:
      conditionsIn - the ILootConditions that need to be matched before the loot is modified.
  • Method Details

    • codecStart

      protected static <T extends LootModifier> com.mojang.datafixers.Products.P1<com.mojang.serialization.codecs.RecordCodecBuilder.Mu<T>,net.minecraft.world.level.storage.loot.predicates.LootItemCondition[]> codecStart(com.mojang.serialization.codecs.RecordCodecBuilder.Instance<T> instance)
      Simplifies codec creation, especially if no other fields are added:

      public static final Codec<MyLootModifier> CODEC = RecordCodecBuilder.create(inst -> codecStart(inst).apply(inst, MyLootModifier::new));

      Otherwise can follow this with #and() to add more fields. Examples: Forge Test Subclasses or BendingTrunkPlacer.CODEC
    • apply

      @NotNull public final @NotNull it.unimi.dsi.fastutil.objects.ObjectArrayList<net.minecraft.world.item.ItemStack> apply(it.unimi.dsi.fastutil.objects.ObjectArrayList<net.minecraft.world.item.ItemStack> generatedLoot, net.minecraft.world.level.storage.loot.LootContext context)
      Specified by:
      apply in interface IGlobalLootModifier
    • doApply

      @NotNull protected abstract @NotNull it.unimi.dsi.fastutil.objects.ObjectArrayList<net.minecraft.world.item.ItemStack> doApply(it.unimi.dsi.fastutil.objects.ObjectArrayList<net.minecraft.world.item.ItemStack> generatedLoot, net.minecraft.world.level.storage.loot.LootContext context)
      Applies the modifier to the generated loot (all loot conditions have already been checked and have returned true).
      Parameters:
      generatedLoot - the list of ItemStacks that will be dropped, generated by loot tables
      context - the LootContext, identical to what is passed to loot tables
      Returns:
      modified loot drops