mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-26 10:29:20 +00:00
配方映射完成80%
This commit is contained in:
@@ -276,7 +276,7 @@ public final class BukkitBlockManager extends AbstractBlockManager {
|
||||
}
|
||||
|
||||
private void registerEmptyBlock() {
|
||||
Holder.Reference<CustomBlock> holder = ((WritableRegistry<CustomBlock>) BuiltInRegistries.BLOCK).registerForHolder(new ResourceKey<>(BuiltInRegistries.BLOCK.key().location(), Key.withDefaultNamespace("empty")));
|
||||
Holder.Reference<CustomBlock> holder = ((WritableRegistry<CustomBlock>) BuiltInRegistries.BLOCK).registerForHolder(ResourceKey.create(BuiltInRegistries.BLOCK.key().location(), Key.withDefaultNamespace("empty")));
|
||||
EmptyBlock emptyBlock = new EmptyBlock(Key.withDefaultNamespace("empty"), holder);
|
||||
holder.bindValue(emptyBlock);
|
||||
}
|
||||
|
||||
@@ -254,9 +254,8 @@ public final class BukkitCustomBlock extends AbstractCustomBlock {
|
||||
@Override
|
||||
public @NotNull CustomBlock build() {
|
||||
// create or get block holder
|
||||
Holder.Reference<CustomBlock> holder = BuiltInRegistries.BLOCK.get(id).orElseGet(() ->
|
||||
((WritableRegistry<CustomBlock>) BuiltInRegistries.BLOCK).registerForHolder(new ResourceKey<>(BuiltInRegistries.BLOCK.key().location(), id)));
|
||||
return new BukkitCustomBlock(id, holder, properties, appearances, variantMapper, settings, events, behavior, lootTable);
|
||||
Holder.Reference<CustomBlock> holder = ((WritableRegistry<CustomBlock>) BuiltInRegistries.BLOCK).getOrRegisterForHolder(ResourceKey.create(BuiltInRegistries.BLOCK.key().location(), this.id));
|
||||
return new BukkitCustomBlock(this.id, holder, this.properties, this.appearances, this.variantMapper, this.settings, this.events, this.behavior, this.lootTable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -374,7 +374,7 @@ public class BukkitItemManager extends AbstractItemManager<ItemStack> {
|
||||
VANILLA_ITEMS.add(itemKey);
|
||||
Holder.Reference<Key> holder = BuiltInRegistries.OPTIMIZED_ITEM_ID.get(itemKey)
|
||||
.orElseGet(() -> ((WritableRegistry<Key>) BuiltInRegistries.OPTIMIZED_ITEM_ID)
|
||||
.register(new ResourceKey<>(BuiltInRegistries.OPTIMIZED_ITEM_ID.key().location(), itemKey), itemKey));
|
||||
.register(ResourceKey.create(BuiltInRegistries.OPTIMIZED_ITEM_ID.key().location(), itemKey), itemKey));
|
||||
Object mcHolder = FastNMS.INSTANCE.method$Registry$getHolderByResourceKey(MBuiltInRegistries.ITEM, FastNMS.INSTANCE.method$ResourceKey$create(MRegistries.ITEM, resourceLocation)).get();
|
||||
Set<Object> tags = (Set<Object>) CoreReflections.field$Holder$Reference$tags.get(mcHolder);
|
||||
for (Object tag : tags) {
|
||||
|
||||
@@ -4,7 +4,6 @@ import com.google.gson.JsonElement;
|
||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||
import net.momirealms.craftengine.bukkit.item.ComponentItemWrapper;
|
||||
import net.momirealms.craftengine.bukkit.item.ComponentTypes;
|
||||
import net.momirealms.craftengine.bukkit.item.LegacyItemWrapper;
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.CoreReflections;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.MBuiltInRegistries;
|
||||
|
||||
@@ -42,6 +42,7 @@ import net.momirealms.craftengine.core.item.CustomItem;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.item.behavior.ItemBehavior;
|
||||
import net.momirealms.craftengine.core.item.context.UseOnContext;
|
||||
import net.momirealms.craftengine.core.item.recipe.network.legacy.LegacyRecipeHolder;
|
||||
import net.momirealms.craftengine.core.item.recipe.network.modern.RecipeBookEntry;
|
||||
import net.momirealms.craftengine.core.item.recipe.network.modern.display.RecipeDisplay;
|
||||
import net.momirealms.craftengine.core.pack.host.ResourcePackDownloadData;
|
||||
@@ -2317,7 +2318,7 @@ public class PacketConsumers {
|
||||
}
|
||||
|
||||
boolean isTerminal = action == NetworkReflections.instance$ServerboundResourcePackPacket$Action$SUCCESSFULLY_LOADED || action == NetworkReflections.instance$ServerboundResourcePackPacket$Action$DOWNLOADED;
|
||||
if (isTerminal) {
|
||||
if (isTerminal && VersionHelper.isOrAbove1_20_2()) {
|
||||
event.setCancelled(true);
|
||||
Object packetListener = FastNMS.INSTANCE.method$Connection$getPacketListener(user.connection());
|
||||
if (!CoreReflections.clazz$ServerConfigurationPacketListenerImpl.isInstance(packetListener)) return;
|
||||
@@ -2520,6 +2521,15 @@ public class PacketConsumers {
|
||||
try {
|
||||
if (VersionHelper.isOrAbove1_21_2()) return;
|
||||
FriendlyByteBuf buf = event.getBuffer();
|
||||
List<LegacyRecipeHolder> holders = buf.readCollection(ArrayList::new, byteBuf -> {
|
||||
LegacyRecipeHolder holder = LegacyRecipeHolder.read(byteBuf);
|
||||
holder.recipe().applyClientboundData((BukkitServerPlayer) user);
|
||||
return holder;
|
||||
});
|
||||
event.setChanged(true);
|
||||
buf.clear();
|
||||
buf.writeVarInt(event.packetID());
|
||||
buf.writeCollection(holders, ((byteBuf, recipeHolder) -> recipeHolder.write(byteBuf)));
|
||||
} catch (Exception e) {
|
||||
CraftEngine.instance().logger().warn("Failed to handle ClientboundUpdateRecipesPacket", e);
|
||||
}
|
||||
|
||||
@@ -152,16 +152,16 @@ public class PacketIds1_20 implements PacketIds {
|
||||
|
||||
@Override
|
||||
public int clientboundRecipeBookAddPacket() {
|
||||
return PacketIdFinder.serverboundByClazz(NetworkReflections.clazz$ClientboundRecipeBookAddPacket);
|
||||
return PacketIdFinder.clientboundByClazz(NetworkReflections.clazz$ClientboundRecipeBookAddPacket);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int clientboundPlaceGhostRecipePacket() {
|
||||
return PacketIdFinder.serverboundByClazz(NetworkReflections.clazz$ClientboundPlaceGhostRecipePacket);
|
||||
return PacketIdFinder.clientboundByClazz(NetworkReflections.clazz$ClientboundPlaceGhostRecipePacket);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int clientboundUpdateRecipesPacket() {
|
||||
return PacketIdFinder.serverboundByClazz(NetworkReflections.clazz$ClientboundUpdateRecipesPacket);
|
||||
return PacketIdFinder.clientboundByClazz(NetworkReflections.clazz$ClientboundUpdateRecipesPacket);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1569,7 +1569,7 @@ public final class NetworkReflections {
|
||||
|
||||
public static final Class<?> clazz$ClientboundPlaceGhostRecipePacket = requireNonNull(
|
||||
BukkitReflectionUtils.findReobfOrMojmapClass(
|
||||
"network.protocol.game.ClientboundPlaceGhostRecipePacket",
|
||||
"network.protocol.game.PacketPlayOutAutoRecipe",
|
||||
"network.protocol.game.ClientboundPlaceGhostRecipePacket"
|
||||
)
|
||||
);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package net.momirealms.craftengine.bukkit.util;
|
||||
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.CoreReflections;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.MRegistries;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import net.momirealms.craftengine.core.block.BlockBehavior;
|
||||
import net.momirealms.craftengine.core.block.CustomBlock;
|
||||
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
|
||||
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
|
||||
import net.momirealms.craftengine.core.registry.Holder;
|
||||
import net.momirealms.craftengine.core.registry.Registries;
|
||||
import net.momirealms.craftengine.core.registry.WritableRegistry;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
@@ -18,9 +17,8 @@ public class BlockBehaviors {
|
||||
public static final Key EMPTY = Key.from("craftengine:empty");
|
||||
|
||||
public static void register(Key key, BlockBehaviorFactory factory) {
|
||||
Holder.Reference<BlockBehaviorFactory> holder = ((WritableRegistry<BlockBehaviorFactory>) BuiltInRegistries.BLOCK_BEHAVIOR_FACTORY)
|
||||
.registerForHolder(new ResourceKey<>(Registries.BLOCK_BEHAVIOR_FACTORY.location(), key));
|
||||
holder.bindValue(factory);
|
||||
((WritableRegistry<BlockBehaviorFactory>) BuiltInRegistries.BLOCK_BEHAVIOR_FACTORY)
|
||||
.register(ResourceKey.create(Registries.BLOCK_BEHAVIOR_FACTORY.location(), key), factory);
|
||||
}
|
||||
|
||||
public static BlockBehavior fromMap(CustomBlock block, @Nullable Map<String, Object> map) {
|
||||
|
||||
@@ -3,7 +3,6 @@ package net.momirealms.craftengine.core.block.properties;
|
||||
import net.momirealms.craftengine.core.block.state.properties.*;
|
||||
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
|
||||
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
|
||||
import net.momirealms.craftengine.core.registry.Holder;
|
||||
import net.momirealms.craftengine.core.registry.Registries;
|
||||
import net.momirealms.craftengine.core.registry.WritableRegistry;
|
||||
import net.momirealms.craftengine.core.util.*;
|
||||
@@ -40,8 +39,7 @@ public class Properties {
|
||||
}
|
||||
|
||||
public static void register(Key key, PropertyFactory factory) {
|
||||
Holder.Reference<PropertyFactory> holder = ((WritableRegistry<PropertyFactory>) BuiltInRegistries.PROPERTY_FACTORY).registerForHolder(new ResourceKey<>(Registries.PROPERTY_FACTORY.location(), key));
|
||||
holder.bindValue(factory);
|
||||
((WritableRegistry<PropertyFactory>) BuiltInRegistries.PROPERTY_FACTORY).register(ResourceKey.create(Registries.PROPERTY_FACTORY.location(), key), factory);
|
||||
}
|
||||
|
||||
public static Property<?> fromMap(String name, Map<String, Object> map) {
|
||||
|
||||
@@ -2,7 +2,6 @@ package net.momirealms.craftengine.core.entity.furniture;
|
||||
|
||||
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
|
||||
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
|
||||
import net.momirealms.craftengine.core.registry.Holder;
|
||||
import net.momirealms.craftengine.core.registry.Registries;
|
||||
import net.momirealms.craftengine.core.registry.WritableRegistry;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
@@ -18,9 +17,8 @@ public class HitBoxTypes {
|
||||
public static final Key CUSTOM = Key.of("minecraft:custom");
|
||||
|
||||
public static void register(Key key, HitBoxFactory factory) {
|
||||
Holder.Reference<HitBoxFactory> holder = ((WritableRegistry<HitBoxFactory>) BuiltInRegistries.HITBOX_FACTORY)
|
||||
.registerForHolder(new ResourceKey<>(Registries.HITBOX_FACTORY.location(), key));
|
||||
holder.bindValue(factory);
|
||||
((WritableRegistry<HitBoxFactory>) BuiltInRegistries.HITBOX_FACTORY)
|
||||
.register(ResourceKey.create(Registries.HITBOX_FACTORY.location(), key), factory);
|
||||
}
|
||||
|
||||
public static HitBox fromMap(Map<String, Object> arguments) {
|
||||
|
||||
@@ -9,7 +9,6 @@ import net.momirealms.craftengine.core.sound.SoundSource;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.world.BlockPos;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@@ -330,7 +330,7 @@ public abstract class AbstractItemManager<I> extends AbstractModelGenerator impl
|
||||
// register for recipes
|
||||
Holder.Reference<Key> holder = BuiltInRegistries.OPTIMIZED_ITEM_ID.get(id)
|
||||
.orElseGet(() -> ((WritableRegistry<Key>) BuiltInRegistries.OPTIMIZED_ITEM_ID)
|
||||
.register(new ResourceKey<>(BuiltInRegistries.OPTIMIZED_ITEM_ID.key().location(), id), id));
|
||||
.register(ResourceKey.create(BuiltInRegistries.OPTIMIZED_ITEM_ID.key().location(), id), id));
|
||||
|
||||
boolean isVanillaItem = isVanillaItem(id);
|
||||
Key material = Key.from(isVanillaItem ? id.value() : ResourceConfigUtils.requireNonEmptyStringOrThrow(section.get("material"), "warning.config.item.missing_material").toLowerCase(Locale.ENGLISH));
|
||||
|
||||
@@ -3,7 +3,6 @@ package net.momirealms.craftengine.core.item.behavior;
|
||||
import net.momirealms.craftengine.core.pack.Pack;
|
||||
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
|
||||
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
|
||||
import net.momirealms.craftengine.core.registry.Holder;
|
||||
import net.momirealms.craftengine.core.registry.Registries;
|
||||
import net.momirealms.craftengine.core.registry.WritableRegistry;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
@@ -20,9 +19,8 @@ public class ItemBehaviors {
|
||||
public static final Key EMPTY = Key.withDefaultNamespace("empty", Key.DEFAULT_NAMESPACE);
|
||||
|
||||
public static void register(Key key, ItemBehaviorFactory factory) {
|
||||
Holder.Reference<ItemBehaviorFactory> holder = ((WritableRegistry<ItemBehaviorFactory>) BuiltInRegistries.ITEM_BEHAVIOR_FACTORY)
|
||||
.registerForHolder(new ResourceKey<>(Registries.ITEM_BEHAVIOR_FACTORY.location(), key));
|
||||
holder.bindValue(factory);
|
||||
((WritableRegistry<ItemBehaviorFactory>) BuiltInRegistries.ITEM_BEHAVIOR_FACTORY)
|
||||
.register(ResourceKey.create(Registries.ITEM_BEHAVIOR_FACTORY.location(), key), factory);
|
||||
}
|
||||
|
||||
public static ItemBehavior fromMap(Pack pack, Path path, Key id, Map<String, Object> map) {
|
||||
|
||||
@@ -9,7 +9,6 @@ import net.momirealms.craftengine.core.world.BlockPos;
|
||||
import net.momirealms.craftengine.core.world.Vec3d;
|
||||
import net.momirealms.craftengine.core.world.World;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class UseOnContext {
|
||||
private final Player player;
|
||||
|
||||
@@ -2,7 +2,6 @@ package net.momirealms.craftengine.core.item.equipment;
|
||||
|
||||
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
|
||||
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
|
||||
import net.momirealms.craftengine.core.registry.Holder;
|
||||
import net.momirealms.craftengine.core.registry.Registries;
|
||||
import net.momirealms.craftengine.core.registry.WritableRegistry;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
@@ -21,9 +20,8 @@ public final class Equipments {
|
||||
}
|
||||
|
||||
public static void register(Key key, EquipmentFactory factory) {
|
||||
Holder.Reference<EquipmentFactory> holder = ((WritableRegistry<EquipmentFactory>) BuiltInRegistries.EQUIPMENT_FACTORY)
|
||||
.registerForHolder(new ResourceKey<>(Registries.EQUIPMENT_FACTORY.location(), key));
|
||||
holder.bindValue(factory);
|
||||
((WritableRegistry<EquipmentFactory>) BuiltInRegistries.EQUIPMENT_FACTORY)
|
||||
.register(ResourceKey.create(Registries.EQUIPMENT_FACTORY.location(), key), factory);
|
||||
}
|
||||
|
||||
public static Equipment fromMap(Key id, Map<String, Object> map) {
|
||||
|
||||
@@ -3,5 +3,11 @@ package net.momirealms.craftengine.core.item.recipe;
|
||||
public enum CookingRecipeCategory {
|
||||
FOOD,
|
||||
BLOCKS,
|
||||
MISC
|
||||
MISC;
|
||||
|
||||
public static final CookingRecipeCategory[] VALUES = CookingRecipeCategory.values();
|
||||
|
||||
public static CookingRecipeCategory byId(final int id) {
|
||||
return VALUES[id];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,9 +193,8 @@ public class CustomSmithingTransformRecipe<T> implements Recipe<T> {
|
||||
}
|
||||
|
||||
public static void register(Key key, ItemDataProcessor.ProcessorFactory factory) {
|
||||
Holder.Reference<ItemDataProcessor.ProcessorFactory> holder = ((WritableRegistry<ItemDataProcessor.ProcessorFactory>) BuiltInRegistries.SMITHING_RESULT_PROCESSOR_FACTORY)
|
||||
.registerForHolder(new ResourceKey<>(Registries.SMITHING_RESULT_PROCESSOR_FACTORY.location(), key));
|
||||
holder.bindValue(factory);
|
||||
((WritableRegistry<ItemDataProcessor.ProcessorFactory>) BuiltInRegistries.SMITHING_RESULT_PROCESSOR_FACTORY)
|
||||
.register(ResourceKey.create(Registries.SMITHING_RESULT_PROCESSOR_FACTORY.location(), key), factory);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package net.momirealms.craftengine.core.item.recipe;
|
||||
|
||||
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
|
||||
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
|
||||
import net.momirealms.craftengine.core.registry.Holder;
|
||||
import net.momirealms.craftengine.core.registry.Registries;
|
||||
import net.momirealms.craftengine.core.registry.WritableRegistry;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
@@ -34,9 +33,8 @@ public class RecipeTypes {
|
||||
}
|
||||
|
||||
public static <T> void register(Key key, RecipeFactory<T> factory) {
|
||||
Holder.Reference<RecipeFactory<?>> holder = ((WritableRegistry<RecipeFactory<?>>) BuiltInRegistries.RECIPE_FACTORY)
|
||||
.registerForHolder(new ResourceKey<>(Registries.RECIPE_FACTORY.location(), key));
|
||||
holder.bindValue(factory);
|
||||
((WritableRegistry<RecipeFactory<?>>) BuiltInRegistries.RECIPE_FACTORY)
|
||||
.register(ResourceKey.create(Registries.RECIPE_FACTORY.location(), key), factory);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
package net.momirealms.craftengine.core.item.recipe.network.legacy;
|
||||
|
||||
import net.momirealms.craftengine.core.entity.player.Player;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.item.recipe.CookingRecipeCategory;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.util.FriendlyByteBuf;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
@ApiStatus.Obsolete
|
||||
public class LegacyCookingRecipe implements LegacyRecipe {
|
||||
private Item<Object> result;
|
||||
private final CookingRecipeCategory category;
|
||||
private final String group;
|
||||
private final LegacyIngredient ingredient;
|
||||
private final float experience;
|
||||
private final int cookingTime;
|
||||
|
||||
public LegacyCookingRecipe(LegacyIngredient ingredient,
|
||||
CookingRecipeCategory category,
|
||||
float experience,
|
||||
int cookingTime,
|
||||
Item<Object> result,
|
||||
String group) {
|
||||
this.ingredient = ingredient;
|
||||
this.category = category;
|
||||
this.experience = experience;
|
||||
this.cookingTime = cookingTime;
|
||||
this.result = result;
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyClientboundData(Player player) {
|
||||
this.result = CraftEngine.instance().itemManager().s2c(this.result, player);
|
||||
this.ingredient.applyClientboundData(player);
|
||||
}
|
||||
|
||||
public static LegacyCookingRecipe read(FriendlyByteBuf buf) {
|
||||
String group = buf.readUtf();
|
||||
CookingRecipeCategory category = CookingRecipeCategory.byId(buf.readVarInt());
|
||||
LegacyIngredient ingredient = LegacyIngredient.read(buf);
|
||||
Item<Object> result = CraftEngine.instance().itemManager().decode(buf);
|
||||
float experience = buf.readFloat();
|
||||
int cookingTime = buf.readVarInt();
|
||||
return new LegacyCookingRecipe(ingredient, category, experience, cookingTime, result, group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(FriendlyByteBuf buf) {
|
||||
buf.writeUtf(this.group);
|
||||
buf.writeVarInt(this.category.ordinal());
|
||||
this.ingredient.write(buf);
|
||||
CraftEngine.instance().itemManager().encode(buf, this.result);
|
||||
buf.writeFloat(this.experience);
|
||||
buf.writeVarInt(this.cookingTime);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package net.momirealms.craftengine.core.item.recipe.network.legacy;
|
||||
|
||||
import net.momirealms.craftengine.core.item.recipe.CraftingRecipeCategory;
|
||||
import net.momirealms.craftengine.core.util.FriendlyByteBuf;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
@ApiStatus.Obsolete
|
||||
public class LegacyCustomRecipe implements LegacyRecipe {
|
||||
private final CraftingRecipeCategory category;
|
||||
|
||||
public LegacyCustomRecipe(CraftingRecipeCategory category) {
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
public static LegacyCustomRecipe read(FriendlyByteBuf buf) {
|
||||
CraftingRecipeCategory category = CraftingRecipeCategory.byId(buf.readVarInt());
|
||||
return new LegacyCustomRecipe(category);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(FriendlyByteBuf buf) {
|
||||
buf.writeVarInt(this.category.ordinal());
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package net.momirealms.craftengine.core.item.recipe.network.legacy;
|
||||
|
||||
import net.momirealms.craftengine.core.entity.player.Player;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.item.ItemManager;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.util.FriendlyByteBuf;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
@@ -18,6 +19,10 @@ public class LegacyIngredient {
|
||||
return items;
|
||||
}
|
||||
|
||||
public void write(FriendlyByteBuf buf) {
|
||||
buf.writeArray(this.items, (byteBuf, item) -> CraftEngine.instance().itemManager().encode(byteBuf, item));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static LegacyIngredient read(FriendlyByteBuf buf) {
|
||||
Item<Object>[] items = buf.readArray(byteBuf -> CraftEngine.instance().itemManager().decode(byteBuf), Item.class);
|
||||
@@ -25,9 +30,10 @@ public class LegacyIngredient {
|
||||
}
|
||||
|
||||
public void applyClientboundData(Player player) {
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
Item<Object> item = items[i];
|
||||
this.items[i] = CraftEngine.instance().itemManager().s2c(item, player);
|
||||
ItemManager<Object> manager = CraftEngine.instance().itemManager();
|
||||
for (int i = 0; i < this.items.length; i++) {
|
||||
Item<Object> item = this.items[i];
|
||||
this.items[i] = manager.s2c(item, player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
package net.momirealms.craftengine.core.item.recipe.network.legacy;
|
||||
|
||||
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
|
||||
import net.momirealms.craftengine.core.entity.player.Player;
|
||||
import net.momirealms.craftengine.core.util.FriendlyByteBuf;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.VersionHelper;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
import java.util.function.Function;
|
||||
@@ -11,23 +9,13 @@ import java.util.function.Function;
|
||||
@ApiStatus.Obsolete
|
||||
public interface LegacyRecipe {
|
||||
|
||||
void write(FriendlyByteBuf buf);
|
||||
default void applyClientboundData(Player player) {}
|
||||
|
||||
static LegacyRecipe read(FriendlyByteBuf buf) {
|
||||
if (VersionHelper.isOrAbove1_20_5()) {
|
||||
Key id = buf.readKey();
|
||||
Key type = buf.readKey();
|
||||
return BuiltInRegistries.LEGACY_RECIPE_TYPE.getValue(type).read(id, buf);
|
||||
} else {
|
||||
Key type = buf.readKey();
|
||||
Key id = buf.readKey();
|
||||
return BuiltInRegistries.LEGACY_RECIPE_TYPE.getValue(type).read(id, buf);
|
||||
}
|
||||
}
|
||||
void write(FriendlyByteBuf buf);
|
||||
|
||||
record Type(Function<FriendlyByteBuf, LegacyRecipe> reader) {
|
||||
|
||||
public LegacyRecipe read(Key id, FriendlyByteBuf buf) {
|
||||
public LegacyRecipe read(FriendlyByteBuf buf) {
|
||||
return this.reader.apply(buf);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
package net.momirealms.craftengine.core.item.recipe.network.legacy;
|
||||
|
||||
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
|
||||
import net.momirealms.craftengine.core.util.FriendlyByteBuf;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.VersionHelper;
|
||||
|
||||
public interface LegacyRecipeHolder {
|
||||
|
||||
void write(FriendlyByteBuf buf);
|
||||
|
||||
LegacyRecipe recipe();
|
||||
|
||||
static LegacyRecipeHolder read(FriendlyByteBuf buf) {
|
||||
if (VersionHelper.isOrAbove1_20_5()) {
|
||||
return ModernRecipeHolderImpl.read(buf);
|
||||
} else {
|
||||
return LegacyRecipeHolderImpl.read(buf);
|
||||
}
|
||||
}
|
||||
|
||||
record LegacyRecipeHolderImpl(Key id, Key type, LegacyRecipe recipe) implements LegacyRecipeHolder {
|
||||
|
||||
@Override
|
||||
public void write(FriendlyByteBuf buf) {
|
||||
buf.writeKey(this.type);
|
||||
buf.writeKey(this.id);
|
||||
this.recipe.write(buf);
|
||||
}
|
||||
|
||||
public static LegacyRecipeHolder read(FriendlyByteBuf buf) {
|
||||
Key type = buf.readKey();
|
||||
Key id = buf.readKey();
|
||||
return new LegacyRecipeHolderImpl(id, type, BuiltInRegistries.LEGACY_RECIPE_TYPE.getValue(type).read(buf));
|
||||
}
|
||||
}
|
||||
|
||||
record ModernRecipeHolderImpl(Key id, int type, LegacyRecipe recipe) implements LegacyRecipeHolder {
|
||||
|
||||
@Override
|
||||
public void write(FriendlyByteBuf buf) {
|
||||
buf.writeKey(this.id);
|
||||
buf.writeVarInt(this.type);
|
||||
this.recipe.write(buf);
|
||||
}
|
||||
|
||||
public static LegacyRecipeHolder read(FriendlyByteBuf buf) {
|
||||
Key id = buf.readKey();
|
||||
int type = buf.readVarInt();
|
||||
return new ModernRecipeHolderImpl(id, type, BuiltInRegistries.LEGACY_RECIPE_TYPE.getValue(type).read(buf));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,10 @@
|
||||
package net.momirealms.craftengine.core.item.recipe.network.legacy;
|
||||
|
||||
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
|
||||
import net.momirealms.craftengine.core.registry.Registries;
|
||||
import net.momirealms.craftengine.core.registry.WritableRegistry;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.ResourceKey;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
@ApiStatus.Obsolete
|
||||
@@ -31,4 +35,34 @@ public final class LegacyRecipeTypes {
|
||||
public static final Key SMITHING_TRIM = Key.of("smithing_trim");
|
||||
public static final Key DECORATED_POT_RECIPE = Key.of("crafting_decorated_pot");
|
||||
|
||||
public static void register() {
|
||||
register(SHAPED_RECIPE, new LegacyRecipe.Type(LegacyShapedRecipe::read));
|
||||
register(SHAPELESS_RECIPE, new LegacyRecipe.Type(LegacyShapelessRecipe::read));
|
||||
register(ARMOR_DYE, new LegacyRecipe.Type(LegacyCustomRecipe::read));
|
||||
register(BOOK_CLONING, new LegacyRecipe.Type(LegacyCustomRecipe::read));
|
||||
register(MAP_CLONING, new LegacyRecipe.Type(LegacyCustomRecipe::read));
|
||||
register(MAP_EXTENDING, new LegacyRecipe.Type(LegacyCustomRecipe::read));
|
||||
register(FIREWORK_ROCKET, new LegacyRecipe.Type(LegacyCustomRecipe::read));
|
||||
register(FIREWORK_STAR, new LegacyRecipe.Type(LegacyCustomRecipe::read));
|
||||
register(FIREWORK_STAR_FADE, new LegacyRecipe.Type(LegacyCustomRecipe::read));
|
||||
register(TIPPED_ARROW, new LegacyRecipe.Type(LegacyCustomRecipe::read));
|
||||
register(BANNER_DUPLICATE, new LegacyRecipe.Type(LegacyCustomRecipe::read));
|
||||
register(SHIELD_DECORATION, new LegacyRecipe.Type(LegacyCustomRecipe::read));
|
||||
register(SHULKER_BOX_COLORING, new LegacyRecipe.Type(LegacyCustomRecipe::read));
|
||||
register(SUSPICIOUS_STEW, new LegacyRecipe.Type(LegacyCustomRecipe::read));
|
||||
register(REPAIR_ITEM, new LegacyRecipe.Type(LegacyCustomRecipe::read));
|
||||
register(SMELTING_RECIPE, new LegacyRecipe.Type(LegacyCookingRecipe::read));
|
||||
register(BLASTING_RECIPE, new LegacyRecipe.Type(LegacyCookingRecipe::read));
|
||||
register(SMOKING_RECIPE, new LegacyRecipe.Type(LegacyCookingRecipe::read));
|
||||
register(CAMPFIRE_COOKING_RECIPE, new LegacyRecipe.Type(LegacyCookingRecipe::read));
|
||||
register(STONECUTTER, new LegacyRecipe.Type(LegacyStoneCuttingRecipe::read));
|
||||
register(SMITHING_TRANSFORM, new LegacyRecipe.Type(LegacySmithingTransformRecipe::read));
|
||||
register(SMITHING_TRIM, new LegacyRecipe.Type(LegacySmithingTrimRecipe::read));
|
||||
register(DECORATED_POT_RECIPE, new LegacyRecipe.Type(LegacyCustomRecipe::read));
|
||||
}
|
||||
|
||||
public static void register(Key key, LegacyRecipe.Type type) {
|
||||
((WritableRegistry<LegacyRecipe.Type>) BuiltInRegistries.LEGACY_RECIPE_TYPE)
|
||||
.register(ResourceKey.create(Registries.LEGACY_RECIPE_TYPE.location(), key), type);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,41 +1,45 @@
|
||||
package net.momirealms.craftengine.core.item.recipe.network.legacy;
|
||||
|
||||
import net.momirealms.craftengine.core.entity.player.Player;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.item.recipe.CraftingRecipeCategory;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.util.FriendlyByteBuf;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.VersionHelper;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
@ApiStatus.Obsolete
|
||||
public class LegacyShapedRecipe implements LegacyRecipe {
|
||||
private final int width;
|
||||
private final int height;
|
||||
private final List<LegacyIngredient> ingredients;
|
||||
private final Item<?> result;
|
||||
private final Key id;
|
||||
private Item<Object> result;
|
||||
private final String group;
|
||||
private final CraftingRecipeCategory category;
|
||||
private final boolean showNotification;
|
||||
|
||||
public LegacyShapedRecipe(int width, int height, List<LegacyIngredient> ingredients, Item<?> result, Key id, String group, CraftingRecipeCategory category, boolean showNotification) {
|
||||
public LegacyShapedRecipe(int width, int height,
|
||||
List<LegacyIngredient> ingredients,
|
||||
Item<Object> result,
|
||||
String group,
|
||||
CraftingRecipeCategory category,
|
||||
boolean showNotification) {
|
||||
this.category = category;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.ingredients = ingredients;
|
||||
this.result = result;
|
||||
this.id = id;
|
||||
this.group = group;
|
||||
this.showNotification = showNotification;
|
||||
}
|
||||
|
||||
private static final BiFunction<Key, FriendlyByteBuf, LegacyShapedRecipe> READER = VersionHelper.isOrAbove1_20_3() ?
|
||||
(id, buf) -> {
|
||||
private static final Function<FriendlyByteBuf, LegacyShapedRecipe> READER = VersionHelper.isOrAbove1_20_3() ?
|
||||
(buf) -> {
|
||||
String group = buf.readUtf();
|
||||
int category = buf.readVarInt();
|
||||
int width = buf.readVarInt();
|
||||
@@ -43,13 +47,13 @@ public class LegacyShapedRecipe implements LegacyRecipe {
|
||||
int size = width * height;
|
||||
List<LegacyIngredient> ingredients = new ArrayList<>(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
ingredients.set(i, LegacyIngredient.read(buf));
|
||||
ingredients.add(LegacyIngredient.read(buf));
|
||||
}
|
||||
Item<?> result = CraftEngine.instance().itemManager().decode(buf);
|
||||
Item<Object> result = CraftEngine.instance().itemManager().decode(buf);
|
||||
boolean flag = buf.readBoolean();
|
||||
return new LegacyShapedRecipe(width, height, ingredients, result, id, group, CraftingRecipeCategory.byId(category), flag);
|
||||
return new LegacyShapedRecipe(width, height, ingredients, result, group, CraftingRecipeCategory.byId(category), flag);
|
||||
} :
|
||||
(id, buf) -> {
|
||||
(buf) -> {
|
||||
int width = buf.readVarInt();
|
||||
int height = buf.readVarInt();
|
||||
String group = buf.readUtf();
|
||||
@@ -57,19 +61,51 @@ public class LegacyShapedRecipe implements LegacyRecipe {
|
||||
int size = width * height;
|
||||
List<LegacyIngredient> ingredients = new ArrayList<>(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
ingredients.set(i, LegacyIngredient.read(buf));
|
||||
ingredients.add(LegacyIngredient.read(buf));
|
||||
}
|
||||
Item<?> result = CraftEngine.instance().itemManager().decode(buf);
|
||||
Item<Object> result = CraftEngine.instance().itemManager().decode(buf);
|
||||
boolean flag = buf.readBoolean();
|
||||
return new LegacyShapedRecipe(width, height, ingredients, result, id, group, CraftingRecipeCategory.byId(category), flag);
|
||||
return new LegacyShapedRecipe(width, height, ingredients, result, group, CraftingRecipeCategory.byId(category), flag);
|
||||
};
|
||||
|
||||
public static LegacyShapedRecipe read(Key id, FriendlyByteBuf buf) {
|
||||
return READER.apply(id, buf);
|
||||
private static final BiConsumer<LegacyShapedRecipe, FriendlyByteBuf> WRITER = VersionHelper.isOrAbove1_20_3() ?
|
||||
(recipe, buf) -> {
|
||||
buf.writeUtf(recipe.group);
|
||||
buf.writeVarInt(recipe.category.ordinal());
|
||||
buf.writeVarInt(recipe.width);
|
||||
buf.writeVarInt(recipe.height);
|
||||
for (LegacyIngredient ingredient : recipe.ingredients) {
|
||||
ingredient.write(buf);
|
||||
}
|
||||
CraftEngine.instance().itemManager().encode(buf, recipe.result);
|
||||
buf.writeBoolean(recipe.showNotification);
|
||||
} :
|
||||
(recipe, buf) -> {
|
||||
buf.writeVarInt(recipe.width);
|
||||
buf.writeVarInt(recipe.height);
|
||||
buf.writeUtf(recipe.group);
|
||||
buf.writeVarInt(recipe.category.ordinal());
|
||||
for (LegacyIngredient ingredient : recipe.ingredients) {
|
||||
ingredient.write(buf);
|
||||
}
|
||||
CraftEngine.instance().itemManager().encode(buf, recipe.result);
|
||||
buf.writeBoolean(recipe.showNotification);
|
||||
};
|
||||
|
||||
@Override
|
||||
public void applyClientboundData(Player player) {
|
||||
this.result = CraftEngine.instance().itemManager().s2c(this.result, player);
|
||||
for (LegacyIngredient ingredient : this.ingredients) {
|
||||
ingredient.applyClientboundData(player);
|
||||
}
|
||||
}
|
||||
|
||||
public static LegacyShapedRecipe read(FriendlyByteBuf buf) {
|
||||
return READER.apply(buf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(FriendlyByteBuf buf) {
|
||||
|
||||
WRITER.accept(this, buf);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
package net.momirealms.craftengine.core.item.recipe.network.legacy;
|
||||
|
||||
import net.momirealms.craftengine.core.entity.player.Player;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.item.recipe.CraftingRecipeCategory;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.util.FriendlyByteBuf;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ApiStatus.Obsolete
|
||||
public class LegacyShapelessRecipe implements LegacyRecipe {
|
||||
private final List<LegacyIngredient> ingredients;
|
||||
private Item<Object> result;
|
||||
private final String group;
|
||||
private final CraftingRecipeCategory category;
|
||||
|
||||
public LegacyShapelessRecipe(List<LegacyIngredient> ingredients,
|
||||
Item<Object> result,
|
||||
String group,
|
||||
CraftingRecipeCategory category) {
|
||||
this.category = category;
|
||||
this.ingredients = ingredients;
|
||||
this.result = result;
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyClientboundData(Player player) {
|
||||
this.result = CraftEngine.instance().itemManager().s2c(this.result, player);
|
||||
for (LegacyIngredient ingredient : this.ingredients) {
|
||||
ingredient.applyClientboundData(player);
|
||||
}
|
||||
}
|
||||
|
||||
public static LegacyShapelessRecipe read(FriendlyByteBuf buf) {
|
||||
String group = buf.readUtf();
|
||||
CraftingRecipeCategory category = CraftingRecipeCategory.byId(buf.readVarInt());
|
||||
List<LegacyIngredient> ingredient = buf.readCollection(ArrayList::new, LegacyIngredient::read);
|
||||
Item<Object> result = CraftEngine.instance().itemManager().decode(buf);
|
||||
return new LegacyShapelessRecipe(ingredient, result, group, category);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(FriendlyByteBuf buf) {
|
||||
buf.writeUtf(this.group);
|
||||
buf.writeVarInt(this.category.ordinal());
|
||||
buf.writeCollection(this.ingredients, (byteBuf, legacyIngredient) -> legacyIngredient.write(buf));
|
||||
CraftEngine.instance().itemManager().encode(buf, this.result);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package net.momirealms.craftengine.core.item.recipe.network.legacy;
|
||||
|
||||
import net.momirealms.craftengine.core.entity.player.Player;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.util.FriendlyByteBuf;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
@ApiStatus.Obsolete
|
||||
public class LegacySmithingTransformRecipe implements LegacyRecipe {
|
||||
private final LegacyIngredient template;
|
||||
private final LegacyIngredient base;
|
||||
private final LegacyIngredient addition;
|
||||
private Item<Object> result;
|
||||
|
||||
public LegacySmithingTransformRecipe(LegacyIngredient addition, LegacyIngredient template, LegacyIngredient base, Item<Object> result) {
|
||||
this.addition = addition;
|
||||
this.template = template;
|
||||
this.base = base;
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyClientboundData(Player player) {
|
||||
this.result = CraftEngine.instance().itemManager().s2c(this.result, player);
|
||||
this.template.applyClientboundData(player);
|
||||
this.base.applyClientboundData(player);
|
||||
this.addition.applyClientboundData(player);
|
||||
}
|
||||
|
||||
public static LegacySmithingTransformRecipe read(FriendlyByteBuf buf) {
|
||||
LegacyIngredient template = LegacyIngredient.read(buf);
|
||||
LegacyIngredient base = LegacyIngredient.read(buf);
|
||||
LegacyIngredient addition = LegacyIngredient.read(buf);
|
||||
Item<Object> result = CraftEngine.instance().itemManager().decode(buf);
|
||||
return new LegacySmithingTransformRecipe(template, base, addition, result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(FriendlyByteBuf buf) {
|
||||
this.template.write(buf);
|
||||
this.base.write(buf);
|
||||
this.addition.write(buf);
|
||||
CraftEngine.instance().itemManager().encode(buf, this.result);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package net.momirealms.craftengine.core.item.recipe.network.legacy;
|
||||
|
||||
import net.momirealms.craftengine.core.entity.player.Player;
|
||||
import net.momirealms.craftengine.core.util.FriendlyByteBuf;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
@ApiStatus.Obsolete
|
||||
public class LegacySmithingTrimRecipe implements LegacyRecipe {
|
||||
private final LegacyIngredient template;
|
||||
private final LegacyIngredient base;
|
||||
private final LegacyIngredient addition;
|
||||
|
||||
public LegacySmithingTrimRecipe(LegacyIngredient addition, LegacyIngredient template, LegacyIngredient base) {
|
||||
this.addition = addition;
|
||||
this.template = template;
|
||||
this.base = base;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyClientboundData(Player player) {
|
||||
this.template.applyClientboundData(player);
|
||||
this.base.applyClientboundData(player);
|
||||
this.addition.applyClientboundData(player);
|
||||
}
|
||||
|
||||
public static LegacySmithingTrimRecipe read(FriendlyByteBuf buf) {
|
||||
LegacyIngredient template = LegacyIngredient.read(buf);
|
||||
LegacyIngredient base = LegacyIngredient.read(buf);
|
||||
LegacyIngredient addition = LegacyIngredient.read(buf);
|
||||
return new LegacySmithingTrimRecipe(template, base, addition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(FriendlyByteBuf buf) {
|
||||
this.template.write(buf);
|
||||
this.base.write(buf);
|
||||
this.addition.write(buf);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package net.momirealms.craftengine.core.item.recipe.network.legacy;
|
||||
|
||||
import net.momirealms.craftengine.core.entity.player.Player;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.util.FriendlyByteBuf;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
@ApiStatus.Obsolete
|
||||
public class LegacyStoneCuttingRecipe implements LegacyRecipe {
|
||||
private Item<Object> result;
|
||||
private final String group;
|
||||
private final LegacyIngredient ingredient;
|
||||
|
||||
public LegacyStoneCuttingRecipe(LegacyIngredient ingredient,
|
||||
Item<Object> result,
|
||||
String group) {
|
||||
this.ingredient = ingredient;
|
||||
this.result = result;
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyClientboundData(Player player) {
|
||||
this.result = CraftEngine.instance().itemManager().s2c(this.result, player);
|
||||
this.ingredient.applyClientboundData(player);
|
||||
}
|
||||
|
||||
public static LegacyStoneCuttingRecipe read(FriendlyByteBuf buf) {
|
||||
String group = buf.readUtf();
|
||||
LegacyIngredient ingredient = LegacyIngredient.read(buf);
|
||||
Item<Object> result = CraftEngine.instance().itemManager().decode(buf);
|
||||
return new LegacyStoneCuttingRecipe(ingredient, result, group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(FriendlyByteBuf buf) {
|
||||
buf.writeUtf(this.group);
|
||||
this.ingredient.write(buf);
|
||||
CraftEngine.instance().itemManager().encode(buf, this.result);
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,13 @@
|
||||
package net.momirealms.craftengine.core.item.recipe.network.modern.display;
|
||||
|
||||
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
|
||||
import net.momirealms.craftengine.core.registry.Holder;
|
||||
import net.momirealms.craftengine.core.registry.Registries;
|
||||
import net.momirealms.craftengine.core.registry.WritableRegistry;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.ResourceKey;
|
||||
|
||||
public final class RecipeDisplays {
|
||||
private RecipeDisplays() {}
|
||||
public final class RecipeDisplayTypes {
|
||||
private RecipeDisplayTypes() {}
|
||||
|
||||
public static final Key CRAFTING_SHAPELESS = Key.of("crafting_shapeless");
|
||||
public static final Key CRAFTING_SHAPED = Key.of("crafting_shaped");
|
||||
@@ -25,8 +24,6 @@ public final class RecipeDisplays {
|
||||
}
|
||||
|
||||
public static void register(Key key, RecipeDisplay.Type type) {
|
||||
Holder.Reference<RecipeDisplay.Type> holder = ((WritableRegistry<RecipeDisplay.Type>) BuiltInRegistries.RECIPE_DISPLAY_TYPE)
|
||||
.registerForHolder(new ResourceKey<>(Registries.RECIPE_DISPLAY_TYPE.location(), key));
|
||||
holder.bindValue(type);
|
||||
((WritableRegistry<RecipeDisplay.Type>) BuiltInRegistries.RECIPE_DISPLAY_TYPE).register(ResourceKey.create(Registries.RECIPE_DISPLAY_TYPE.location(), key), type);
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,13 @@
|
||||
package net.momirealms.craftengine.core.item.recipe.network.modern.display.slot;
|
||||
|
||||
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
|
||||
import net.momirealms.craftengine.core.registry.Holder;
|
||||
import net.momirealms.craftengine.core.registry.Registries;
|
||||
import net.momirealms.craftengine.core.registry.WritableRegistry;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.ResourceKey;
|
||||
|
||||
public final class SlotDisplays {
|
||||
private SlotDisplays() {}
|
||||
public final class SlotDisplayTypes {
|
||||
private SlotDisplayTypes() {}
|
||||
|
||||
public static final Key EMPTY = Key.of("empty");
|
||||
public static final Key ANY_FUEL = Key.of("any_fuel");
|
||||
@@ -31,8 +30,7 @@ public final class SlotDisplays {
|
||||
}
|
||||
|
||||
public static void register(Key key, SlotDisplay.Type type) {
|
||||
Holder.Reference<SlotDisplay.Type> holder = ((WritableRegistry<SlotDisplay.Type>) BuiltInRegistries.SLOT_DISPLAY_TYPE)
|
||||
.registerForHolder(new ResourceKey<>(Registries.SLOT_DISPLAY_TYPE.location(), key));
|
||||
holder.bindValue(type);
|
||||
((WritableRegistry<SlotDisplay.Type>) BuiltInRegistries.SLOT_DISPLAY_TYPE)
|
||||
.register(ResourceKey.create(Registries.SLOT_DISPLAY_TYPE.location(), key), type);
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@ import net.momirealms.craftengine.core.plugin.context.Condition;
|
||||
import net.momirealms.craftengine.core.plugin.context.condition.*;
|
||||
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
|
||||
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
|
||||
import net.momirealms.craftengine.core.registry.Holder;
|
||||
import net.momirealms.craftengine.core.registry.Registries;
|
||||
import net.momirealms.craftengine.core.registry.WritableRegistry;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
@@ -41,9 +40,8 @@ public class LootConditions {
|
||||
}
|
||||
|
||||
public static void register(Key key, ConditionFactory<LootContext> factory) {
|
||||
Holder.Reference<ConditionFactory<LootContext>> holder = ((WritableRegistry<ConditionFactory<LootContext>>) BuiltInRegistries.LOOT_CONDITION_FACTORY)
|
||||
.registerForHolder(new ResourceKey<>(Registries.LOOT_CONDITION_FACTORY.location(), key));
|
||||
holder.bindValue(factory);
|
||||
((WritableRegistry<ConditionFactory<LootContext>>) BuiltInRegistries.LOOT_CONDITION_FACTORY)
|
||||
.register(ResourceKey.create(Registries.LOOT_CONDITION_FACTORY.location(), key), factory);
|
||||
}
|
||||
|
||||
public static <T> Predicate<T> andConditions(List<? extends Predicate<T>> predicates) {
|
||||
|
||||
@@ -2,7 +2,6 @@ package net.momirealms.craftengine.core.loot.entry;
|
||||
|
||||
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
|
||||
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
|
||||
import net.momirealms.craftengine.core.registry.Holder;
|
||||
import net.momirealms.craftengine.core.registry.Registries;
|
||||
import net.momirealms.craftengine.core.registry.WritableRegistry;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
@@ -27,9 +26,8 @@ public class LootEntryContainers {
|
||||
}
|
||||
|
||||
public static <T> void register(Key key, LootEntryContainerFactory<T> factory) {
|
||||
Holder.Reference<LootEntryContainerFactory<?>> holder = ((WritableRegistry<LootEntryContainerFactory<?>>) BuiltInRegistries.LOOT_ENTRY_CONTAINER_FACTORY)
|
||||
.registerForHolder(new ResourceKey<>(Registries.LOOT_ENTRY_CONTAINER_FACTORY.location(), key));
|
||||
holder.bindValue(factory);
|
||||
((WritableRegistry<LootEntryContainerFactory<?>>) BuiltInRegistries.LOOT_ENTRY_CONTAINER_FACTORY)
|
||||
.register(ResourceKey.create(Registries.LOOT_ENTRY_CONTAINER_FACTORY.location(), key), factory);
|
||||
}
|
||||
|
||||
public static <T> List<LootEntryContainer<T>> fromMapList(List<Map<String, Object>> mapList) {
|
||||
|
||||
@@ -8,7 +8,6 @@ import net.momirealms.craftengine.core.plugin.context.Condition;
|
||||
import net.momirealms.craftengine.core.plugin.context.parameter.DirectContextParameters;
|
||||
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
|
||||
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
|
||||
import net.momirealms.craftengine.core.registry.Holder;
|
||||
import net.momirealms.craftengine.core.registry.Registries;
|
||||
import net.momirealms.craftengine.core.registry.WritableRegistry;
|
||||
import net.momirealms.craftengine.core.util.*;
|
||||
@@ -81,9 +80,8 @@ public class ApplyBonusCountFunction<T> extends AbstractLootConditionalFunction<
|
||||
}
|
||||
|
||||
public static void register(Key key, FormulaFactory factory) {
|
||||
Holder.Reference<FormulaFactory> holder = ((WritableRegistry<FormulaFactory>) BuiltInRegistries.FORMULA_FACTORY)
|
||||
.registerForHolder(new ResourceKey<>(Registries.FORMULA_FACTORY.location(), key));
|
||||
holder.bindValue(factory);
|
||||
((WritableRegistry<FormulaFactory>) BuiltInRegistries.FORMULA_FACTORY)
|
||||
.register(ResourceKey.create(Registries.FORMULA_FACTORY.location(), key), factory);
|
||||
}
|
||||
|
||||
public static Formula fromMap(Map<String, Object> map) {
|
||||
|
||||
@@ -4,7 +4,6 @@ import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.loot.LootContext;
|
||||
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
|
||||
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
|
||||
import net.momirealms.craftengine.core.registry.Holder;
|
||||
import net.momirealms.craftengine.core.registry.Registries;
|
||||
import net.momirealms.craftengine.core.registry.WritableRegistry;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
@@ -30,9 +29,8 @@ public class LootFunctions {
|
||||
}
|
||||
|
||||
public static <T> void register(Key key, LootFunctionFactory<T> factory) {
|
||||
Holder.Reference<LootFunctionFactory<?>> holder = ((WritableRegistry<LootFunctionFactory<?>>) BuiltInRegistries.LOOT_FUNCTION_FACTORY)
|
||||
.registerForHolder(new ResourceKey<>(Registries.LOOT_FUNCTION_FACTORY.location(), key));
|
||||
holder.bindValue(factory);
|
||||
((WritableRegistry<LootFunctionFactory<?>>) BuiltInRegistries.LOOT_FUNCTION_FACTORY)
|
||||
.register(ResourceKey.create(Registries.LOOT_FUNCTION_FACTORY.location(), key), factory);
|
||||
}
|
||||
|
||||
public static <T> BiFunction<Item<T>, LootContext, Item<T>> identity() {
|
||||
|
||||
@@ -5,7 +5,6 @@ import net.momirealms.craftengine.core.plugin.context.Condition;
|
||||
import net.momirealms.craftengine.core.plugin.context.condition.*;
|
||||
import net.momirealms.craftengine.core.plugin.locale.LocalizedException;
|
||||
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
|
||||
import net.momirealms.craftengine.core.registry.Holder;
|
||||
import net.momirealms.craftengine.core.registry.Registries;
|
||||
import net.momirealms.craftengine.core.registry.WritableRegistry;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
@@ -37,9 +36,8 @@ public class PathMatchers {
|
||||
}
|
||||
|
||||
public static void register(Key key, ConditionFactory<PathContext> factory) {
|
||||
Holder.Reference<ConditionFactory<PathContext>> holder = ((WritableRegistry<ConditionFactory<PathContext>>) BuiltInRegistries.PATH_MATCHER_FACTORY)
|
||||
.registerForHolder(new ResourceKey<>(Registries.PATH_MATCHER_FACTORY.location(), key));
|
||||
holder.bindValue(factory);
|
||||
((WritableRegistry<ConditionFactory<PathContext>>) BuiltInRegistries.PATH_MATCHER_FACTORY)
|
||||
.register(ResourceKey.create(Registries.PATH_MATCHER_FACTORY.location(), key), factory);
|
||||
}
|
||||
|
||||
public static List<Condition<PathContext>> fromMapList(List<Map<String, Object>> arguments) {
|
||||
|
||||
@@ -2,7 +2,6 @@ package net.momirealms.craftengine.core.pack.conflict.resolution;
|
||||
|
||||
import net.momirealms.craftengine.core.plugin.locale.LocalizedException;
|
||||
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
|
||||
import net.momirealms.craftengine.core.registry.Holder;
|
||||
import net.momirealms.craftengine.core.registry.Registries;
|
||||
import net.momirealms.craftengine.core.registry.WritableRegistry;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
@@ -27,8 +26,7 @@ public class Resolutions {
|
||||
}
|
||||
|
||||
public static void register(Key key, ResolutionFactory factory) {
|
||||
Holder.Reference<ResolutionFactory> holder = ((WritableRegistry<ResolutionFactory>) BuiltInRegistries.RESOLUTION_FACTORY).registerForHolder(new ResourceKey<>(Registries.RESOLUTION_FACTORY.location(), key));
|
||||
holder.bindValue(factory);
|
||||
((WritableRegistry<ResolutionFactory>) BuiltInRegistries.RESOLUTION_FACTORY).register(ResourceKey.create(Registries.RESOLUTION_FACTORY.location(), key), factory);
|
||||
}
|
||||
|
||||
public static Resolution fromMap(Map<String, Object> map) {
|
||||
|
||||
@@ -3,7 +3,6 @@ package net.momirealms.craftengine.core.pack.host;
|
||||
import net.momirealms.craftengine.core.pack.host.impl.*;
|
||||
import net.momirealms.craftengine.core.plugin.locale.LocalizedException;
|
||||
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
|
||||
import net.momirealms.craftengine.core.registry.Holder;
|
||||
import net.momirealms.craftengine.core.registry.Registries;
|
||||
import net.momirealms.craftengine.core.registry.WritableRegistry;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
@@ -35,9 +34,8 @@ public class ResourcePackHosts {
|
||||
}
|
||||
|
||||
public static void register(Key key, ResourcePackHostFactory factory) {
|
||||
Holder.Reference<ResourcePackHostFactory> holder = ((WritableRegistry<ResourcePackHostFactory>) BuiltInRegistries.RESOURCE_PACK_HOST_FACTORY)
|
||||
.registerForHolder(new ResourceKey<>(Registries.RESOURCE_PACK_HOST_FACTORY.location(), key));
|
||||
holder.bindValue(factory);
|
||||
((WritableRegistry<ResourcePackHostFactory>) BuiltInRegistries.RESOURCE_PACK_HOST_FACTORY)
|
||||
.register(ResourceKey.create(Registries.RESOURCE_PACK_HOST_FACTORY.location(), key), factory);
|
||||
}
|
||||
|
||||
public static ResourcePackHost fromMap(Map<String, Object> map) {
|
||||
|
||||
@@ -3,7 +3,6 @@ package net.momirealms.craftengine.core.pack.model;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
|
||||
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
|
||||
import net.momirealms.craftengine.core.registry.Holder;
|
||||
import net.momirealms.craftengine.core.registry.Registries;
|
||||
import net.momirealms.craftengine.core.registry.WritableRegistry;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
@@ -41,15 +40,13 @@ public class ItemModels {
|
||||
}
|
||||
|
||||
public static void registerFactory(Key key, ItemModelFactory factory) {
|
||||
Holder.Reference<ItemModelFactory> holder = ((WritableRegistry<ItemModelFactory>) BuiltInRegistries.ITEM_MODEL_FACTORY)
|
||||
.registerForHolder(new ResourceKey<>(Registries.ITEM_MODEL_FACTORY.location(), key));
|
||||
holder.bindValue(factory);
|
||||
((WritableRegistry<ItemModelFactory>) BuiltInRegistries.ITEM_MODEL_FACTORY)
|
||||
.register(ResourceKey.create(Registries.ITEM_MODEL_FACTORY.location(), key), factory);
|
||||
}
|
||||
|
||||
public static void registerReader(Key key, ItemModelReader reader) {
|
||||
Holder.Reference<ItemModelReader> holder = ((WritableRegistry<ItemModelReader>) BuiltInRegistries.ITEM_MODEL_READER)
|
||||
.registerForHolder(new ResourceKey<>(Registries.ITEM_MODEL_READER.location(), key));
|
||||
holder.bindValue(reader);
|
||||
((WritableRegistry<ItemModelReader>) BuiltInRegistries.ITEM_MODEL_READER)
|
||||
.register(ResourceKey.create(Registries.ITEM_MODEL_READER.location(), key), reader);
|
||||
}
|
||||
|
||||
public static ItemModel fromMap(Map<String, Object> map) {
|
||||
|
||||
@@ -3,7 +3,6 @@ package net.momirealms.craftengine.core.pack.model.condition;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
|
||||
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
|
||||
import net.momirealms.craftengine.core.registry.Holder;
|
||||
import net.momirealms.craftengine.core.registry.Registries;
|
||||
import net.momirealms.craftengine.core.registry.WritableRegistry;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
@@ -57,15 +56,13 @@ public class ConditionProperties {
|
||||
}
|
||||
|
||||
public static void registerFactory(Key key, ConditionPropertyFactory factory) {
|
||||
Holder.Reference<ConditionPropertyFactory> holder = ((WritableRegistry<ConditionPropertyFactory>) BuiltInRegistries.CONDITION_PROPERTY_FACTORY)
|
||||
.registerForHolder(new ResourceKey<>(Registries.CONDITION_PROPERTY_FACTORY.location(), key));
|
||||
holder.bindValue(factory);
|
||||
((WritableRegistry<ConditionPropertyFactory>) BuiltInRegistries.CONDITION_PROPERTY_FACTORY)
|
||||
.register(ResourceKey.create(Registries.CONDITION_PROPERTY_FACTORY.location(), key), factory);
|
||||
}
|
||||
|
||||
public static void registerReader(Key key, ConditionPropertyReader reader) {
|
||||
Holder.Reference<ConditionPropertyReader> holder = ((WritableRegistry<ConditionPropertyReader>) BuiltInRegistries.CONDITION_PROPERTY_READER)
|
||||
.registerForHolder(new ResourceKey<>(Registries.CONDITION_PROPERTY_READER.location(), key));
|
||||
holder.bindValue(reader);
|
||||
((WritableRegistry<ConditionPropertyReader>) BuiltInRegistries.CONDITION_PROPERTY_READER)
|
||||
.register(ResourceKey.create(Registries.CONDITION_PROPERTY_READER.location(), key), reader);
|
||||
}
|
||||
|
||||
public static ConditionProperty fromMap(Map<String, Object> map) {
|
||||
|
||||
@@ -3,7 +3,6 @@ package net.momirealms.craftengine.core.pack.model.rangedisptach;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
|
||||
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
|
||||
import net.momirealms.craftengine.core.registry.Holder;
|
||||
import net.momirealms.craftengine.core.registry.Registries;
|
||||
import net.momirealms.craftengine.core.registry.WritableRegistry;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
@@ -48,15 +47,13 @@ public class RangeDispatchProperties {
|
||||
}
|
||||
|
||||
public static void registerFactory(Key key, RangeDispatchPropertyFactory factory) {
|
||||
Holder.Reference<RangeDispatchPropertyFactory> holder = ((WritableRegistry<RangeDispatchPropertyFactory>) BuiltInRegistries.RANGE_DISPATCH_PROPERTY_FACTORY)
|
||||
.registerForHolder(new ResourceKey<>(Registries.RANGE_DISPATCH_PROPERTY_FACTORY.location(), key));
|
||||
holder.bindValue(factory);
|
||||
((WritableRegistry<RangeDispatchPropertyFactory>) BuiltInRegistries.RANGE_DISPATCH_PROPERTY_FACTORY)
|
||||
.register(ResourceKey.create(Registries.RANGE_DISPATCH_PROPERTY_FACTORY.location(), key), factory);
|
||||
}
|
||||
|
||||
public static void registerReader(Key key, RangeDispatchPropertyReader reader) {
|
||||
Holder.Reference<RangeDispatchPropertyReader> holder = ((WritableRegistry<RangeDispatchPropertyReader>) BuiltInRegistries.RANGE_DISPATCH_PROPERTY_READER)
|
||||
.registerForHolder(new ResourceKey<>(Registries.RANGE_DISPATCH_PROPERTY_READER.location(), key));
|
||||
holder.bindValue(reader);
|
||||
((WritableRegistry<RangeDispatchPropertyReader>) BuiltInRegistries.RANGE_DISPATCH_PROPERTY_READER)
|
||||
.register(ResourceKey.create(Registries.RANGE_DISPATCH_PROPERTY_READER.location(), key), reader);
|
||||
}
|
||||
|
||||
public static RangeDispatchProperty fromMap(Map<String, Object> map) {
|
||||
|
||||
@@ -3,7 +3,6 @@ package net.momirealms.craftengine.core.pack.model.select;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
|
||||
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
|
||||
import net.momirealms.craftengine.core.registry.Holder;
|
||||
import net.momirealms.craftengine.core.registry.Registries;
|
||||
import net.momirealms.craftengine.core.registry.WritableRegistry;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
@@ -48,15 +47,13 @@ public class SelectProperties {
|
||||
}
|
||||
|
||||
public static void registerFactory(Key key, SelectPropertyFactory factory) {
|
||||
Holder.Reference<SelectPropertyFactory> holder = ((WritableRegistry<SelectPropertyFactory>) BuiltInRegistries.SELECT_PROPERTY_FACTORY)
|
||||
.registerForHolder(new ResourceKey<>(Registries.SELECT_PROPERTY_FACTORY.location(), key));
|
||||
holder.bindValue(factory);
|
||||
((WritableRegistry<SelectPropertyFactory>) BuiltInRegistries.SELECT_PROPERTY_FACTORY)
|
||||
.register(ResourceKey.create(Registries.SELECT_PROPERTY_FACTORY.location(), key), factory);
|
||||
}
|
||||
|
||||
public static void registerReader(Key key, SelectPropertyReader reader) {
|
||||
Holder.Reference<SelectPropertyReader> holder = ((WritableRegistry<SelectPropertyReader>) BuiltInRegistries.SELECT_PROPERTY_READER)
|
||||
.registerForHolder(new ResourceKey<>(Registries.SELECT_PROPERTY_READER.location(), key));
|
||||
holder.bindValue(reader);
|
||||
((WritableRegistry<SelectPropertyReader>) BuiltInRegistries.SELECT_PROPERTY_READER)
|
||||
.register(ResourceKey.create(Registries.SELECT_PROPERTY_READER.location(), key), reader);
|
||||
}
|
||||
|
||||
public static SelectProperty fromMap(Map<String, Object> map) {
|
||||
|
||||
@@ -3,7 +3,6 @@ package net.momirealms.craftengine.core.pack.model.special;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
|
||||
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
|
||||
import net.momirealms.craftengine.core.registry.Holder;
|
||||
import net.momirealms.craftengine.core.registry.Registries;
|
||||
import net.momirealms.craftengine.core.registry.WritableRegistry;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
@@ -54,15 +53,13 @@ public class SpecialModels {
|
||||
}
|
||||
|
||||
public static void registerFactory(Key key, SpecialModelFactory factory) {
|
||||
Holder.Reference<SpecialModelFactory> holder = ((WritableRegistry<SpecialModelFactory>) BuiltInRegistries.SPECIAL_MODEL_FACTORY)
|
||||
.registerForHolder(new ResourceKey<>(Registries.SPECIAL_MODEL_FACTORY.location(), key));
|
||||
holder.bindValue(factory);
|
||||
((WritableRegistry<SpecialModelFactory>) BuiltInRegistries.SPECIAL_MODEL_FACTORY)
|
||||
.register(ResourceKey.create(Registries.SPECIAL_MODEL_FACTORY.location(), key), factory);
|
||||
}
|
||||
|
||||
public static void registerReader(Key key, SpecialModelReader factory) {
|
||||
Holder.Reference<SpecialModelReader> holder = ((WritableRegistry<SpecialModelReader>) BuiltInRegistries.SPECIAL_MODEL_READER)
|
||||
.registerForHolder(new ResourceKey<>(Registries.SPECIAL_MODEL_READER.location(), key));
|
||||
holder.bindValue(factory);
|
||||
public static void registerReader(Key key, SpecialModelReader reader) {
|
||||
((WritableRegistry<SpecialModelReader>) BuiltInRegistries.SPECIAL_MODEL_READER)
|
||||
.register(ResourceKey.create(Registries.SPECIAL_MODEL_READER.location(), key), reader);
|
||||
}
|
||||
|
||||
public static SpecialModel fromMap(Map<String, Object> map) {
|
||||
|
||||
@@ -3,7 +3,6 @@ package net.momirealms.craftengine.core.pack.model.tint;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
|
||||
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
|
||||
import net.momirealms.craftengine.core.registry.Holder;
|
||||
import net.momirealms.craftengine.core.registry.Registries;
|
||||
import net.momirealms.craftengine.core.registry.WritableRegistry;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
@@ -42,15 +41,13 @@ public class Tints {
|
||||
}
|
||||
|
||||
public static void registerFactory(Key key, TintFactory factory) {
|
||||
Holder.Reference<TintFactory> holder = ((WritableRegistry<TintFactory>) BuiltInRegistries.TINT_FACTORY)
|
||||
.registerForHolder(new ResourceKey<>(Registries.TINT_FACTORY.location(), key));
|
||||
holder.bindValue(factory);
|
||||
((WritableRegistry<TintFactory>) BuiltInRegistries.TINT_FACTORY)
|
||||
.register(ResourceKey.create(Registries.TINT_FACTORY.location(), key), factory);
|
||||
}
|
||||
|
||||
public static void registerReader(Key key, TintReader reader) {
|
||||
Holder.Reference<TintReader> holder = ((WritableRegistry<TintReader>) BuiltInRegistries.TINT_READER)
|
||||
.registerForHolder(new ResourceKey<>(Registries.TINT_READER.location(), key));
|
||||
holder.bindValue(reader);
|
||||
((WritableRegistry<TintReader>) BuiltInRegistries.TINT_READER)
|
||||
.register(ResourceKey.create(Registries.TINT_READER.location(), key), reader);
|
||||
}
|
||||
|
||||
public static Tint fromMap(Map<String, Object> map) {
|
||||
|
||||
@@ -7,8 +7,9 @@ import net.momirealms.craftengine.core.entity.projectile.ProjectileManager;
|
||||
import net.momirealms.craftengine.core.font.FontManager;
|
||||
import net.momirealms.craftengine.core.item.ItemManager;
|
||||
import net.momirealms.craftengine.core.item.recipe.RecipeManager;
|
||||
import net.momirealms.craftengine.core.item.recipe.network.modern.display.RecipeDisplays;
|
||||
import net.momirealms.craftengine.core.item.recipe.network.modern.display.slot.SlotDisplays;
|
||||
import net.momirealms.craftengine.core.item.recipe.network.legacy.LegacyRecipeTypes;
|
||||
import net.momirealms.craftengine.core.item.recipe.network.modern.display.RecipeDisplayTypes;
|
||||
import net.momirealms.craftengine.core.item.recipe.network.modern.display.slot.SlotDisplayTypes;
|
||||
import net.momirealms.craftengine.core.loot.VanillaLootManager;
|
||||
import net.momirealms.craftengine.core.pack.PackManager;
|
||||
import net.momirealms.craftengine.core.plugin.classpath.ClassPathAppender;
|
||||
@@ -95,8 +96,9 @@ public abstract class CraftEngine implements Plugin {
|
||||
}
|
||||
|
||||
protected void onPluginLoad() {
|
||||
RecipeDisplays.register();
|
||||
SlotDisplays.register();
|
||||
RecipeDisplayTypes.register();
|
||||
SlotDisplayTypes.register();
|
||||
LegacyRecipeTypes.register();
|
||||
((Logger) LogManager.getRootLogger()).addFilter(new LogFilter());
|
||||
((Logger) LogManager.getRootLogger()).addFilter(new DisconnectLogFilter());
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package net.momirealms.craftengine.core.plugin.config.template;
|
||||
|
||||
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
|
||||
import net.momirealms.craftengine.core.registry.Holder;
|
||||
import net.momirealms.craftengine.core.registry.Registries;
|
||||
import net.momirealms.craftengine.core.registry.WritableRegistry;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
@@ -19,9 +18,8 @@ public class TemplateArguments {
|
||||
public static final Key OBJECT = Key.of("craftengine:object"); // No Factory, internal use
|
||||
|
||||
public static void register(Key key, TemplateArgumentFactory factory) {
|
||||
Holder.Reference<TemplateArgumentFactory> holder = ((WritableRegistry<TemplateArgumentFactory>) BuiltInRegistries.TEMPLATE_ARGUMENT_FACTORY)
|
||||
.registerForHolder(new ResourceKey<>(Registries.TEMPLATE_ARGUMENT_FACTORY.location(), key));
|
||||
holder.bindValue(factory);
|
||||
((WritableRegistry<TemplateArgumentFactory>) BuiltInRegistries.TEMPLATE_ARGUMENT_FACTORY)
|
||||
.register(ResourceKey.create(Registries.TEMPLATE_ARGUMENT_FACTORY.location(), key), factory);
|
||||
}
|
||||
|
||||
static {
|
||||
|
||||
@@ -5,7 +5,6 @@ import net.momirealms.craftengine.core.plugin.context.PlayerOptionalContext;
|
||||
import net.momirealms.craftengine.core.plugin.context.condition.*;
|
||||
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
|
||||
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
|
||||
import net.momirealms.craftengine.core.registry.Holder;
|
||||
import net.momirealms.craftengine.core.registry.Registries;
|
||||
import net.momirealms.craftengine.core.registry.WritableRegistry;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
@@ -40,9 +39,8 @@ public class EventConditions {
|
||||
}
|
||||
|
||||
public static void register(Key key, ConditionFactory<PlayerOptionalContext> factory) {
|
||||
Holder.Reference<ConditionFactory<PlayerOptionalContext>> holder = ((WritableRegistry<ConditionFactory<PlayerOptionalContext>>) BuiltInRegistries.EVENT_CONDITION_FACTORY)
|
||||
.registerForHolder(new ResourceKey<>(Registries.EVENT_CONDITION_FACTORY.location(), key));
|
||||
holder.bindValue(factory);
|
||||
((WritableRegistry<ConditionFactory<PlayerOptionalContext>>) BuiltInRegistries.EVENT_CONDITION_FACTORY)
|
||||
.register(ResourceKey.create(Registries.EVENT_CONDITION_FACTORY.location(), key), factory);
|
||||
}
|
||||
|
||||
public static Condition<PlayerOptionalContext> fromMap(Map<String, Object> map) {
|
||||
|
||||
@@ -4,7 +4,6 @@ import net.momirealms.craftengine.core.plugin.context.PlayerOptionalContext;
|
||||
import net.momirealms.craftengine.core.plugin.context.function.*;
|
||||
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
|
||||
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
|
||||
import net.momirealms.craftengine.core.registry.Holder;
|
||||
import net.momirealms.craftengine.core.registry.Registries;
|
||||
import net.momirealms.craftengine.core.registry.WritableRegistry;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
@@ -42,9 +41,8 @@ public class EventFunctions {
|
||||
}
|
||||
|
||||
public static void register(Key key, FunctionFactory<PlayerOptionalContext> factory) {
|
||||
Holder.Reference<FunctionFactory<PlayerOptionalContext>> holder = ((WritableRegistry<FunctionFactory<PlayerOptionalContext>>) BuiltInRegistries.EVENT_FUNCTION_FACTORY)
|
||||
.registerForHolder(new ResourceKey<>(Registries.EVENT_FUNCTION_FACTORY.location(), key));
|
||||
holder.bindValue(factory);
|
||||
((WritableRegistry<FunctionFactory<PlayerOptionalContext>>) BuiltInRegistries.EVENT_FUNCTION_FACTORY)
|
||||
.register(ResourceKey.create(Registries.EVENT_FUNCTION_FACTORY.location(), key), factory);
|
||||
}
|
||||
|
||||
public static Function<PlayerOptionalContext> fromMap(Map<String, Object> map) {
|
||||
|
||||
@@ -2,7 +2,6 @@ package net.momirealms.craftengine.core.plugin.context.number;
|
||||
|
||||
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
|
||||
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
|
||||
import net.momirealms.craftengine.core.registry.Holder;
|
||||
import net.momirealms.craftengine.core.registry.Registries;
|
||||
import net.momirealms.craftengine.core.registry.WritableRegistry;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
@@ -27,9 +26,8 @@ public class NumberProviders {
|
||||
}
|
||||
|
||||
public static void register(Key key, NumberProviderFactory factory) {
|
||||
Holder.Reference<NumberProviderFactory> holder = ((WritableRegistry<NumberProviderFactory>) BuiltInRegistries.NUMBER_PROVIDER_FACTORY)
|
||||
.registerForHolder(new ResourceKey<>(Registries.NUMBER_PROVIDER_FACTORY.location(), key));
|
||||
holder.bindValue(factory);
|
||||
((WritableRegistry<NumberProviderFactory>) BuiltInRegistries.NUMBER_PROVIDER_FACTORY)
|
||||
.register(ResourceKey.create(Registries.NUMBER_PROVIDER_FACTORY.location(), key), factory);
|
||||
}
|
||||
|
||||
public static List<NumberProvider> fromMapList(List<Map<String, Object>> mapList) {
|
||||
|
||||
@@ -4,7 +4,6 @@ import net.momirealms.craftengine.core.plugin.context.Condition;
|
||||
import net.momirealms.craftengine.core.plugin.context.Context;
|
||||
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
|
||||
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
|
||||
import net.momirealms.craftengine.core.registry.Holder;
|
||||
import net.momirealms.craftengine.core.registry.Registries;
|
||||
import net.momirealms.craftengine.core.registry.WritableRegistry;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
@@ -26,9 +25,8 @@ public class PlayerSelectors {
|
||||
}
|
||||
|
||||
public static void register(Key key, PlayerSelectorFactory<?> factory) {
|
||||
Holder.Reference<PlayerSelectorFactory<?>> holder = ((WritableRegistry<PlayerSelectorFactory<?>>) BuiltInRegistries.PLAYER_SELECTOR_FACTORY)
|
||||
.registerForHolder(new ResourceKey<>(Registries.PLAYER_SELECTOR_FACTORY.location(), key));
|
||||
holder.bindValue(factory);
|
||||
((WritableRegistry<PlayerSelectorFactory<?>>) BuiltInRegistries.PLAYER_SELECTOR_FACTORY)
|
||||
.register(ResourceKey.create(Registries.PLAYER_SELECTOR_FACTORY.location(), key), factory);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -7,13 +7,13 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class MappedRegistry<T> implements WritableRegistry<T> {
|
||||
private final ResourceKey<? extends Registry<T>> key;
|
||||
private final Map<Key, Holder.Reference<T>> byResourceLocation = new HashMap<>(512);
|
||||
private final Map<ResourceKey<T>, Holder.Reference<T>> byResourceKey = new HashMap<>(512);
|
||||
private final List<Holder.Reference<T>> byId = new ArrayList<>(512);
|
||||
public abstract class AbstractMappedRegistry<T> implements WritableRegistry<T> {
|
||||
protected final ResourceKey<? extends Registry<T>> key;
|
||||
protected final Map<Key, Holder.Reference<T>> byResourceLocation = new HashMap<>(512);
|
||||
protected final Map<ResourceKey<T>, Holder.Reference<T>> byResourceKey = new HashMap<>(512);
|
||||
protected final List<Holder.Reference<T>> byId = new ArrayList<>(512);
|
||||
|
||||
public MappedRegistry(ResourceKey<? extends Registry<T>> key) {
|
||||
protected AbstractMappedRegistry(ResourceKey<? extends Registry<T>> key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
@@ -22,30 +22,6 @@ public class MappedRegistry<T> implements WritableRegistry<T> {
|
||||
return this.key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Holder.Reference<T> registerForHolder(ResourceKey<T> key) {
|
||||
Objects.requireNonNull(key);
|
||||
if (!key.registry().equals(this.key.location())) {
|
||||
throw new IllegalStateException(key + " is not allowed to be registered in " + this.key);
|
||||
}
|
||||
if (this.byResourceLocation.containsKey(key.location())) {
|
||||
throw new IllegalStateException("Adding duplicate key '" + key + "' to registry");
|
||||
} else {
|
||||
Holder.Reference<T> reference = this.byResourceKey.computeIfAbsent(key, k -> Holder.Reference.create(this, k));
|
||||
this.byResourceKey.put(key, reference);
|
||||
this.byResourceLocation.put(key.location(), reference);
|
||||
this.byId.add(reference);
|
||||
return reference;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Holder.Reference<T> register(ResourceKey<T> key, T value) {
|
||||
Holder.Reference<T> holder = registerForHolder(key);
|
||||
holder.bindValue(value);
|
||||
return holder;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public T getValue(@Nullable ResourceKey<T> key) {
|
||||
@@ -40,44 +40,48 @@ import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.ResourceKey;
|
||||
|
||||
public class BuiltInRegistries {
|
||||
public static final Registry<CustomBlock> BLOCK = createRegistry(Registries.BLOCK);
|
||||
public static final Registry<Key> OPTIMIZED_ITEM_ID = createRegistry(Registries.OPTIMIZED_ITEM_ID);
|
||||
public static final Registry<BlockBehaviorFactory> BLOCK_BEHAVIOR_FACTORY = createRegistry(Registries.BLOCK_BEHAVIOR_FACTORY);
|
||||
public static final Registry<ItemBehaviorFactory> ITEM_BEHAVIOR_FACTORY = createRegistry(Registries.ITEM_BEHAVIOR_FACTORY);
|
||||
public static final Registry<PropertyFactory> PROPERTY_FACTORY = createRegistry(Registries.PROPERTY_FACTORY);
|
||||
public static final Registry<LootFunctionFactory<?>> LOOT_FUNCTION_FACTORY = createRegistry(Registries.LOOT_FUNCTION_FACTORY);
|
||||
public static final Registry<ConditionFactory<LootContext>> LOOT_CONDITION_FACTORY = createRegistry(Registries.LOOT_CONDITION_FACTORY);
|
||||
public static final Registry<LootEntryContainerFactory<?>> LOOT_ENTRY_CONTAINER_FACTORY = createRegistry(Registries.LOOT_ENTRY_CONTAINER_FACTORY);
|
||||
public static final Registry<NumberProviderFactory> NUMBER_PROVIDER_FACTORY = createRegistry(Registries.NUMBER_PROVIDER_FACTORY);
|
||||
public static final Registry<TemplateArgumentFactory> TEMPLATE_ARGUMENT_FACTORY = createRegistry(Registries.TEMPLATE_ARGUMENT_FACTORY);
|
||||
public static final Registry<ItemModelFactory> ITEM_MODEL_FACTORY = createRegistry(Registries.ITEM_MODEL_FACTORY);
|
||||
public static final Registry<ItemModelReader> ITEM_MODEL_READER = createRegistry(Registries.ITEM_MODEL_READER);
|
||||
public static final Registry<TintFactory> TINT_FACTORY = createRegistry(Registries.TINT_FACTORY);
|
||||
public static final Registry<TintReader> TINT_READER = createRegistry(Registries.TINT_READER);
|
||||
public static final Registry<SpecialModelFactory> SPECIAL_MODEL_FACTORY = createRegistry(Registries.SPECIAL_MODEL_FACTORY);
|
||||
public static final Registry<SpecialModelReader> SPECIAL_MODEL_READER = createRegistry(Registries.SPECIAL_MODEL_READER);
|
||||
public static final Registry<RangeDispatchPropertyFactory> RANGE_DISPATCH_PROPERTY_FACTORY = createRegistry(Registries.RANGE_DISPATCH_PROPERTY_FACTORY);
|
||||
public static final Registry<RangeDispatchPropertyReader> RANGE_DISPATCH_PROPERTY_READER = createRegistry(Registries.RANGE_DISPATCH_PROPERTY_READER);
|
||||
public static final Registry<ConditionPropertyFactory> CONDITION_PROPERTY_FACTORY = createRegistry(Registries.CONDITION_PROPERTY_FACTORY);
|
||||
public static final Registry<ConditionPropertyReader> CONDITION_PROPERTY_READER = createRegistry(Registries.CONDITION_PROPERTY_READER);
|
||||
public static final Registry<SelectPropertyFactory> SELECT_PROPERTY_FACTORY = createRegistry(Registries.SELECT_PROPERTY_FACTORY);
|
||||
public static final Registry<SelectPropertyReader> SELECT_PROPERTY_READER = createRegistry(Registries.SELECT_PROPERTY_READER);
|
||||
public static final Registry<RecipeFactory<?>> RECIPE_FACTORY = createRegistry(Registries.RECIPE_FACTORY);
|
||||
public static final Registry<ApplyBonusCountFunction.FormulaFactory> FORMULA_FACTORY = createRegistry(Registries.FORMULA_FACTORY);
|
||||
public static final Registry<ConditionFactory<PathContext>> PATH_MATCHER_FACTORY = createRegistry(Registries.PATH_MATCHER_FACTORY);
|
||||
public static final Registry<ResolutionFactory> RESOLUTION_FACTORY = createRegistry(Registries.RESOLUTION_FACTORY);
|
||||
public static final Registry<CustomSmithingTransformRecipe.ItemDataProcessor.ProcessorFactory> SMITHING_RESULT_PROCESSOR_FACTORY = createRegistry(Registries.SMITHING_RESULT_PROCESSOR_FACTORY);
|
||||
public static final Registry<HitBoxFactory> HITBOX_FACTORY = createRegistry(Registries.HITBOX_FACTORY);
|
||||
public static final Registry<ResourcePackHostFactory> RESOURCE_PACK_HOST_FACTORY = createRegistry(Registries.RESOURCE_PACK_HOST_FACTORY);
|
||||
public static final Registry<FunctionFactory<PlayerOptionalContext>> EVENT_FUNCTION_FACTORY = createRegistry(Registries.EVENT_FUNCTION_FACTORY);
|
||||
public static final Registry<ConditionFactory<PlayerOptionalContext>> EVENT_CONDITION_FACTORY = createRegistry(Registries.EVENT_CONDITION_FACTORY);
|
||||
public static final Registry<PlayerSelectorFactory<?>> PLAYER_SELECTOR_FACTORY = createRegistry(Registries.PLAYER_SELECTOR_FACTORY);
|
||||
public static final Registry<EquipmentFactory> EQUIPMENT_FACTORY = createRegistry(Registries.EQUIPMENT_FACTORY);
|
||||
public static final Registry<SlotDisplay.Type> SLOT_DISPLAY_TYPE = createRegistry(Registries.SLOT_DISPLAY_TYPE);
|
||||
public static final Registry<RecipeDisplay.Type> RECIPE_DISPLAY_TYPE = createRegistry(Registries.RECIPE_DISPLAY_TYPE);
|
||||
public static final Registry<LegacyRecipe.Type> LEGACY_RECIPE_TYPE = createRegistry(Registries.LEGACY_RECIPE_TYPE);
|
||||
public static final Registry<CustomBlock> BLOCK = createDynamicBoundRegistry(Registries.BLOCK);
|
||||
public static final Registry<Key> OPTIMIZED_ITEM_ID = createConstantBoundRegistry(Registries.OPTIMIZED_ITEM_ID);
|
||||
public static final Registry<BlockBehaviorFactory> BLOCK_BEHAVIOR_FACTORY = createConstantBoundRegistry(Registries.BLOCK_BEHAVIOR_FACTORY);
|
||||
public static final Registry<ItemBehaviorFactory> ITEM_BEHAVIOR_FACTORY = createConstantBoundRegistry(Registries.ITEM_BEHAVIOR_FACTORY);
|
||||
public static final Registry<PropertyFactory> PROPERTY_FACTORY = createConstantBoundRegistry(Registries.PROPERTY_FACTORY);
|
||||
public static final Registry<LootFunctionFactory<?>> LOOT_FUNCTION_FACTORY = createConstantBoundRegistry(Registries.LOOT_FUNCTION_FACTORY);
|
||||
public static final Registry<ConditionFactory<LootContext>> LOOT_CONDITION_FACTORY = createConstantBoundRegistry(Registries.LOOT_CONDITION_FACTORY);
|
||||
public static final Registry<LootEntryContainerFactory<?>> LOOT_ENTRY_CONTAINER_FACTORY = createConstantBoundRegistry(Registries.LOOT_ENTRY_CONTAINER_FACTORY);
|
||||
public static final Registry<NumberProviderFactory> NUMBER_PROVIDER_FACTORY = createConstantBoundRegistry(Registries.NUMBER_PROVIDER_FACTORY);
|
||||
public static final Registry<TemplateArgumentFactory> TEMPLATE_ARGUMENT_FACTORY = createConstantBoundRegistry(Registries.TEMPLATE_ARGUMENT_FACTORY);
|
||||
public static final Registry<ItemModelFactory> ITEM_MODEL_FACTORY = createConstantBoundRegistry(Registries.ITEM_MODEL_FACTORY);
|
||||
public static final Registry<ItemModelReader> ITEM_MODEL_READER = createConstantBoundRegistry(Registries.ITEM_MODEL_READER);
|
||||
public static final Registry<TintFactory> TINT_FACTORY = createConstantBoundRegistry(Registries.TINT_FACTORY);
|
||||
public static final Registry<TintReader> TINT_READER = createConstantBoundRegistry(Registries.TINT_READER);
|
||||
public static final Registry<SpecialModelFactory> SPECIAL_MODEL_FACTORY = createConstantBoundRegistry(Registries.SPECIAL_MODEL_FACTORY);
|
||||
public static final Registry<SpecialModelReader> SPECIAL_MODEL_READER = createConstantBoundRegistry(Registries.SPECIAL_MODEL_READER);
|
||||
public static final Registry<RangeDispatchPropertyFactory> RANGE_DISPATCH_PROPERTY_FACTORY = createConstantBoundRegistry(Registries.RANGE_DISPATCH_PROPERTY_FACTORY);
|
||||
public static final Registry<RangeDispatchPropertyReader> RANGE_DISPATCH_PROPERTY_READER = createConstantBoundRegistry(Registries.RANGE_DISPATCH_PROPERTY_READER);
|
||||
public static final Registry<ConditionPropertyFactory> CONDITION_PROPERTY_FACTORY = createConstantBoundRegistry(Registries.CONDITION_PROPERTY_FACTORY);
|
||||
public static final Registry<ConditionPropertyReader> CONDITION_PROPERTY_READER = createConstantBoundRegistry(Registries.CONDITION_PROPERTY_READER);
|
||||
public static final Registry<SelectPropertyFactory> SELECT_PROPERTY_FACTORY = createConstantBoundRegistry(Registries.SELECT_PROPERTY_FACTORY);
|
||||
public static final Registry<SelectPropertyReader> SELECT_PROPERTY_READER = createConstantBoundRegistry(Registries.SELECT_PROPERTY_READER);
|
||||
public static final Registry<RecipeFactory<?>> RECIPE_FACTORY = createConstantBoundRegistry(Registries.RECIPE_FACTORY);
|
||||
public static final Registry<ApplyBonusCountFunction.FormulaFactory> FORMULA_FACTORY = createConstantBoundRegistry(Registries.FORMULA_FACTORY);
|
||||
public static final Registry<ConditionFactory<PathContext>> PATH_MATCHER_FACTORY = createConstantBoundRegistry(Registries.PATH_MATCHER_FACTORY);
|
||||
public static final Registry<ResolutionFactory> RESOLUTION_FACTORY = createConstantBoundRegistry(Registries.RESOLUTION_FACTORY);
|
||||
public static final Registry<CustomSmithingTransformRecipe.ItemDataProcessor.ProcessorFactory> SMITHING_RESULT_PROCESSOR_FACTORY = createConstantBoundRegistry(Registries.SMITHING_RESULT_PROCESSOR_FACTORY);
|
||||
public static final Registry<HitBoxFactory> HITBOX_FACTORY = createConstantBoundRegistry(Registries.HITBOX_FACTORY);
|
||||
public static final Registry<ResourcePackHostFactory> RESOURCE_PACK_HOST_FACTORY = createConstantBoundRegistry(Registries.RESOURCE_PACK_HOST_FACTORY);
|
||||
public static final Registry<FunctionFactory<PlayerOptionalContext>> EVENT_FUNCTION_FACTORY = createConstantBoundRegistry(Registries.EVENT_FUNCTION_FACTORY);
|
||||
public static final Registry<ConditionFactory<PlayerOptionalContext>> EVENT_CONDITION_FACTORY = createConstantBoundRegistry(Registries.EVENT_CONDITION_FACTORY);
|
||||
public static final Registry<PlayerSelectorFactory<?>> PLAYER_SELECTOR_FACTORY = createConstantBoundRegistry(Registries.PLAYER_SELECTOR_FACTORY);
|
||||
public static final Registry<EquipmentFactory> EQUIPMENT_FACTORY = createConstantBoundRegistry(Registries.EQUIPMENT_FACTORY);
|
||||
public static final Registry<SlotDisplay.Type> SLOT_DISPLAY_TYPE = createConstantBoundRegistry(Registries.SLOT_DISPLAY_TYPE);
|
||||
public static final Registry<RecipeDisplay.Type> RECIPE_DISPLAY_TYPE = createConstantBoundRegistry(Registries.RECIPE_DISPLAY_TYPE);
|
||||
public static final Registry<LegacyRecipe.Type> LEGACY_RECIPE_TYPE = createConstantBoundRegistry(Registries.LEGACY_RECIPE_TYPE);
|
||||
|
||||
private static <T> Registry<T> createRegistry(ResourceKey<? extends Registry<T>> key) {
|
||||
return new MappedRegistry<>(key);
|
||||
private static <T> Registry<T> createConstantBoundRegistry(ResourceKey<? extends Registry<T>> key) {
|
||||
return new ConstantBoundRegistry<>(key);
|
||||
}
|
||||
|
||||
private static <T> Registry<T> createDynamicBoundRegistry(ResourceKey<? extends Registry<T>> key) {
|
||||
return new DynamicBoundRegistry<>(key);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
package net.momirealms.craftengine.core.registry;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.Reference2IntMap;
|
||||
import it.unimi.dsi.fastutil.objects.Reference2IntOpenHashMap;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.MCUtils;
|
||||
import net.momirealms.craftengine.core.util.ResourceKey;
|
||||
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ConstantBoundRegistry<T> extends AbstractMappedRegistry<T> {
|
||||
protected final Reference2IntMap<T> toId = MCUtils.make(new Reference2IntOpenHashMap<>(), map -> map.defaultReturnValue(-1));
|
||||
protected final Map<T, Holder.Reference<T>> byValue = new IdentityHashMap<>(512);
|
||||
|
||||
public ConstantBoundRegistry(ResourceKey<? extends Registry<T>> key) {
|
||||
super(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Holder.Reference<T> registerForHolder(ResourceKey<T> key) {
|
||||
throw new IllegalArgumentException("Cannot register a holder for a MappedRegistry");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Holder.Reference<T> register(ResourceKey<T> key, T value) {
|
||||
Objects.requireNonNull(key);
|
||||
if (!key.registry().equals(super.key.location())) {
|
||||
throw new IllegalStateException(key + " is not allowed to be registered in " + this.key);
|
||||
}
|
||||
if (this.byResourceLocation.containsKey(key.location())) {
|
||||
throw new IllegalStateException("Adding duplicate key '" + key + "' to registry");
|
||||
} else {
|
||||
Holder.Reference<T> reference = this.byResourceKey.computeIfAbsent(key, k -> Holder.Reference.createConstant(this, k, value));
|
||||
this.byResourceKey.put(key, reference);
|
||||
this.byResourceLocation.put(key.location(), reference);
|
||||
int size = this.byId.size();
|
||||
this.byId.add(reference);
|
||||
this.toId.put(value, size);
|
||||
this.byValue.put(value, reference);
|
||||
return reference;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId(T value) {
|
||||
return this.toId.getInt(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Key getKey(T value) {
|
||||
Holder.Reference<T> reference = this.byValue.get(value);
|
||||
if (reference == null) return null;
|
||||
return reference.key().location();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package net.momirealms.craftengine.core.registry;
|
||||
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.ResourceKey;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class DynamicBoundRegistry<T> extends AbstractMappedRegistry<T> {
|
||||
|
||||
public DynamicBoundRegistry(ResourceKey<? extends Registry<T>> key) {
|
||||
super(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Holder.Reference<T> registerForHolder(ResourceKey<T> key) {
|
||||
Objects.requireNonNull(key);
|
||||
if (!key.registry().equals(this.key.location())) {
|
||||
throw new IllegalStateException(key + " is not allowed to be registered in " + this.key);
|
||||
}
|
||||
if (this.byResourceLocation.containsKey(key.location())) {
|
||||
throw new IllegalStateException("Adding duplicate key '" + key + "' to registry");
|
||||
} else {
|
||||
Holder.Reference<T> reference = this.byResourceKey.computeIfAbsent(key, k -> Holder.Reference.create(this, k));
|
||||
this.byResourceKey.put(key, reference);
|
||||
this.byResourceLocation.put(key.location(), reference);
|
||||
this.byId.add(reference);
|
||||
return reference;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Holder.Reference<T> register(ResourceKey<T> key, T value) {
|
||||
Holder.Reference<T> holder = registerForHolder(key);
|
||||
holder.bindValue(value);
|
||||
return holder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId(@Nullable T value) {
|
||||
throw new UnsupportedOperationException("getId is not supported for dynamic bound registry");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Key getKey(T value) {
|
||||
throw new UnsupportedOperationException("getKey is not supported for dynamic bound registry");
|
||||
}
|
||||
}
|
||||
@@ -118,6 +118,10 @@ public interface Holder<T> {
|
||||
return new Reference<>(owner, registryKey, null);
|
||||
}
|
||||
|
||||
public static <T> Reference<T> createConstant(Owner<T> owner, ResourceKey<T> registryKey, T value) {
|
||||
return new Constant<>(owner, registryKey, value);
|
||||
}
|
||||
|
||||
public ResourceKey<T> key() {
|
||||
if (this.key == null) {
|
||||
throw new IllegalStateException("Trying to access unbound value '" + this.value + "' from registry " + this.owner);
|
||||
@@ -204,6 +208,18 @@ public interface Holder<T> {
|
||||
public String toString() {
|
||||
return "Reference{" + this.key + "=" + this.value + "}";
|
||||
}
|
||||
|
||||
static class Constant<A> extends Reference<A> {
|
||||
|
||||
public Constant(Owner<A> owner, @Nullable ResourceKey<A> key, @Nullable A value) {
|
||||
super(owner, key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindValue(A value) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
interface Owner<T> {
|
||||
|
||||
@@ -41,40 +41,40 @@ import net.momirealms.craftengine.core.util.ResourceKey;
|
||||
|
||||
public class Registries {
|
||||
public static final Key ROOT_REGISTRY = Key.withDefaultNamespace("root");
|
||||
public static final ResourceKey<Registry<CustomBlock>> BLOCK = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("block"));
|
||||
public static final ResourceKey<Registry<Key>> OPTIMIZED_ITEM_ID = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("optimized_item_id"));
|
||||
public static final ResourceKey<Registry<PropertyFactory>> PROPERTY_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("property_factory"));
|
||||
public static final ResourceKey<Registry<BlockBehaviorFactory>> BLOCK_BEHAVIOR_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("block_behavior_factory"));
|
||||
public static final ResourceKey<Registry<ItemBehaviorFactory>> ITEM_BEHAVIOR_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("item_behavior_factory"));
|
||||
public static final ResourceKey<Registry<LootFunctionFactory<?>>> LOOT_FUNCTION_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("loot_function_factory"));
|
||||
public static final ResourceKey<Registry<LootEntryContainerFactory<?>>> LOOT_ENTRY_CONTAINER_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("loot_entry_container_factory"));
|
||||
public static final ResourceKey<Registry<ConditionFactory<LootContext>>> LOOT_CONDITION_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("loot_condition_factory"));
|
||||
public static final ResourceKey<Registry<NumberProviderFactory>> NUMBER_PROVIDER_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("number_provider_factory"));
|
||||
public static final ResourceKey<Registry<TemplateArgumentFactory>> TEMPLATE_ARGUMENT_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("template_argument_factory"));
|
||||
public static final ResourceKey<Registry<ItemModelFactory>> ITEM_MODEL_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("item_model_factory"));
|
||||
public static final ResourceKey<Registry<ItemModelReader>> ITEM_MODEL_READER = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("item_model_reader"));
|
||||
public static final ResourceKey<Registry<TintFactory>> TINT_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("tint_factory"));
|
||||
public static final ResourceKey<Registry<TintReader>> TINT_READER = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("tint_reader"));
|
||||
public static final ResourceKey<Registry<SpecialModelFactory>> SPECIAL_MODEL_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("special_model_factory"));
|
||||
public static final ResourceKey<Registry<SpecialModelReader>> SPECIAL_MODEL_READER = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("special_model_reader"));
|
||||
public static final ResourceKey<Registry<RangeDispatchPropertyFactory>> RANGE_DISPATCH_PROPERTY_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("range_dispatch_property_factory"));
|
||||
public static final ResourceKey<Registry<RangeDispatchPropertyReader>> RANGE_DISPATCH_PROPERTY_READER = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("range_dispatch_property_reader"));
|
||||
public static final ResourceKey<Registry<ConditionPropertyFactory>> CONDITION_PROPERTY_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("condition_property_factory"));
|
||||
public static final ResourceKey<Registry<ConditionPropertyReader>> CONDITION_PROPERTY_READER = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("condition_property_reader"));
|
||||
public static final ResourceKey<Registry<SelectPropertyFactory>> SELECT_PROPERTY_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("select_property_factory"));
|
||||
public static final ResourceKey<Registry<SelectPropertyReader>> SELECT_PROPERTY_READER = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("select_property_reader"));
|
||||
public static final ResourceKey<Registry<RecipeFactory<?>>> RECIPE_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("recipe_factory"));
|
||||
public static final ResourceKey<Registry<ApplyBonusCountFunction.FormulaFactory>> FORMULA_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("formula_factory"));
|
||||
public static final ResourceKey<Registry<ConditionFactory<PathContext>>> PATH_MATCHER_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("path_matcher_factory"));
|
||||
public static final ResourceKey<Registry<ResolutionFactory>> RESOLUTION_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("resolution_factory"));
|
||||
public static final ResourceKey<Registry<CustomSmithingTransformRecipe.ItemDataProcessor.ProcessorFactory>> SMITHING_RESULT_PROCESSOR_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("smithing_result_processor_factory"));
|
||||
public static final ResourceKey<Registry<HitBoxFactory>> HITBOX_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("hitbox_factory"));
|
||||
public static final ResourceKey<Registry<ResourcePackHostFactory>> RESOURCE_PACK_HOST_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("resource_pack_host_factory"));
|
||||
public static final ResourceKey<Registry<FunctionFactory<PlayerOptionalContext>>> EVENT_FUNCTION_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("event_function_factory"));
|
||||
public static final ResourceKey<Registry<ConditionFactory<PlayerOptionalContext>>> EVENT_CONDITION_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("event_condition_factory"));
|
||||
public static final ResourceKey<Registry<PlayerSelectorFactory<?>>> PLAYER_SELECTOR_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("player_selector_factory"));
|
||||
public static final ResourceKey<Registry<EquipmentFactory>> EQUIPMENT_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("equipment_factory"));
|
||||
public static final ResourceKey<Registry<SlotDisplay.Type>> SLOT_DISPLAY_TYPE = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("slot_display_type"));
|
||||
public static final ResourceKey<Registry<RecipeDisplay.Type>> RECIPE_DISPLAY_TYPE = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("recipe_display_type"));
|
||||
public static final ResourceKey<Registry<LegacyRecipe.Type>> LEGACY_RECIPE_TYPE = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("legacy_recipe_type"));
|
||||
public static final ResourceKey<Registry<CustomBlock>> BLOCK = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("block"));
|
||||
public static final ResourceKey<Registry<Key>> OPTIMIZED_ITEM_ID = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("optimized_item_id"));
|
||||
public static final ResourceKey<Registry<PropertyFactory>> PROPERTY_FACTORY = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("property_factory"));
|
||||
public static final ResourceKey<Registry<BlockBehaviorFactory>> BLOCK_BEHAVIOR_FACTORY = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("block_behavior_factory"));
|
||||
public static final ResourceKey<Registry<ItemBehaviorFactory>> ITEM_BEHAVIOR_FACTORY = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("item_behavior_factory"));
|
||||
public static final ResourceKey<Registry<LootFunctionFactory<?>>> LOOT_FUNCTION_FACTORY = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("loot_function_factory"));
|
||||
public static final ResourceKey<Registry<LootEntryContainerFactory<?>>> LOOT_ENTRY_CONTAINER_FACTORY = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("loot_entry_container_factory"));
|
||||
public static final ResourceKey<Registry<ConditionFactory<LootContext>>> LOOT_CONDITION_FACTORY = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("loot_condition_factory"));
|
||||
public static final ResourceKey<Registry<NumberProviderFactory>> NUMBER_PROVIDER_FACTORY = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("number_provider_factory"));
|
||||
public static final ResourceKey<Registry<TemplateArgumentFactory>> TEMPLATE_ARGUMENT_FACTORY = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("template_argument_factory"));
|
||||
public static final ResourceKey<Registry<ItemModelFactory>> ITEM_MODEL_FACTORY = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("item_model_factory"));
|
||||
public static final ResourceKey<Registry<ItemModelReader>> ITEM_MODEL_READER = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("item_model_reader"));
|
||||
public static final ResourceKey<Registry<TintFactory>> TINT_FACTORY = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("tint_factory"));
|
||||
public static final ResourceKey<Registry<TintReader>> TINT_READER = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("tint_reader"));
|
||||
public static final ResourceKey<Registry<SpecialModelFactory>> SPECIAL_MODEL_FACTORY = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("special_model_factory"));
|
||||
public static final ResourceKey<Registry<SpecialModelReader>> SPECIAL_MODEL_READER = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("special_model_reader"));
|
||||
public static final ResourceKey<Registry<RangeDispatchPropertyFactory>> RANGE_DISPATCH_PROPERTY_FACTORY = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("range_dispatch_property_factory"));
|
||||
public static final ResourceKey<Registry<RangeDispatchPropertyReader>> RANGE_DISPATCH_PROPERTY_READER = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("range_dispatch_property_reader"));
|
||||
public static final ResourceKey<Registry<ConditionPropertyFactory>> CONDITION_PROPERTY_FACTORY = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("condition_property_factory"));
|
||||
public static final ResourceKey<Registry<ConditionPropertyReader>> CONDITION_PROPERTY_READER = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("condition_property_reader"));
|
||||
public static final ResourceKey<Registry<SelectPropertyFactory>> SELECT_PROPERTY_FACTORY = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("select_property_factory"));
|
||||
public static final ResourceKey<Registry<SelectPropertyReader>> SELECT_PROPERTY_READER = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("select_property_reader"));
|
||||
public static final ResourceKey<Registry<RecipeFactory<?>>> RECIPE_FACTORY = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("recipe_factory"));
|
||||
public static final ResourceKey<Registry<ApplyBonusCountFunction.FormulaFactory>> FORMULA_FACTORY = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("formula_factory"));
|
||||
public static final ResourceKey<Registry<ConditionFactory<PathContext>>> PATH_MATCHER_FACTORY = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("path_matcher_factory"));
|
||||
public static final ResourceKey<Registry<ResolutionFactory>> RESOLUTION_FACTORY = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("resolution_factory"));
|
||||
public static final ResourceKey<Registry<CustomSmithingTransformRecipe.ItemDataProcessor.ProcessorFactory>> SMITHING_RESULT_PROCESSOR_FACTORY = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("smithing_result_processor_factory"));
|
||||
public static final ResourceKey<Registry<HitBoxFactory>> HITBOX_FACTORY = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("hitbox_factory"));
|
||||
public static final ResourceKey<Registry<ResourcePackHostFactory>> RESOURCE_PACK_HOST_FACTORY = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("resource_pack_host_factory"));
|
||||
public static final ResourceKey<Registry<FunctionFactory<PlayerOptionalContext>>> EVENT_FUNCTION_FACTORY = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("event_function_factory"));
|
||||
public static final ResourceKey<Registry<ConditionFactory<PlayerOptionalContext>>> EVENT_CONDITION_FACTORY = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("event_condition_factory"));
|
||||
public static final ResourceKey<Registry<PlayerSelectorFactory<?>>> PLAYER_SELECTOR_FACTORY = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("player_selector_factory"));
|
||||
public static final ResourceKey<Registry<EquipmentFactory>> EQUIPMENT_FACTORY = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("equipment_factory"));
|
||||
public static final ResourceKey<Registry<SlotDisplay.Type>> SLOT_DISPLAY_TYPE = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("slot_display_type"));
|
||||
public static final ResourceKey<Registry<RecipeDisplay.Type>> RECIPE_DISPLAY_TYPE = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("recipe_display_type"));
|
||||
public static final ResourceKey<Registry<LegacyRecipe.Type>> LEGACY_RECIPE_TYPE = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("legacy_recipe_type"));
|
||||
}
|
||||
|
||||
@@ -21,6 +21,10 @@ public interface Registry<T> extends Holder.Owner<T> {
|
||||
@Nullable
|
||||
T getValue(int id);
|
||||
|
||||
int getId(T value);
|
||||
|
||||
Key getKey(T value);
|
||||
|
||||
Set<Key> keySet();
|
||||
|
||||
Set<Map.Entry<ResourceKey<T>, T>> entrySet();
|
||||
|
||||
@@ -6,6 +6,10 @@ public interface WritableRegistry<T> extends Registry<T> {
|
||||
|
||||
Holder.Reference<T> registerForHolder(ResourceKey<T> key);
|
||||
|
||||
default Holder.Reference<T> getOrRegisterForHolder(ResourceKey<T> key) {
|
||||
return this.get(key).orElseGet(() -> registerForHolder(key));
|
||||
}
|
||||
|
||||
Holder.Reference<T> register(ResourceKey<T> key, T value);
|
||||
|
||||
boolean isEmpty();
|
||||
|
||||
@@ -365,6 +365,10 @@ public class FriendlyByteBuf extends ByteBuf {
|
||||
return registry.getValue(id);
|
||||
}
|
||||
|
||||
public <T> void writeById(Registry<T> registry, T value) {
|
||||
this.writeVarInt(registry.getId(value));
|
||||
}
|
||||
|
||||
public int readVarInt() {
|
||||
int value = 0;
|
||||
int shift = 0;
|
||||
|
||||
@@ -1,16 +1,22 @@
|
||||
package net.momirealms.craftengine.core.util;
|
||||
|
||||
import com.google.common.collect.MapMaker;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ResourceKey<T> {
|
||||
private static final Map<Internal, ResourceKey<?>> VALUES = (new MapMaker()).weakValues().makeMap();
|
||||
private final Key registry;
|
||||
private final Key location;
|
||||
|
||||
public ResourceKey(Key registry, Key location) {
|
||||
private ResourceKey(Key registry, Key location) {
|
||||
this.registry = registry;
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> ResourceKey<T> create(Key registry, Key location) {
|
||||
return new ResourceKey<>(registry, location);
|
||||
return (ResourceKey<T>) VALUES.computeIfAbsent(new Internal(registry, location), (key) -> new ResourceKey<>(key.registry, key.location));
|
||||
}
|
||||
|
||||
public Key registry() {
|
||||
@@ -25,4 +31,7 @@ public class ResourceKey<T> {
|
||||
public String toString() {
|
||||
return "ResourceKey[" + this.registry + " / " + this.location + "]";
|
||||
}
|
||||
|
||||
record Internal(Key registry, Key location) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ public final class DefaultSectionSerializer {
|
||||
Key key = Key.of(id);
|
||||
Holder<CustomBlock> owner = BuiltInRegistries.BLOCK.get(key).orElseGet(() -> {
|
||||
Holder.Reference<CustomBlock> holder = ((WritableRegistry<CustomBlock>) BuiltInRegistries.BLOCK).registerForHolder(
|
||||
new ResourceKey<>(BuiltInRegistries.BLOCK.key().location(), key));
|
||||
ResourceKey.create(BuiltInRegistries.BLOCK.key().location(), key));
|
||||
InactiveCustomBlock inactiveBlock = new InactiveCustomBlock(key, holder);
|
||||
holder.bindValue(inactiveBlock);
|
||||
return holder;
|
||||
|
||||
Reference in New Issue
Block a user