2022-10-11 17:19:50 +02:00
|
|
|
package com.minelittlepony.unicopia;
|
|
|
|
|
2024-01-29 17:35:08 +01:00
|
|
|
import java.util.Set;
|
|
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
import com.google.common.collect.Sets;
|
2023-11-02 16:47:45 +01:00
|
|
|
import com.minelittlepony.unicopia.ability.magic.spell.trait.SpellTraits;
|
2023-09-02 19:34:57 +02:00
|
|
|
import com.minelittlepony.unicopia.entity.mob.AirBalloonEntity;
|
|
|
|
import com.minelittlepony.unicopia.entity.mob.UEntities;
|
2023-08-13 11:04:09 +02:00
|
|
|
|
|
|
|
import net.minecraft.entity.vehicle.BoatEntity;
|
2023-11-02 16:47:45 +01:00
|
|
|
import net.minecraft.registry.Registries;
|
2024-01-29 17:35:08 +01:00
|
|
|
import net.minecraft.registry.tag.TagKey;
|
|
|
|
import net.minecraft.util.Identifier;
|
2023-08-13 11:04:09 +02:00
|
|
|
import net.minecraft.world.World;
|
2024-01-29 17:35:08 +01:00
|
|
|
import net.minecraft.world.dimension.DimensionTypes;
|
2023-08-13 11:04:09 +02:00
|
|
|
|
2022-12-04 20:13:57 +01:00
|
|
|
public interface Debug {
|
2023-08-13 11:04:09 +02:00
|
|
|
boolean SPELLBOOK_CHAPTERS = Boolean.getBoolean("unicopia.debug.spellbookChapters");
|
|
|
|
boolean CHECK_GAME_VALUES = Boolean.getBoolean("unicopia.debug.checkGameValues");
|
2024-01-29 17:35:08 +01:00
|
|
|
boolean CHECK_TRAIT_COVERAGE = Boolean.getBoolean("unicopia.debug.checkTraitCoverage");
|
2023-08-13 11:04:09 +02:00
|
|
|
|
2024-01-29 17:35:08 +01:00
|
|
|
AtomicReference<World> LAST_TESTED_WORLD = new AtomicReference<>(null);
|
2023-08-13 11:04:09 +02:00
|
|
|
|
|
|
|
static void runTests(World world) {
|
2024-01-29 17:35:08 +01:00
|
|
|
if (!CHECK_GAME_VALUES || !world.getDimensionKey().getValue().equals(DimensionTypes.OVERWORLD_ID) || (LAST_TESTED_WORLD.getAndSet(world) == world)) {
|
2023-08-13 11:04:09 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-01-29 17:35:08 +01:00
|
|
|
if (CHECK_TRAIT_COVERAGE) {
|
|
|
|
testTraitCoverage();
|
2023-11-02 16:47:45 +01:00
|
|
|
}
|
|
|
|
|
2023-08-13 11:04:09 +02:00
|
|
|
try {
|
|
|
|
for (var type : BoatEntity.Type.values()) {
|
|
|
|
var balloon = UEntities.AIR_BALLOON.create(world);
|
2023-08-14 21:31:33 +02:00
|
|
|
balloon.setBasketType(AirBalloonEntity.BasketType.of(type));
|
2023-08-13 11:04:09 +02:00
|
|
|
balloon.asItem();
|
|
|
|
}
|
|
|
|
} catch (Throwable t) {
|
|
|
|
throw new IllegalStateException("Tests failed", t);
|
|
|
|
}
|
|
|
|
}
|
2024-01-29 17:35:08 +01:00
|
|
|
|
|
|
|
private static void testTraitCoverage() {
|
|
|
|
Registries.ITEM.getEntrySet().stream().collect(Collectors.toMap(
|
|
|
|
entry -> entry.getKey().getValue().getNamespace(),
|
|
|
|
Set::of,
|
|
|
|
Sets::union
|
|
|
|
)).forEach((namespace, entries) -> {
|
|
|
|
@SuppressWarnings("deprecation")
|
|
|
|
var unregistered = entries.stream()
|
|
|
|
.filter(entry -> !entry.getValue().getRegistryEntry().isIn(UTags.HAS_NO_TRAITS) && SpellTraits.of(entry.getValue()).isEmpty())
|
|
|
|
.map(entry -> {
|
|
|
|
String id = entry.getKey().getValue().toString();
|
|
|
|
|
|
|
|
return id + "(" + Registries.ITEM.streamTags()
|
|
|
|
.filter(entry.getValue().getRegistryEntry()::isIn)
|
|
|
|
.map(TagKey::id)
|
|
|
|
.map(Identifier::toString)
|
|
|
|
.collect(Collectors.joining(", ")) + ")";
|
|
|
|
})
|
|
|
|
.toList();
|
|
|
|
|
|
|
|
if (!unregistered.isEmpty()) {
|
|
|
|
Unicopia.LOGGER.warn("No traits registered for {} items in namepsace {} {}", unregistered.size(), namespace, String.join(",\r\n", unregistered));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2022-10-11 17:19:50 +02:00
|
|
|
}
|