use of net.minecraft.loot.LootTableManager in project minecolonies by ldtteam.
the class LootTableAnalyzer method toDrops.
public static List<LootDrop> toDrops(@NotNull final LootTableManager lootTableManager, @NotNull final JsonObject lootTableJson) {
final List<LootDrop> drops = new ArrayList<>();
if (!lootTableJson.has("pools")) {
return drops;
}
final JsonArray pools = JSONUtils.getAsJsonArray(lootTableJson, "pools");
for (final JsonElement pool : pools) {
final JsonArray entries = JSONUtils.getAsJsonArray(pool.getAsJsonObject(), "entries", new JsonArray());
final float totalWeight = StreamSupport.stream(entries.spliterator(), false).filter(entry -> {
final String type = JSONUtils.getAsString(entry.getAsJsonObject(), "type");
return type.equals("minecraft:empty") || type.equals("minecraft:item") || type.equals("minecraft:tag") || type.equals("minecraft:loot_table");
}).mapToInt(entry -> JSONUtils.getAsInt(entry.getAsJsonObject(), "weight", 1)).sum();
for (final JsonElement ej : entries) {
final JsonObject entryJson = ej.getAsJsonObject();
final String type = JSONUtils.getAsString(entryJson, "type");
if (type.equals("minecraft:item")) {
final Item item = ForgeRegistries.ITEMS.getValue(new ResourceLocation(JSONUtils.getAsString(entryJson, "name")));
final float weight = JSONUtils.getAsFloat(entryJson, "weight", 1);
final float quality = JSONUtils.getAsFloat(entryJson, "quality", 0);
float modifier = 1.0F;
final boolean conditional = JSONUtils.getAsJsonArray(entryJson, "conditions", new JsonArray()).size() > 0;
ItemStack stack = new ItemStack(item);
if (entryJson.has("functions")) {
final Tuple<ItemStack, Float> result = processFunctions(stack, JSONUtils.getAsJsonArray(entryJson, "functions"));
stack = result.getA();
modifier = result.getB();
}
if (stack.getItem().equals(ModItems.adventureToken)) {
final List<LootDrop> mobDrops = expandAdventureToken(lootTableManager, stack);
for (final LootTableAnalyzer.LootDrop drop : mobDrops) {
drops.add(new LootDrop(drop.getItemStacks(), drop.getProbability() * (weight / totalWeight), drop.getQuality() + quality, drop.getConditional() || conditional));
}
} else {
drops.add(new LootDrop(Collections.singletonList(stack), weight / totalWeight * modifier, quality, conditional));
}
} else if (type.equals("minecraft:loot_table")) {
final ResourceLocation table = new ResourceLocation(JSONUtils.getAsString(entryJson, "name"));
final List<LootTableAnalyzer.LootDrop> tableDrops = toDrops(lootTableManager, table);
final float weight = JSONUtils.getAsFloat(entryJson, "weight", 1);
final float quality = JSONUtils.getAsFloat(entryJson, "quality", 0);
final boolean conditional = JSONUtils.getAsJsonArray(entryJson, "conditions", new JsonArray()).size() > 0;
for (final LootTableAnalyzer.LootDrop drop : tableDrops) {
drops.add(new LootDrop(drop.getItemStacks(), drop.getProbability() * (weight / totalWeight), drop.getQuality() + quality, drop.getConditional() || conditional));
}
}
}
}
drops.sort(Comparator.comparing(LootDrop::getProbability).reversed());
return drops;
}
use of net.minecraft.loot.LootTableManager in project minecolonies by ldtteam.
the class GatherDataHandler method dataGeneratorSetup.
/**
* This method is for adding datagenerators. this does not run during normal client operations, only during building.
*
* @param event event sent when you run the "runData" gradle task
*/
public static void dataGeneratorSetup(final GatherDataEvent event) {
final DataGenerator generator = event.getGenerator();
final LootTableManager lootTableManager = new DatagenLootTableManager(event.getExistingFileHelper());
final BlockTagsProvider blockTagsProvider = new DefaultBlockTagsProvider(generator, event.getExistingFileHelper());
generator.addProvider(new DefaultBlockLootTableProvider(generator));
generator.addProvider(new DefaultAdvancementsProvider(generator, event.getExistingFileHelper()));
generator.addProvider(new DefaultSoundProvider(generator));
generator.addProvider(blockTagsProvider);
generator.addProvider(new DefaultItemTagsProvider(generator, blockTagsProvider, event.getExistingFileHelper()));
generator.addProvider(new DefaultEntityTypeTagsProvider(generator, event.getExistingFileHelper()));
generator.addProvider(new DefaultResearchProvider(generator));
generator.addProvider(new DefaultRecipeProvider(generator));
generator.addProvider(new SawmillTimberFrameRecipeProvider(generator));
generator.addProvider(new DefaultSifterCraftingProvider(generator, lootTableManager));
generator.addProvider(new DefaultEnchanterCraftingProvider(generator));
generator.addProvider(new DefaultFishermanLootProvider(generator));
generator.addProvider(new DefaultConcreteMixerCraftingProvider(generator));
generator.addProvider(new DefaultNetherWorkerLootProvider(generator, lootTableManager));
}
Aggregations