datagen is still incredibly broken but it doesn't matter because we 1.20 now
This commit is contained in:
parent
a4a49fd411
commit
60c55d86b1
|
@ -4,93 +4,53 @@ import at.petrak.hexcasting.api.HexAPI;
|
||||||
import at.petrak.hexcasting.api.casting.ActionRegistryEntry;
|
import at.petrak.hexcasting.api.casting.ActionRegistryEntry;
|
||||||
import at.petrak.hexcasting.api.casting.PatternShapeMatch;
|
import at.petrak.hexcasting.api.casting.PatternShapeMatch;
|
||||||
import at.petrak.hexcasting.api.casting.castables.SpecialHandler;
|
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.casting.math.HexPattern;
|
||||||
import at.petrak.hexcasting.api.mod.HexTags;
|
import at.petrak.hexcasting.api.mod.HexTags;
|
||||||
import at.petrak.hexcasting.api.utils.HexUtils;
|
import at.petrak.hexcasting.api.utils.HexUtils;
|
||||||
import at.petrak.hexcasting.server.ScrungledPatternsSave;
|
import at.petrak.hexcasting.server.ScrungledPatternsSave;
|
||||||
import at.petrak.hexcasting.xplat.IXplatAbstractions;
|
import at.petrak.hexcasting.xplat.IXplatAbstractions;
|
||||||
import com.mojang.datafixers.util.Pair;
|
import com.mojang.datafixers.util.Pair;
|
||||||
import com.mojang.datafixers.util.Unit;
|
|
||||||
import net.minecraft.resources.ResourceKey;
|
import net.minecraft.resources.ResourceKey;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import org.apache.commons.lang3.NotImplementedException;
|
import org.apache.commons.lang3.NotImplementedException;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
|
||||||
// Now an internal-only class used to do final processing on the registered stuff
|
// Now an internal-only class used to do final processing on the registered stuff
|
||||||
public class PatternRegistryManifest {
|
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 =
|
private static final ConcurrentMap<String, ResourceKey<ActionRegistryEntry>> NORMAL_ACTION_LOOKUP =
|
||||||
new ConcurrentHashMap<>();
|
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!
|
* Process the registry!
|
||||||
* <p>
|
* <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
|
// 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
|
// 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...
|
// 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) {
|
public static void processRegistry(@Nullable ServerLevel overworld) {
|
||||||
ScrungledPatternsSave perWorldPatterns = null;
|
int perWorldActionCount = 0;
|
||||||
if (overworld != null) {
|
|
||||||
perWorldPatterns = ScrungledPatternsSave.open(overworld);
|
|
||||||
}
|
|
||||||
|
|
||||||
var postCalculationNeeders = new ArrayList<ResourceKey<ActionRegistryEntry>>();
|
|
||||||
|
|
||||||
var registry = IXplatAbstractions.INSTANCE.getActionRegistry();
|
var registry = IXplatAbstractions.INSTANCE.getActionRegistry();
|
||||||
for (var key : registry.registryKeySet()) {
|
for (var key : registry.registryKeySet()) {
|
||||||
var entry = registry.get(key);
|
var entry = registry.get(key);
|
||||||
if (HexUtils.isOfTag(registry, key, HexTags.Actions.PER_WORLD_PATTERN)) {
|
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 {
|
|
||||||
NORMAL_ACTION_LOOKUP.put(entry.prototype().anglesSignature(), key);
|
NORMAL_ACTION_LOOKUP.put(entry.prototype().anglesSignature(), key);
|
||||||
}
|
} else {
|
||||||
}
|
perWorldActionCount++;
|
||||||
|
|
||||||
if (perWorldPatterns != null) {
|
|
||||||
for (var postNeederKey : postCalculationNeeders) {
|
|
||||||
var regiEntry = registry.get(postNeederKey);
|
|
||||||
var scrungledPat = scrunglePattern(regiEntry.prototype(), overworld.getSeed());
|
|
||||||
|
|
||||||
perWorldPatterns.insert(scrungledPat, postNeederKey);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HexAPI.LOGGER.info(("We're on the %s! " +
|
HexAPI.LOGGER.info(("We're on the %s! " +
|
||||||
"Loaded %d regular actions, %d per-world actions, and %d special handlers").formatted(
|
"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()
|
IXplatAbstractions.INSTANCE.getSpecialHandlerRegistry().size()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
@ -159,21 +119,4 @@ public class PatternRegistryManifest {
|
||||||
var entry = pair.getSecond();
|
var entry = pair.getSecond();
|
||||||
return HexPattern.fromAngles(sig, entry.canonicalStartDir());
|
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);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,21 @@
|
||||||
package at.petrak.hexcasting.common.command;
|
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.iota.PatternIota;
|
||||||
import at.petrak.hexcasting.api.casting.math.HexPattern;
|
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.casting.PatternRegistryManifest;
|
||||||
import at.petrak.hexcasting.common.items.storage.ItemScroll;
|
import at.petrak.hexcasting.common.items.storage.ItemScroll;
|
||||||
import at.petrak.hexcasting.common.lib.HexItems;
|
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 com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
import net.minecraft.commands.Commands;
|
import net.minecraft.commands.Commands;
|
||||||
import net.minecraft.commands.arguments.EntityArgument;
|
import net.minecraft.commands.arguments.EntityArgument;
|
||||||
import net.minecraft.commands.arguments.ResourceLocationArgument;
|
import net.minecraft.commands.arguments.ResourceLocationArgument;
|
||||||
|
import net.minecraft.core.Registry;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
@ -19,9 +25,9 @@ import net.minecraft.world.item.ItemStack;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ListPatternsCommand {
|
public class ListPerWorldPatternsCommand {
|
||||||
public static void add(LiteralArgumentBuilder<CommandSourceStack> cmd) {
|
public static void add(LiteralArgumentBuilder<CommandSourceStack> cmd) {
|
||||||
cmd.then(Commands.literal("patterns")
|
cmd.then(Commands.literal("perWorldPatterns")
|
||||||
.requires(dp -> dp.hasPermission(Commands.LEVEL_GAMEMASTERS))
|
.requires(dp -> dp.hasPermission(Commands.LEVEL_GAMEMASTERS))
|
||||||
.then(Commands.literal("list")
|
.then(Commands.literal("list")
|
||||||
.executes(ctx -> list(ctx.getSource())))
|
.executes(ctx -> list(ctx.getSource())))
|
||||||
|
@ -57,7 +63,8 @@ public class ListPatternsCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int list(CommandSourceStack source) {
|
private static int list(CommandSourceStack source) {
|
||||||
var keys = PatternRegistryManifest.getAllPerWorldActions();
|
|
||||||
|
var keys = IXplatAbstractions.INSTANCE.getActionRegistry().registryKeySet();
|
||||||
var listing = keys
|
var listing = keys
|
||||||
.stream()
|
.stream()
|
||||||
.sorted((a, b) -> compareResLoc(a.location(), b.location()))
|
.sorted((a, b) -> compareResLoc(a.location(), b.location()))
|
||||||
|
@ -78,34 +85,44 @@ public class ListPatternsCommand {
|
||||||
|
|
||||||
private static int giveAll(CommandSourceStack source, Collection<ServerPlayer> targets) {
|
private static int giveAll(CommandSourceStack source, Collection<ServerPlayer> targets) {
|
||||||
if (!targets.isEmpty()) {
|
if (!targets.isEmpty()) {
|
||||||
var lookup = PatternRegistryManifest.getAllPerWorldActions();
|
|
||||||
var ow = source.getLevel().getServer().overworld();
|
var ow = source.getLevel().getServer().overworld();
|
||||||
|
var save = ScrungledPatternsSave.open(ow);
|
||||||
|
Registry<ActionRegistryEntry> regi = IXplatAbstractions.INSTANCE.getActionRegistry();
|
||||||
|
|
||||||
lookup.forEach(key -> {
|
int count = 0;
|
||||||
var pat = PatternRegistryManifest.getCanonicalStrokesPerWorld(key, ow);
|
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();
|
var tag = new CompoundTag();
|
||||||
tag.putString(ItemScroll.TAG_OP_ID, key.location().toString());
|
tag.putString(ItemScroll.TAG_OP_ID, key.location().toString());
|
||||||
tag.put(ItemScroll.TAG_PATTERN, pat.serializeToNBT());
|
tag.put(ItemScroll.TAG_PATTERN, pat.serializeToNBT());
|
||||||
|
|
||||||
var stack = new ItemStack(HexItems.SCROLL_LARGE);
|
var stack = new ItemStack(HexItems.SCROLL_LARGE);
|
||||||
stack.setTag(tag);
|
stack.setTag(tag);
|
||||||
|
|
||||||
for (var player : targets) {
|
for (var player : targets) {
|
||||||
var stackEntity = player.drop(stack, false);
|
var stackEntity = player.drop(stack, false);
|
||||||
if (stackEntity != null) {
|
if (stackEntity != null) {
|
||||||
stackEntity.setNoPickUpDelay();
|
stackEntity.setNoPickUpDelay();
|
||||||
stackEntity.setOwner(player.getUUID());
|
stackEntity.setOwner(player.getUUID());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
count++;
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
source.sendSuccess(
|
source.sendSuccess(
|
||||||
Component.translatable("command.hexcasting.pats.all",
|
Component.translatable("command.hexcasting.pats.all",
|
||||||
lookup.size(),
|
count,
|
||||||
targets.size() == 1 ? targets.iterator().next().getDisplayName() : targets.size()),
|
targets.size() == 1 ? targets.iterator().next().getDisplayName() : targets.size()),
|
||||||
true);
|
true);
|
||||||
return lookup.size();
|
return count;
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
|
@ -1,6 +1,8 @@
|
||||||
package at.petrak.hexcasting.common.command;
|
package at.petrak.hexcasting.common.command;
|
||||||
|
|
||||||
import at.petrak.hexcasting.api.casting.math.HexPattern;
|
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.casting.PatternRegistryManifest;
|
||||||
import at.petrak.hexcasting.xplat.IXplatAbstractions;
|
import at.petrak.hexcasting.xplat.IXplatAbstractions;
|
||||||
import com.mojang.brigadier.context.CommandContext;
|
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.ResourceKey;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
public class PatternResLocArgument extends ResourceLocationArgument {
|
public class PatternResLocArgument extends ResourceLocationArgument {
|
||||||
|
@ -29,8 +32,15 @@ public class PatternResLocArgument extends ResourceLocationArgument {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
|
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
|
||||||
return SharedSuggestionProvider.suggest(
|
var suggestions = new ArrayList<String>();
|
||||||
PatternRegistryManifest.getAllPerWorldActions().stream().map(key -> key.location().toString()), builder);
|
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(
|
public static HexPattern getPattern(
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package at.petrak.hexcasting.common.lib;
|
package at.petrak.hexcasting.common.lib;
|
||||||
|
|
||||||
import at.petrak.hexcasting.common.command.BrainsweepCommand;
|
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 at.petrak.hexcasting.common.command.RecalcPatternsCommand;
|
||||||
import com.mojang.brigadier.CommandDispatcher;
|
import com.mojang.brigadier.CommandDispatcher;
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
|
@ -12,7 +12,7 @@ public class HexCommands {
|
||||||
var mainCmd = Commands.literal("hexcasting");
|
var mainCmd = Commands.literal("hexcasting");
|
||||||
|
|
||||||
BrainsweepCommand.add(mainCmd);
|
BrainsweepCommand.add(mainCmd);
|
||||||
ListPatternsCommand.add(mainCmd);
|
ListPerWorldPatternsCommand.add(mainCmd);
|
||||||
RecalcPatternsCommand.add(mainCmd);
|
RecalcPatternsCommand.add(mainCmd);
|
||||||
|
|
||||||
dispatcher.register(mainCmd);
|
dispatcher.register(mainCmd);
|
||||||
|
|
|
@ -1,18 +1,26 @@
|
||||||
package at.petrak.hexcasting.common.loot;
|
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.casting.PatternRegistryManifest;
|
||||||
import at.petrak.hexcasting.common.items.storage.ItemScroll;
|
import at.petrak.hexcasting.common.items.storage.ItemScroll;
|
||||||
import at.petrak.hexcasting.common.lib.HexLootFunctions;
|
import at.petrak.hexcasting.common.lib.HexLootFunctions;
|
||||||
|
import at.petrak.hexcasting.xplat.IXplatAbstractions;
|
||||||
import com.google.gson.JsonDeserializationContext;
|
import com.google.gson.JsonDeserializationContext;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonSerializationContext;
|
import com.google.gson.JsonSerializationContext;
|
||||||
|
import net.minecraft.core.Registry;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import net.minecraft.resources.ResourceKey;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.level.storage.loot.LootContext;
|
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.LootItemConditionalFunction;
|
||||||
import net.minecraft.world.level.storage.loot.functions.LootItemFunctionType;
|
import net.minecraft.world.level.storage.loot.functions.LootItemFunctionType;
|
||||||
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition;
|
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Slap a random per-world pattern on the scroll.
|
* Slap a random per-world pattern on the scroll.
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -29,10 +37,14 @@ public class AddPerWorldPatternToScrollFunc extends LootItemConditionalFunction
|
||||||
*/
|
*/
|
||||||
public static ItemStack doStatic(ItemStack stack, LootContext ctx) {
|
public static ItemStack doStatic(ItemStack stack, LootContext ctx) {
|
||||||
var rand = ctx.getRandom();
|
var rand = ctx.getRandom();
|
||||||
var worldLookup = PatternRegistryManifest.getAllPerWorldActions();
|
var perWorldKeys = new ArrayList<ResourceKey<ActionRegistryEntry>>();
|
||||||
|
Registry<ActionRegistryEntry> regi = IXplatAbstractions.INSTANCE.getActionRegistry();
|
||||||
var keys = worldLookup.stream().toList();
|
for (var key : regi.registryKeySet()) {
|
||||||
var key = keys.get(rand.nextInt(keys.size()));
|
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 pat = PatternRegistryManifest.getCanonicalStrokesPerWorld(key, ctx.getLevel().getServer().overworld());
|
||||||
var tag = new CompoundTag();
|
var tag = new CompoundTag();
|
||||||
|
|
|
@ -3,9 +3,12 @@ package at.petrak.hexcasting.datagen.tag;
|
||||||
import at.petrak.hexcasting.api.casting.ActionRegistryEntry;
|
import at.petrak.hexcasting.api.casting.ActionRegistryEntry;
|
||||||
import at.petrak.hexcasting.api.mod.HexTags;
|
import at.petrak.hexcasting.api.mod.HexTags;
|
||||||
import at.petrak.hexcasting.xplat.IXplatAbstractions;
|
import at.petrak.hexcasting.xplat.IXplatAbstractions;
|
||||||
|
import at.petrak.hexcasting.xplat.Platform;
|
||||||
import net.minecraft.data.DataGenerator;
|
import net.minecraft.data.DataGenerator;
|
||||||
import net.minecraft.data.tags.TagsProvider;
|
import net.minecraft.data.tags.TagsProvider;
|
||||||
import net.minecraft.resources.ResourceKey;
|
import net.minecraft.resources.ResourceKey;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.tags.TagKey;
|
||||||
|
|
||||||
import static at.petrak.hexcasting.api.HexAPI.modLoc;
|
import static at.petrak.hexcasting.api.HexAPI.modLoc;
|
||||||
|
|
||||||
|
@ -24,10 +27,23 @@ public class HexActionTagProvider extends TagsProvider<ActionRegistryEntry> {
|
||||||
}) {
|
}) {
|
||||||
var loc = modLoc(normalGreat);
|
var loc = modLoc(normalGreat);
|
||||||
var key = ResourceKey.create(IXplatAbstractions.INSTANCE.getActionRegistry().key(), loc);
|
var key = ResourceKey.create(IXplatAbstractions.INSTANCE.getActionRegistry().key(), loc);
|
||||||
tag(HexTags.Actions.REQUIRES_ENLIGHTENMENT).add(key);
|
tag(ersatzActionTag(HexTags.Actions.REQUIRES_ENLIGHTENMENT)).add(key);
|
||||||
tag(HexTags.Actions.CAN_START_ENLIGHTEN).add(key);
|
tag(ersatzActionTag(HexTags.Actions.CAN_START_ENLIGHTEN)).add(key);
|
||||||
tag(HexTags.Actions.PER_WORLD_PATTERN).add(key);
|
tag(ersatzActionTag(HexTags.Actions.PER_WORLD_PATTERN)).add(key);
|
||||||
}
|
}
|
||||||
// deciding that akashic write can be just a normal spell (as a treat)
|
// 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
package at.petrak.hexcasting.server;
|
package at.petrak.hexcasting.server;
|
||||||
|
|
||||||
import at.petrak.hexcasting.api.casting.ActionRegistryEntry;
|
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.HexDir;
|
||||||
import at.petrak.hexcasting.api.casting.math.HexPattern;
|
import at.petrak.hexcasting.api.mod.HexTags;
|
||||||
import at.petrak.hexcasting.common.casting.PatternRegistryManifest;
|
import at.petrak.hexcasting.api.utils.HexUtils;
|
||||||
import at.petrak.hexcasting.xplat.IXplatAbstractions;
|
import at.petrak.hexcasting.xplat.IXplatAbstractions;
|
||||||
import com.mojang.datafixers.util.Pair;
|
import com.mojang.datafixers.util.Pair;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
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
|
@Nullable
|
||||||
public PerWorldEntry lookup(String signature) {
|
public PerWorldEntry lookup(String signature) {
|
||||||
return this.lookup.get(signature);
|
return this.lookup.get(signature);
|
||||||
|
@ -98,13 +93,25 @@ public class ScrungledPatternsSave extends SavedData {
|
||||||
|
|
||||||
public static ScrungledPatternsSave createFromScratch(long seed) {
|
public static ScrungledPatternsSave createFromScratch(long seed) {
|
||||||
var map = new HashMap<String, PerWorldEntry>();
|
var map = new HashMap<String, PerWorldEntry>();
|
||||||
for (var key : PatternRegistryManifest.getAllPerWorldActions()) {
|
|
||||||
var regiEntry = IXplatAbstractions.INSTANCE.getActionRegistry().get(key);
|
var registry = IXplatAbstractions.INSTANCE.getActionRegistry();
|
||||||
var scrungled = PatternRegistryManifest.scrunglePattern(regiEntry.prototype(), seed);
|
|
||||||
map.put(scrungled.anglesSignature(), new PerWorldEntry(key, scrungled.getStartDir()));
|
// 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) {
|
public static ScrungledPatternsSave open(ServerLevel overworld) {
|
||||||
|
|
|
@ -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
|
bdb90cee0e88e02f0b98f12d5dd212adfaca9afd data/hexcasting/tags/items/impeti.json
|
||||||
5928bad07d3872bb60f29ef4f3c885c8e1967c20 data/hexcasting/tags/items/phial_base.json
|
5928bad07d3872bb60f29ef4f3c885c8e1967c20 data/hexcasting/tags/items/phial_base.json
|
||||||
fdb48f194d7937ab6b423fa4b90a4d438bf6dd90 data/minecraft/tags/items/wooden_doors.json
|
fdb48f194d7937ab6b423fa4b90a4d438bf6dd90 data/minecraft/tags/items/wooden_doors.json
|
||||||
|
|
|
@ -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
|
c4b92d074f5a3cae1249835afaa0f20b6e5c0ef8 data/hexcasting/loot_tables/blocks/amethyst_bricks_small.json
|
||||||
5211c7198f72948d8dbc7714d4e58a234d7d9fce data/hexcasting/loot_tables/blocks/edified_log_purple.json
|
5211c7198f72948d8dbc7714d4e58a234d7d9fce data/hexcasting/loot_tables/blocks/edified_log_purple.json
|
||||||
f522ca0b06b00fbf8524f3399eaab9cc0711f484 data/hexcasting/loot_tables/blocks/slate_tiles.json
|
f522ca0b06b00fbf8524f3399eaab9cc0711f484 data/hexcasting/loot_tables/blocks/slate_tiles.json
|
||||||
|
|
|
@ -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
|
c72a147bc65d26424df199388969ebd11119aed3 data/hexcasting/tags/blocks/brainswept_circle_components.json
|
||||||
357eddf3cee6f16725bed0701d57b2ca3097d74d data/minecraft/tags/blocks/mineable/shovel.json
|
357eddf3cee6f16725bed0701d57b2ca3097d74d data/minecraft/tags/blocks/mineable/shovel.json
|
||||||
20183cd61968ff6548df2dde1100b6378d68d64b data/minecraft/tags/blocks/buttons.json
|
20183cd61968ff6548df2dde1100b6378d68d64b data/minecraft/tags/blocks/buttons.json
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// 1.19.2 2023-06-20T14:35:02.716581079 Tags for hexcasting:action
|
// 1.19.2 2023-07-08T15:19:48.069020223 Tags for hexcasting:action
|
||||||
6fe30f41e2bcd48589caab26d210a513dce1ab7c data/hexcasting/tags/action/per_world_pattern.json
|
6fe30f41e2bcd48589caab26d210a513dce1ab7c data/action/tags/action/requires_enlightenment.json
|
||||||
6fe30f41e2bcd48589caab26d210a513dce1ab7c data/hexcasting/tags/action/requires_enlightenment.json
|
6fe30f41e2bcd48589caab26d210a513dce1ab7c data/action/tags/action/per_world_pattern.json
|
||||||
6fe30f41e2bcd48589caab26d210a513dce1ab7c data/hexcasting/tags/action/can_start_enlighten.json
|
6fe30f41e2bcd48589caab26d210a513dce1ab7c data/action/tags/action/can_start_enlighten.json
|
||||||
|
|
|
@ -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
|
83c23cf481b467a457da980c45700cba0d50f379 data/hexcasting/recipes/staff/mangrove.json
|
||||||
9f75d3e93ecbbbf3ed9a92b2943397e09dcae1a9 data/hexcasting/recipes/dye_colorizer_light_blue.json
|
9f75d3e93ecbbbf3ed9a92b2943397e09dcae1a9 data/hexcasting/recipes/dye_colorizer_light_blue.json
|
||||||
04569ccadfd99f203b0485d0c3e877209290f2b3 data/hexcasting/advancements/recipes/hexcasting.creative_tab/dye_colorizer_pink.json
|
04569ccadfd99f203b0485d0c3e877209290f2b3 data/hexcasting/advancements/recipes/hexcasting.creative_tab/dye_colorizer_pink.json
|
||||||
|
|
Loading…
Reference in a new issue