Skip to content

Commit

Permalink
added Pocket Sand to the husk loot table
Browse files Browse the repository at this point in the history
  • Loading branch information
Skywalker8510 committed Jul 6, 2024
1 parent adba2ae commit 8d7df2f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/main/java/net/skywalker8510/pocketsand/PocketSand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.fabricmc.api.ModInitializer;

import net.skywalker8510.pocketsand.Item.ModItems;
import net.skywalker8510.pocketsand.util.ModLootTableModifiers;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -13,5 +14,7 @@ public class PocketSand implements ModInitializer {
@Override
public void onInitialize() {
ModItems.registerModItems();
ModLootTableModifiers.modifyLootTables();

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package net.skywalker8510.pocketsand.util;

import net.fabricmc.fabric.api.loot.v2.LootTableEvents;
import net.minecraft.loot.LootPool;
import net.minecraft.loot.condition.RandomChanceLootCondition;
import net.minecraft.loot.entry.ItemEntry;
import net.minecraft.loot.function.SetCountLootFunction;
import net.minecraft.loot.provider.number.ConstantLootNumberProvider;
import net.minecraft.loot.provider.number.UniformLootNumberProvider;
import net.minecraft.util.Identifier;
import net.skywalker8510.pocketsand.Item.ModItems;
import net.skywalker8510.pocketsand.PocketSand;

public class ModLootTableModifiers {

private static final Identifier HUSK_LOOT_TABLE_ID =
new Identifier("minecraft","entities/husk");

public static void modifyLootTables() {

PocketSand.LOGGER.info("Registering Loot Tables for " + PocketSand.MOD_ID);

LootTableEvents.MODIFY.register((key, tableBuilder, source) -> {
// Let's only modify built-in loot tables and leave data pack loot tables untouched by checking the source.
// We also check that the loot table ID is equal to the ID we want.
if (source.isBuiltin() && HUSK_LOOT_TABLE_ID.equals(key)) {
// We make the pool and add an item
LootPool.Builder poolBuilder = LootPool.builder()
.rolls(ConstantLootNumberProvider.create(1))
.conditionally(RandomChanceLootCondition.builder(1f))
.with(ItemEntry.builder(ModItems.POCKET_SAND))
.apply(SetCountLootFunction.builder(UniformLootNumberProvider.create(2.0f, 5.0f)).build());
tableBuilder.pool(poolBuilder.build());
}
});
}
}

0 comments on commit 8d7df2f

Please sign in to comment.