Skip to content

Commit

Permalink
Fix block drops
Browse files Browse the repository at this point in the history
  • Loading branch information
lukebemish committed Jul 5, 2024
1 parent c93dfa7 commit f15b681
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,9 @@ public static synchronized void initPostRegister() {
if (modifier.variantFilter.matches(ore, stone, entry.getKey().location())) {
for (ResourceLocation tag : modifier.tags) {
if (tag.getPath().startsWith("block/"))
planBlockTag(tag.withPath(tag.getPath().substring(7)), entry.getKey().location());
planBlockTag(tag.withPath(tag.getPath().substring("block/".length())), entry.getKey().location());
else if (tag.getPath().startsWith("item/"))
planItemTag(tag.withPath(tag.getPath().substring(6)), entry.getKey().location());
planItemTag(tag.withPath(tag.getPath().substring("item/".length())), entry.getKey().location());
else
LOGGER.warn("Unknown tag type: " + tag);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import dev.lukebemish.dynamicassetgenerator.api.templates.TagFile;
import dev.lukebemish.excavatedvariants.api.data.Ore;
import dev.lukebemish.excavatedvariants.api.data.Stone;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagEntry;
Expand All @@ -30,25 +31,27 @@ public void add(String fullId, Ore ore, Stone stone) {
toCheck.add(new CheckPair(fullId, ore, stone));
}

private Set<ResourceLocation> getMiningLevels(ResourceGenerationContext context) {
return KnownTiers.KNOWN_TIERS.keySet().stream().map(TagKey::location).collect(Collectors.toSet());
private Set<ResourceLocation> getMiningLevels() {
return KnownTiers.KNOWN_TIERS.keySet().stream().map(TagKey::location).map(rl -> rl.withPrefix("block/")).collect(Collectors.toSet());
}

@Override
public Map<ResourceLocation, Set<ResourceLocation>> apply(ResourceGenerationContext context) {
Map<ResourceLocation, Set<ResourceLocation>> tags = new HashMap<>();

Set<ResourceLocation> tagNames = getMiningLevels(context);
Set<ResourceLocation> tagNames = getMiningLevels();
Map<ResourceLocation, Set<ResourceLocation>> tagToMemberMap = tagNames.stream().collect(Collectors.toMap(Function.identity(), name -> getTagMembers(name, context), (l1, l2) -> {
Set<ResourceLocation> out = new HashSet<>(l1);
out.addAll(l2);
return out;
}));

for (ResourceLocation tierTag : tagNames) {
System.out.println("Checking tag: "+tierTag);
var members = tagToMemberMap.get(tierTag);
System.out.println("Members: "+members.stream().toList());
for (var pair : toCheck) {
if (members.contains(pair.stone.block.location()) || pair.ore.getBlocks().keySet().stream().map(ResourceKey::location).allMatch(members::contains)) {
if (members.contains(pair.stone.block.location()) || pair.ore.getGeneratingBlocks().keySet().stream().filter(BuiltInRegistries.BLOCK::containsKey).map(ResourceKey::location).allMatch(members::contains)) {
tags.computeIfAbsent(tierTag, k->new HashSet<>()).add(ResourceLocation.fromNamespaceAndPath(ExcavatedVariants.MOD_ID, pair.fullId));
}
}
Expand All @@ -74,15 +77,15 @@ private Set<ResourceLocation> getTagMembers(ResourceLocation location, ResourceG
if (file.replace())
members.clear();
file.values().forEach(value ->
value.build(new TagEntry.Lookup<ResourceLocation>() {
value.build(new TagEntry.Lookup<>() {
@Override
public ResourceLocation element(ResourceLocation elementLocation) {
return elementLocation;
}

@Override
public Collection<ResourceLocation> tag(ResourceLocation tagLocation) {
return getTagMembers(ResourceLocation.fromNamespaceAndPath(tagLocation.getNamespace(), type+"/"+tagLocation.getPath()), context);
return getTagMembers(ResourceLocation.fromNamespaceAndPath(tagLocation.getNamespace(), type + "/" + tagLocation.getPath()), context);
}
}, members::add)
);
Expand Down

0 comments on commit f15b681

Please sign in to comment.