Skip to content

Commit

Permalink
Make loot tables pass validation correctly
Browse files Browse the repository at this point in the history
We need to load vanilla's tables as well, so the fitted carpets can
redirect to those tables
  • Loading branch information
TeamSpen210 committed Dec 26, 2019
1 parent c4405ff commit 1273d51
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Expand Up @@ -34,12 +34,17 @@ public class InspirationsBlockLootTable extends BlockLootTables {
@Override
protected Iterable<Block> getKnownBlocks() {
return ForgeRegistries.BLOCKS.getValues().stream()
.filter((block) -> block.getRegistryName().getNamespace().equals(Inspirations.modID))
.filter((block) -> {
String ns = block.getRegistryName().getNamespace();
return ns.equals(Inspirations.modID) || ns.equals("minecraft");
})
.collect(Collectors.toList());
}

@Override
protected void addTables() {
super.addTables();

addIf(InspirationsBuilding.pulseID, this::addBuilding);
addIf(InspirationsTools.pulseID, this::addTools);
addIf(InspirationsTweaks.pulseID, this::addTweaks);
Expand Down
Expand Up @@ -2,6 +2,7 @@

import com.google.common.collect.ImmutableList;
import com.mojang.datafixers.util.Pair;
import knightminer.inspirations.Inspirations;
import net.minecraft.data.DataGenerator;
import net.minecraft.data.LootTableProvider;
import net.minecraft.util.ResourceLocation;
Expand All @@ -11,6 +12,8 @@
import net.minecraft.world.storage.loot.LootTableManager;
import net.minecraft.world.storage.loot.ValidationResults;

import javax.annotation.Nonnull;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.BiConsumer;
Expand All @@ -22,6 +25,13 @@ public InspirationsLootTableProvider(DataGenerator gen) {
super(gen);
}

@Nonnull
@Override
public String getName() {
return "Inspirations Loot Tables";
}

@Nonnull
@Override
protected List<Pair<Supplier<Consumer<BiConsumer<ResourceLocation, LootTable.Builder>>>, LootParameterSet>> getTables() {
return ImmutableList.of(
Expand All @@ -32,8 +42,15 @@ protected List<Pair<Supplier<Consumer<BiConsumer<ResourceLocation, LootTable.Bui
// Override to skip validating that vanilla's tables are present.
@Override
protected void validate(Map<ResourceLocation, LootTable> map, ValidationResults validationresults) {
Map<ResourceLocation, LootTable> kept = new HashMap<>();
map.forEach((loc, table) -> {
LootTableManager.func_215302_a(validationresults, loc, table, map::get);
if (loc.getNamespace().equals(Inspirations.modID)) {
LootTableManager.func_215302_a(validationresults, loc, table, map::get);
kept.put(loc, table);
}
});
// Remove vanilla's tables, which we also loaded so we can redirect stuff to them.
map.clear();
map.putAll(kept);
}
}

0 comments on commit 1273d51

Please sign in to comment.