datagen is still incredibly broken but it doesn't matter because we 1.20 now

This commit is contained in:
petrak@ 2023-07-08 15:23:22 -05:00
parent a4a49fd411
commit 60c55d86b1
15 changed files with 123 additions and 118 deletions

View File

@ -4,93 +4,53 @@ import at.petrak.hexcasting.api.HexAPI;
import at.petrak.hexcasting.api.casting.ActionRegistryEntry;
import at.petrak.hexcasting.api.casting.PatternShapeMatch;
import at.petrak.hexcasting.api.casting.castables.SpecialHandler;
import at.petrak.hexcasting.api.casting.math.EulerPathFinder;
import at.petrak.hexcasting.api.casting.math.HexPattern;
import at.petrak.hexcasting.api.mod.HexTags;
import at.petrak.hexcasting.api.utils.HexUtils;
import at.petrak.hexcasting.server.ScrungledPatternsSave;
import at.petrak.hexcasting.xplat.IXplatAbstractions;
import com.mojang.datafixers.util.Pair;
import com.mojang.datafixers.util.Unit;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.level.ServerLevel;
import org.apache.commons.lang3.NotImplementedException;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
// Now an internal-only class used to do final processing on the registered stuff
public class PatternRegistryManifest {
/* Map actions to their entry except for the per-world ones
*
* This can be static because the patterns that are per-world don't change in one server lifecycle.
*/
private static final ConcurrentMap<String, ResourceKey<ActionRegistryEntry>> NORMAL_ACTION_LOOKUP =
new ConcurrentHashMap<>();
/**
* A set of all the per-world patterns. This doesn't store <em>what</em> they are, just that
* they exist.
*/
private static final ConcurrentMap<ResourceKey<ActionRegistryEntry>, Unit> PER_WORLD_ACTIONS =
new ConcurrentHashMap<>();
/**
* Process the registry!
* <p>
* Pass null for the OW to signal we're on the client
* This no longer checks any kind of per-world-pattern-ness because both this and ScrungledPatternsSave depends on
* the other to be done first. lol lmao. It just caches signature->action for the non-per-world-pats
* so it's an O(1) lookup.
*/
// TODO i just realized that logically, this should not be run every time the client/server connects
// just run it on startup, the info gathered here i think is static per world ... except for the per-worldies
// that need to be recalced...
//
// Client is passed in currently for no reason, again will be required for shape-matching
public static void processRegistry(@Nullable ServerLevel overworld) {
ScrungledPatternsSave perWorldPatterns = null;
if (overworld != null) {
perWorldPatterns = ScrungledPatternsSave.open(overworld);
}
var postCalculationNeeders = new ArrayList<ResourceKey<ActionRegistryEntry>>();
int perWorldActionCount = 0;
var registry = IXplatAbstractions.INSTANCE.getActionRegistry();
for (var key : registry.registryKeySet()) {
var entry = registry.get(key);
if (HexUtils.isOfTag(registry, key, HexTags.Actions.PER_WORLD_PATTERN)) {
// We might be double-inserting here, once when the client does it and once when the server does
// However, we do need both to happen (what if it's a dedicated client connecting to a dedicated
// server?)
// hence, a set
PER_WORLD_ACTIONS.put(key, Unit.INSTANCE);
// Then we need to create this only on the server, gulp
if (perWorldPatterns != null) {
var precalced = perWorldPatterns.lookup(entry.prototype().anglesSignature());
if (precalced == null) {
postCalculationNeeders.add(key);
}
} else {
// We're on the client, TODO implement the client guessing code
}
} else {
if (!HexUtils.isOfTag(registry, key, HexTags.Actions.PER_WORLD_PATTERN)) {
NORMAL_ACTION_LOOKUP.put(entry.prototype().anglesSignature(), key);
}
}
if (perWorldPatterns != null) {
for (var postNeederKey : postCalculationNeeders) {
var regiEntry = registry.get(postNeederKey);
var scrungledPat = scrunglePattern(regiEntry.prototype(), overworld.getSeed());
perWorldPatterns.insert(scrungledPat, postNeederKey);
} else {
perWorldActionCount++;
}
}
HexAPI.LOGGER.info(("We're on the %s! " +
"Loaded %d regular actions, %d per-world actions, and %d special handlers").formatted(
(overworld == null) ? "client" : "server", NORMAL_ACTION_LOOKUP.size(), PER_WORLD_ACTIONS.size(),
(overworld == null) ? "client" : "server", NORMAL_ACTION_LOOKUP.size(), perWorldActionCount,
IXplatAbstractions.INSTANCE.getSpecialHandlerRegistry().size()
));
}
@ -159,21 +119,4 @@ public class PatternRegistryManifest {
var entry = pair.getSecond();
return HexPattern.fromAngles(sig, entry.canonicalStartDir());
}
/**
* Get the IDs of all the patterns marked as per-world
*/
public static Collection<ResourceKey<ActionRegistryEntry>> getAllPerWorldActions() {
return PER_WORLD_ACTIONS.keySet();
}
/**
* Find a valid alternate drawing for this pattern that won't collide with anything pre-existing
*/
public static HexPattern scrunglePattern(HexPattern prototype, long seed) {
return EulerPathFinder.findAltDrawing(prototype, seed, it -> {
var sig = it.anglesSignature();
return !NORMAL_ACTION_LOOKUP.containsKey(sig);
});
}
}

View File

@ -1,15 +1,21 @@
package at.petrak.hexcasting.common.command;
import at.petrak.hexcasting.api.casting.ActionRegistryEntry;
import at.petrak.hexcasting.api.casting.iota.PatternIota;
import at.petrak.hexcasting.api.casting.math.HexPattern;
import at.petrak.hexcasting.api.mod.HexTags;
import at.petrak.hexcasting.api.utils.HexUtils;
import at.petrak.hexcasting.common.casting.PatternRegistryManifest;
import at.petrak.hexcasting.common.items.storage.ItemScroll;
import at.petrak.hexcasting.common.lib.HexItems;
import at.petrak.hexcasting.server.ScrungledPatternsSave;
import at.petrak.hexcasting.xplat.IXplatAbstractions;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.commands.arguments.EntityArgument;
import net.minecraft.commands.arguments.ResourceLocationArgument;
import net.minecraft.core.Registry;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
@ -19,9 +25,9 @@ import net.minecraft.world.item.ItemStack;
import java.util.Collection;
import java.util.List;
public class ListPatternsCommand {
public class ListPerWorldPatternsCommand {
public static void add(LiteralArgumentBuilder<CommandSourceStack> cmd) {
cmd.then(Commands.literal("patterns")
cmd.then(Commands.literal("perWorldPatterns")
.requires(dp -> dp.hasPermission(Commands.LEVEL_GAMEMASTERS))
.then(Commands.literal("list")
.executes(ctx -> list(ctx.getSource())))
@ -57,7 +63,8 @@ public class ListPatternsCommand {
}
private static int list(CommandSourceStack source) {
var keys = PatternRegistryManifest.getAllPerWorldActions();
var keys = IXplatAbstractions.INSTANCE.getActionRegistry().registryKeySet();
var listing = keys
.stream()
.sorted((a, b) -> compareResLoc(a.location(), b.location()))
@ -78,34 +85,44 @@ public class ListPatternsCommand {
private static int giveAll(CommandSourceStack source, Collection<ServerPlayer> targets) {
if (!targets.isEmpty()) {
var lookup = PatternRegistryManifest.getAllPerWorldActions();
var ow = source.getLevel().getServer().overworld();
var save = ScrungledPatternsSave.open(ow);
Registry<ActionRegistryEntry> regi = IXplatAbstractions.INSTANCE.getActionRegistry();
lookup.forEach(key -> {
var pat = PatternRegistryManifest.getCanonicalStrokesPerWorld(key, ow);
int count = 0;
for (var entry : regi.entrySet()) {
var key = entry.getKey();
if (HexUtils.isOfTag(regi, key, HexTags.Actions.PER_WORLD_PATTERN)) {
var found = save.lookupReverse(key);
var signature = found.getFirst();
var startDir = found.getSecond().canonicalStartDir();
var pat = HexPattern.fromAngles(signature, startDir);
var tag = new CompoundTag();
tag.putString(ItemScroll.TAG_OP_ID, key.location().toString());
tag.put(ItemScroll.TAG_PATTERN, pat.serializeToNBT());
var tag = new CompoundTag();
tag.putString(ItemScroll.TAG_OP_ID, key.location().toString());
tag.put(ItemScroll.TAG_PATTERN, pat.serializeToNBT());
var stack = new ItemStack(HexItems.SCROLL_LARGE);
stack.setTag(tag);
var stack = new ItemStack(HexItems.SCROLL_LARGE);
stack.setTag(tag);
for (var player : targets) {
var stackEntity = player.drop(stack, false);
if (stackEntity != null) {
stackEntity.setNoPickUpDelay();
stackEntity.setOwner(player.getUUID());
for (var player : targets) {
var stackEntity = player.drop(stack, false);
if (stackEntity != null) {
stackEntity.setNoPickUpDelay();
stackEntity.setOwner(player.getUUID());
}
}
count++;
}
});
}
source.sendSuccess(
Component.translatable("command.hexcasting.pats.all",
lookup.size(),
count,
targets.size() == 1 ? targets.iterator().next().getDisplayName() : targets.size()),
true);
return lookup.size();
return count;
} else {
return 0;
}

View File

@ -1,6 +1,8 @@
package at.petrak.hexcasting.common.command;
import at.petrak.hexcasting.api.casting.math.HexPattern;
import at.petrak.hexcasting.api.mod.HexTags;
import at.petrak.hexcasting.api.utils.HexUtils;
import at.petrak.hexcasting.common.casting.PatternRegistryManifest;
import at.petrak.hexcasting.xplat.IXplatAbstractions;
import com.mojang.brigadier.context.CommandContext;
@ -15,6 +17,7 @@ import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import java.util.ArrayList;
import java.util.concurrent.CompletableFuture;
public class PatternResLocArgument extends ResourceLocationArgument {
@ -29,8 +32,15 @@ public class PatternResLocArgument extends ResourceLocationArgument {
@Override
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
return SharedSuggestionProvider.suggest(
PatternRegistryManifest.getAllPerWorldActions().stream().map(key -> key.location().toString()), builder);
var suggestions = new ArrayList<String>();
var registry = IXplatAbstractions.INSTANCE.getActionRegistry();
for (var key : registry.registryKeySet()) {
if (HexUtils.isOfTag(registry, key, HexTags.Actions.PER_WORLD_PATTERN)) {
suggestions.add(key.location().toString());
}
}
return SharedSuggestionProvider.suggest(suggestions, builder);
}
public static HexPattern getPattern(

View File

@ -1,7 +1,7 @@
package at.petrak.hexcasting.common.lib;
import at.petrak.hexcasting.common.command.BrainsweepCommand;
import at.petrak.hexcasting.common.command.ListPatternsCommand;
import at.petrak.hexcasting.common.command.ListPerWorldPatternsCommand;
import at.petrak.hexcasting.common.command.RecalcPatternsCommand;
import com.mojang.brigadier.CommandDispatcher;
import net.minecraft.commands.CommandSourceStack;
@ -12,7 +12,7 @@ public class HexCommands {
var mainCmd = Commands.literal("hexcasting");
BrainsweepCommand.add(mainCmd);
ListPatternsCommand.add(mainCmd);
ListPerWorldPatternsCommand.add(mainCmd);
RecalcPatternsCommand.add(mainCmd);
dispatcher.register(mainCmd);

View File

@ -1,18 +1,26 @@
package at.petrak.hexcasting.common.loot;
import at.petrak.hexcasting.api.casting.ActionRegistryEntry;
import at.petrak.hexcasting.api.mod.HexTags;
import at.petrak.hexcasting.api.utils.HexUtils;
import at.petrak.hexcasting.common.casting.PatternRegistryManifest;
import at.petrak.hexcasting.common.items.storage.ItemScroll;
import at.petrak.hexcasting.common.lib.HexLootFunctions;
import at.petrak.hexcasting.xplat.IXplatAbstractions;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonObject;
import com.google.gson.JsonSerializationContext;
import net.minecraft.core.Registry;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.functions.LootItemConditionalFunction;
import net.minecraft.world.level.storage.loot.functions.LootItemFunctionType;
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition;
import java.util.ArrayList;
/**
* Slap a random per-world pattern on the scroll.
* <p>
@ -29,10 +37,14 @@ public class AddPerWorldPatternToScrollFunc extends LootItemConditionalFunction
*/
public static ItemStack doStatic(ItemStack stack, LootContext ctx) {
var rand = ctx.getRandom();
var worldLookup = PatternRegistryManifest.getAllPerWorldActions();
var keys = worldLookup.stream().toList();
var key = keys.get(rand.nextInt(keys.size()));
var perWorldKeys = new ArrayList<ResourceKey<ActionRegistryEntry>>();
Registry<ActionRegistryEntry> regi = IXplatAbstractions.INSTANCE.getActionRegistry();
for (var key : regi.registryKeySet()) {
if (HexUtils.isOfTag(regi, key, HexTags.Actions.PER_WORLD_PATTERN)) {
perWorldKeys.add(key);
}
}
var key = perWorldKeys.get(rand.nextInt(perWorldKeys.size()));
var pat = PatternRegistryManifest.getCanonicalStrokesPerWorld(key, ctx.getLevel().getServer().overworld());
var tag = new CompoundTag();

View File

@ -3,9 +3,12 @@ package at.petrak.hexcasting.datagen.tag;
import at.petrak.hexcasting.api.casting.ActionRegistryEntry;
import at.petrak.hexcasting.api.mod.HexTags;
import at.petrak.hexcasting.xplat.IXplatAbstractions;
import at.petrak.hexcasting.xplat.Platform;
import net.minecraft.data.DataGenerator;
import net.minecraft.data.tags.TagsProvider;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagKey;
import static at.petrak.hexcasting.api.HexAPI.modLoc;
@ -24,10 +27,23 @@ public class HexActionTagProvider extends TagsProvider<ActionRegistryEntry> {
}) {
var loc = modLoc(normalGreat);
var key = ResourceKey.create(IXplatAbstractions.INSTANCE.getActionRegistry().key(), loc);
tag(HexTags.Actions.REQUIRES_ENLIGHTENMENT).add(key);
tag(HexTags.Actions.CAN_START_ENLIGHTEN).add(key);
tag(HexTags.Actions.PER_WORLD_PATTERN).add(key);
tag(ersatzActionTag(HexTags.Actions.REQUIRES_ENLIGHTENMENT)).add(key);
tag(ersatzActionTag(HexTags.Actions.CAN_START_ENLIGHTEN)).add(key);
tag(ersatzActionTag(HexTags.Actions.PER_WORLD_PATTERN)).add(key);
}
// deciding that akashic write can be just a normal spell (as a treat)
}
private static TagKey<ActionRegistryEntry> ersatzActionTag(TagKey<ActionRegistryEntry> real) {
if (IXplatAbstractions.INSTANCE.platform() == Platform.FABRIC) {
// Vanilla (and Fabric) has a bug here where it *writes* hexcasting action tags to `.../tags/action`
// instead of `.../tags/hexcasting/action`.
// So we pull this bullshit
var fakeKey = ResourceKey.<ActionRegistryEntry>createRegistryKey(
new ResourceLocation("foobar", "hexcasting/tags/action"));
return TagKey.create(fakeKey, real.location());
} else {
return real;
}
}
}

View File

@ -1,9 +1,10 @@
package at.petrak.hexcasting.server;
import at.petrak.hexcasting.api.casting.ActionRegistryEntry;
import at.petrak.hexcasting.api.casting.math.EulerPathFinder;
import at.petrak.hexcasting.api.casting.math.HexDir;
import at.petrak.hexcasting.api.casting.math.HexPattern;
import at.petrak.hexcasting.common.casting.PatternRegistryManifest;
import at.petrak.hexcasting.api.mod.HexTags;
import at.petrak.hexcasting.api.utils.HexUtils;
import at.petrak.hexcasting.xplat.IXplatAbstractions;
import com.mojang.datafixers.util.Pair;
import net.minecraft.nbt.CompoundTag;
@ -46,12 +47,6 @@ public class ScrungledPatternsSave extends SavedData {
});
}
public void insert(HexPattern scrungledPattern, ResourceKey<ActionRegistryEntry> key) {
this.lookup.put(scrungledPattern.anglesSignature(), new PerWorldEntry(key, scrungledPattern.getStartDir()));
this.reverseLookup.put(key, scrungledPattern.anglesSignature());
this.setDirty();
}
@Nullable
public PerWorldEntry lookup(String signature) {
return this.lookup.get(signature);
@ -98,13 +93,25 @@ public class ScrungledPatternsSave extends SavedData {
public static ScrungledPatternsSave createFromScratch(long seed) {
var map = new HashMap<String, PerWorldEntry>();
for (var key : PatternRegistryManifest.getAllPerWorldActions()) {
var regiEntry = IXplatAbstractions.INSTANCE.getActionRegistry().get(key);
var scrungled = PatternRegistryManifest.scrunglePattern(regiEntry.prototype(), seed);
map.put(scrungled.anglesSignature(), new PerWorldEntry(key, scrungled.getStartDir()));
var registry = IXplatAbstractions.INSTANCE.getActionRegistry();
// TODO: this version of the code doesn't have overlap protection
// this means if some hilarious funny person makes a great spell that has the same shape as a normal spell
// there might be overlap.
// I'm going to file that under "don't do that"
// (the number literal phial incident won't happen though because we check for special handlers first now)
for (var key : registry.registryKeySet()) {
var entry = registry.get(key);
if (HexUtils.isOfTag(registry, key, HexTags.Actions.PER_WORLD_PATTERN)) {
var scrungledPat = EulerPathFinder.findAltDrawing(entry.prototype(), seed);
map.put(scrungledPat.anglesSignature(), new PerWorldEntry(key, scrungledPat.getStartDir()));
}
}
return new ScrungledPatternsSave(map);
var out = new ScrungledPatternsSave(map);
out.setDirty();
return out;
}
public static ScrungledPatternsSave open(ServerLevel overworld) {

View File

@ -1,4 +1,4 @@
// 1.19.2 2023-06-20T14:35:02.713372803 Tags for minecraft:item
// 1.19.2 2023-07-08T15:19:48.058598656 Tags for minecraft:item
bdb90cee0e88e02f0b98f12d5dd212adfaca9afd data/hexcasting/tags/items/impeti.json
5928bad07d3872bb60f29ef4f3c885c8e1967c20 data/hexcasting/tags/items/phial_base.json
fdb48f194d7937ab6b423fa4b90a4d438bf6dd90 data/minecraft/tags/items/wooden_doors.json

View File

@ -1,4 +1,4 @@
// 1.19.2 2023-06-20T14:35:02.717093115 LootTables
// 1.19.2 2023-07-08T15:19:48.070759599 LootTables
c4b92d074f5a3cae1249835afaa0f20b6e5c0ef8 data/hexcasting/loot_tables/blocks/amethyst_bricks_small.json
5211c7198f72948d8dbc7714d4e58a234d7d9fce data/hexcasting/loot_tables/blocks/edified_log_purple.json
f522ca0b06b00fbf8524f3399eaab9cc0711f484 data/hexcasting/loot_tables/blocks/slate_tiles.json

View File

@ -1,4 +1,4 @@
// 1.19.2 2023-06-20T14:35:02.735720596 Tags for minecraft:block
// 1.19.2 2023-07-08T15:19:48.06956573 Tags for minecraft:block
c72a147bc65d26424df199388969ebd11119aed3 data/hexcasting/tags/blocks/brainswept_circle_components.json
357eddf3cee6f16725bed0701d57b2ca3097d74d data/minecraft/tags/blocks/mineable/shovel.json
20183cd61968ff6548df2dde1100b6378d68d64b data/minecraft/tags/blocks/buttons.json

View File

@ -1,4 +1,4 @@
// 1.19.2 2023-06-20T14:35:02.716581079 Tags for hexcasting:action
6fe30f41e2bcd48589caab26d210a513dce1ab7c data/hexcasting/tags/action/per_world_pattern.json
6fe30f41e2bcd48589caab26d210a513dce1ab7c data/hexcasting/tags/action/requires_enlightenment.json
6fe30f41e2bcd48589caab26d210a513dce1ab7c data/hexcasting/tags/action/can_start_enlighten.json
// 1.19.2 2023-07-08T15:19:48.069020223 Tags for hexcasting:action
6fe30f41e2bcd48589caab26d210a513dce1ab7c data/action/tags/action/requires_enlightenment.json
6fe30f41e2bcd48589caab26d210a513dce1ab7c data/action/tags/action/per_world_pattern.json
6fe30f41e2bcd48589caab26d210a513dce1ab7c data/action/tags/action/can_start_enlighten.json

View File

@ -1,4 +1,4 @@
// 1.19.2 2023-06-20T14:35:02.737606972 Recipes
// 1.19.2 2023-07-08T15:19:48.074650046 Recipes
83c23cf481b467a457da980c45700cba0d50f379 data/hexcasting/recipes/staff/mangrove.json
9f75d3e93ecbbbf3ed9a92b2943397e09dcae1a9 data/hexcasting/recipes/dye_colorizer_light_blue.json
04569ccadfd99f203b0485d0c3e877209290f2b3 data/hexcasting/advancements/recipes/hexcasting.creative_tab/dye_colorizer_pink.json