133 lines
6.4 KiB
Java
133 lines
6.4 KiB
Java
package net.minecraft.data.loot.packs;
|
|
|
|
import java.util.function.BiConsumer;
|
|
import net.minecraft.core.Holder;
|
|
import net.minecraft.core.HolderLookup;
|
|
import net.minecraft.core.component.DataComponents;
|
|
import net.minecraft.core.registries.Registries;
|
|
import net.minecraft.data.loot.LootTableSubProvider;
|
|
import net.minecraft.resources.ResourceKey;
|
|
import net.minecraft.world.item.Item;
|
|
import net.minecraft.world.item.Items;
|
|
import net.minecraft.world.item.armortrim.ArmorTrim;
|
|
import net.minecraft.world.item.armortrim.TrimMaterial;
|
|
import net.minecraft.world.item.armortrim.TrimMaterials;
|
|
import net.minecraft.world.item.armortrim.TrimPattern;
|
|
import net.minecraft.world.item.armortrim.TrimPatterns;
|
|
import net.minecraft.world.item.enchantment.Enchantment;
|
|
import net.minecraft.world.item.enchantment.Enchantments;
|
|
import net.minecraft.world.level.storage.loot.BuiltInLootTables;
|
|
import net.minecraft.world.level.storage.loot.LootPool;
|
|
import net.minecraft.world.level.storage.loot.LootTable;
|
|
import net.minecraft.world.level.storage.loot.entries.LootItem;
|
|
import net.minecraft.world.level.storage.loot.entries.NestedLootTable;
|
|
import net.minecraft.world.level.storage.loot.functions.SetComponentsFunction;
|
|
import net.minecraft.world.level.storage.loot.functions.SetEnchantmentsFunction;
|
|
import net.minecraft.world.level.storage.loot.predicates.LootItemRandomChanceCondition;
|
|
import net.minecraft.world.level.storage.loot.providers.number.ConstantValue;
|
|
|
|
public record VanillaEquipmentLoot(HolderLookup.Provider registries) implements LootTableSubProvider {
|
|
@Override
|
|
public void generate(BiConsumer<ResourceKey<LootTable>, LootTable.Builder> biConsumer) {
|
|
HolderLookup.RegistryLookup<TrimPattern> registryLookup = (HolderLookup.RegistryLookup<TrimPattern>)this.registries
|
|
.lookup(Registries.TRIM_PATTERN)
|
|
.orElseThrow();
|
|
HolderLookup.RegistryLookup<TrimMaterial> registryLookup2 = (HolderLookup.RegistryLookup<TrimMaterial>)this.registries
|
|
.lookup(Registries.TRIM_MATERIAL)
|
|
.orElseThrow();
|
|
HolderLookup.RegistryLookup<Enchantment> registryLookup3 = this.registries.lookupOrThrow(Registries.ENCHANTMENT);
|
|
ArmorTrim armorTrim = new ArmorTrim(
|
|
(Holder<TrimMaterial>)registryLookup2.get(TrimMaterials.COPPER).orElseThrow(), (Holder<TrimPattern>)registryLookup.get(TrimPatterns.FLOW).orElseThrow()
|
|
);
|
|
ArmorTrim armorTrim2 = new ArmorTrim(
|
|
(Holder<TrimMaterial>)registryLookup2.get(TrimMaterials.COPPER).orElseThrow(), (Holder<TrimPattern>)registryLookup.get(TrimPatterns.BOLT).orElseThrow()
|
|
);
|
|
biConsumer.accept(
|
|
BuiltInLootTables.EQUIPMENT_TRIAL_CHAMBER,
|
|
LootTable.lootTable()
|
|
.withPool(
|
|
LootPool.lootPool()
|
|
.setRolls(ConstantValue.exactly(1.0F))
|
|
.add(
|
|
NestedLootTable.inlineLootTable(trialChamberEquipment(Items.CHAINMAIL_HELMET, Items.CHAINMAIL_CHESTPLATE, armorTrim2, registryLookup3).build())
|
|
.setWeight(4)
|
|
)
|
|
.add(NestedLootTable.inlineLootTable(trialChamberEquipment(Items.IRON_HELMET, Items.IRON_CHESTPLATE, armorTrim, registryLookup3).build()).setWeight(2))
|
|
.add(
|
|
NestedLootTable.inlineLootTable(trialChamberEquipment(Items.DIAMOND_HELMET, Items.DIAMOND_CHESTPLATE, armorTrim, registryLookup3).build()).setWeight(1)
|
|
)
|
|
)
|
|
);
|
|
biConsumer.accept(
|
|
BuiltInLootTables.EQUIPMENT_TRIAL_CHAMBER_MELEE,
|
|
LootTable.lootTable()
|
|
.withPool(LootPool.lootPool().setRolls(ConstantValue.exactly(1.0F)).add(NestedLootTable.lootTableReference(BuiltInLootTables.EQUIPMENT_TRIAL_CHAMBER)))
|
|
.withPool(
|
|
LootPool.lootPool()
|
|
.setRolls(ConstantValue.exactly(1.0F))
|
|
.add(LootItem.lootTableItem(Items.IRON_SWORD).setWeight(4))
|
|
.add(
|
|
LootItem.lootTableItem(Items.IRON_SWORD)
|
|
.apply(new SetEnchantmentsFunction.Builder().withEnchantment(registryLookup3.getOrThrow(Enchantments.SHARPNESS), ConstantValue.exactly(1.0F)))
|
|
)
|
|
.add(
|
|
LootItem.lootTableItem(Items.IRON_SWORD)
|
|
.apply(new SetEnchantmentsFunction.Builder().withEnchantment(registryLookup3.getOrThrow(Enchantments.KNOCKBACK), ConstantValue.exactly(1.0F)))
|
|
)
|
|
.add(LootItem.lootTableItem(Items.DIAMOND_SWORD))
|
|
)
|
|
);
|
|
biConsumer.accept(
|
|
BuiltInLootTables.EQUIPMENT_TRIAL_CHAMBER_RANGED,
|
|
LootTable.lootTable()
|
|
.withPool(LootPool.lootPool().setRolls(ConstantValue.exactly(1.0F)).add(NestedLootTable.lootTableReference(BuiltInLootTables.EQUIPMENT_TRIAL_CHAMBER)))
|
|
.withPool(
|
|
LootPool.lootPool()
|
|
.setRolls(ConstantValue.exactly(1.0F))
|
|
.add(LootItem.lootTableItem(Items.BOW).setWeight(2))
|
|
.add(
|
|
LootItem.lootTableItem(Items.BOW)
|
|
.apply(new SetEnchantmentsFunction.Builder().withEnchantment(registryLookup3.getOrThrow(Enchantments.POWER), ConstantValue.exactly(1.0F)))
|
|
)
|
|
.add(
|
|
LootItem.lootTableItem(Items.BOW)
|
|
.apply(new SetEnchantmentsFunction.Builder().withEnchantment(registryLookup3.getOrThrow(Enchantments.PUNCH), ConstantValue.exactly(1.0F)))
|
|
)
|
|
)
|
|
);
|
|
}
|
|
|
|
public static LootTable.Builder trialChamberEquipment(Item helmet, Item chestplate, ArmorTrim trim, HolderLookup.RegistryLookup<Enchantment> enchantments) {
|
|
return LootTable.lootTable()
|
|
.withPool(
|
|
LootPool.lootPool()
|
|
.setRolls(ConstantValue.exactly(1.0F))
|
|
.when(LootItemRandomChanceCondition.randomChance(0.5F))
|
|
.add(
|
|
LootItem.lootTableItem(helmet)
|
|
.apply(SetComponentsFunction.setComponent(DataComponents.TRIM, trim))
|
|
.apply(
|
|
new SetEnchantmentsFunction.Builder()
|
|
.withEnchantment(enchantments.getOrThrow(Enchantments.PROTECTION), ConstantValue.exactly(4.0F))
|
|
.withEnchantment(enchantments.getOrThrow(Enchantments.PROJECTILE_PROTECTION), ConstantValue.exactly(4.0F))
|
|
.withEnchantment(enchantments.getOrThrow(Enchantments.FIRE_PROTECTION), ConstantValue.exactly(4.0F))
|
|
)
|
|
)
|
|
)
|
|
.withPool(
|
|
LootPool.lootPool()
|
|
.setRolls(ConstantValue.exactly(1.0F))
|
|
.when(LootItemRandomChanceCondition.randomChance(0.5F))
|
|
.add(
|
|
LootItem.lootTableItem(chestplate)
|
|
.apply(SetComponentsFunction.setComponent(DataComponents.TRIM, trim))
|
|
.apply(
|
|
new SetEnchantmentsFunction.Builder()
|
|
.withEnchantment(enchantments.getOrThrow(Enchantments.PROTECTION), ConstantValue.exactly(4.0F))
|
|
.withEnchantment(enchantments.getOrThrow(Enchantments.PROJECTILE_PROTECTION), ConstantValue.exactly(4.0F))
|
|
.withEnchantment(enchantments.getOrThrow(Enchantments.FIRE_PROTECTION), ConstantValue.exactly(4.0F))
|
|
)
|
|
)
|
|
);
|
|
}
|
|
}
|