Skip to content

Commit

Permalink
Fixed Water Protection enchanted books not being usable
Browse files Browse the repository at this point in the history
  • Loading branch information
apace100 committed Aug 25, 2020
1 parent 2c2c1e3 commit a5546a2
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions src/main/java/io/github/apace100/origins/registry/ModLoot.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

import net.fabricmc.fabric.api.loot.v1.FabricLootPoolBuilder;
import net.fabricmc.fabric.api.loot.v1.event.LootTableLoadingCallback;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentLevelEntry;
import net.minecraft.item.EnchantedBookItem;
import net.minecraft.item.Items;
import net.minecraft.loot.ConstantLootTableRange;
import net.minecraft.loot.entry.EmptyEntry;
import net.minecraft.loot.entry.ItemEntry;
import net.minecraft.loot.function.SetNbtLootFunction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.util.Identifier;

public class ModLoot {
Expand All @@ -19,9 +21,9 @@ public class ModLoot {
private static final Identifier WATER_RUIN = new Identifier("minecraft", "chests/underwater_ruin_small");

public static void register() {
CompoundTag waterProtectionLevel1 = createEnchantmentTag("origins:water_protection", 1);
CompoundTag waterProtectionLevel2 = createEnchantmentTag("origins:water_protection", 2);
CompoundTag waterProtectionLevel3 = createEnchantmentTag("origins:water_protection", 3);
CompoundTag waterProtectionLevel1 = createEnchantmentTag(ModEnchantments.WATER_PROTECTION, 1);
CompoundTag waterProtectionLevel2 = createEnchantmentTag(ModEnchantments.WATER_PROTECTION, 2);
CompoundTag waterProtectionLevel3 = createEnchantmentTag(ModEnchantments.WATER_PROTECTION, 3);
LootTableLoadingCallback.EVENT.register(((resourceManager, lootManager, identifier, fabricLootSupplierBuilder, lootTableSetter) -> {
if(DUNGEON_LOOT.equals(identifier)) {
FabricLootPoolBuilder lootPool = FabricLootPoolBuilder.builder()
Expand Down Expand Up @@ -71,14 +73,8 @@ public static void register() {
}));
}

private static CompoundTag createEnchantmentTag(String enchantmentId, int level) {
CompoundTag enchantmentTag = new CompoundTag();
ListTag tag = new ListTag();
CompoundTag tmp = new CompoundTag();
tmp.putString("id", enchantmentId);
tmp.putInt("lvl", level);
tag.add(tmp);
enchantmentTag.put("Enchantments", tag);
return enchantmentTag;
private static CompoundTag createEnchantmentTag(Enchantment enchantment, int level) {
EnchantmentLevelEntry entry = new EnchantmentLevelEntry(enchantment, level);
return EnchantedBookItem.forEnchantment(entry).getTag();
}
}

0 comments on commit a5546a2

Please sign in to comment.