aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorAnthony Hilyard <anthony.hilyard@gmail.com>2022-06-14 22:24:22 -0700
committerAnthony Hilyard <anthony.hilyard@gmail.com>2022-06-14 22:24:22 -0700
commitee81f0ac1cb848609a755a875f5df0f5d51fa881 (patch)
tree76522b793e92f971f324be7935710c4b3b59ba1f /src/main/java
parent15a3b944d13e54f4241df78b199403d414b9bd69 (diff)
downloadIceberg-ee81f0ac1cb848609a755a875f5df0f5d51fa881.tar.gz
Iceberg-ee81f0ac1cb848609a755a875f5df0f5d51fa881.tar.bz2
Iceberg-ee81f0ac1cb848609a755a875f5df0f5d51fa881.zip
Initial port to 1.19.
Disabled Config Menus for Forge support until it has a 1.19 version. Disabled AutoRegistry since Forge broke it.
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/com/anthonyhilyard/iceberg/mixin/ConfigMenusForgeConfigScreenMixin.java217
-rw-r--r--src/main/java/com/anthonyhilyard/iceberg/mixin/ConfigMenusForgeIEntryDataMixin.java56
-rw-r--r--src/main/java/com/anthonyhilyard/iceberg/mixin/ConfigMenusForgeServerConfigUploaderMixin.java40
-rw-r--r--src/main/java/com/anthonyhilyard/iceberg/mixin/ForgeConfigMenusPlugin.java61
-rw-r--r--src/main/java/com/anthonyhilyard/iceberg/registry/AutoRegistry.java356
-rw-r--r--src/main/java/com/anthonyhilyard/iceberg/registry/RendererRegistrar.java62
-rw-r--r--src/main/java/com/anthonyhilyard/iceberg/util/ConfigMenusForgeHelper.java531
-rw-r--r--src/main/java/com/anthonyhilyard/iceberg/util/DynamicResourcePack.java4
-rw-r--r--src/main/java/com/anthonyhilyard/iceberg/util/Selectors.java3
-rw-r--r--src/main/java/com/anthonyhilyard/iceberg/util/StringRecomposer.java8
10 files changed, 482 insertions, 856 deletions
diff --git a/src/main/java/com/anthonyhilyard/iceberg/mixin/ConfigMenusForgeConfigScreenMixin.java b/src/main/java/com/anthonyhilyard/iceberg/mixin/ConfigMenusForgeConfigScreenMixin.java
deleted file mode 100644
index 42c388d..0000000
--- a/src/main/java/com/anthonyhilyard/iceberg/mixin/ConfigMenusForgeConfigScreenMixin.java
+++ /dev/null
@@ -1,217 +0,0 @@
-package com.anthonyhilyard.iceberg.mixin;
-
-import java.lang.reflect.Constructor;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Stream;
-
-import com.anthonyhilyard.iceberg.Loader;
-import com.anthonyhilyard.iceberg.util.ConfigMenusForgeHelper;
-import com.electronwill.nightconfig.core.UnmodifiableConfig;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Lists;
-
-import org.apache.commons.lang3.exception.ExceptionUtils;
-import org.spongepowered.asm.mixin.Mixin;
-import org.spongepowered.asm.mixin.Unique;
-import org.spongepowered.asm.mixin.injection.Inject;
-import org.spongepowered.asm.mixin.injection.Redirect;
-import org.spongepowered.asm.mixin.injection.At;
-import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
-
-import fuzs.configmenusforge.client.gui.data.IEntryData;
-import fuzs.configmenusforge.client.gui.screens.ConfigScreen;
-import fuzs.configmenusforge.client.util.ServerConfigUploader;
-import net.minecraft.client.gui.screens.Screen;
-import net.minecraft.network.chat.Component;
-import net.minecraft.resources.ResourceLocation;
-import net.minecraftforge.common.ForgeConfigSpec;
-import net.minecraftforge.fml.config.ModConfig;
-
-
-@Mixin(ConfigScreen.class)
-public abstract class ConfigMenusForgeConfigScreenMixin extends Screen
-{
- protected ConfigMenusForgeConfigScreenMixin(Component p_96550_) { super(p_96550_); }
-
- @Unique
- private UnmodifiableConfig mainConfig = null;
-
- @Inject(method = "create", at = @At("HEAD"), remap = false, cancellable = true)
- private static void create(Screen lastScreen, Component title, ResourceLocation background, ModConfig config, Map<Object, IEntryData> valueToData, CallbackInfoReturnable<ConfigScreen> info)
- {
- try
- {
- Constructor<?> mainConstructor = Class.forName("fuzs.configmenusforge.client.gui.screens.ConfigScreen$Main").getDeclaredConstructor(Screen.class, Component.class, ResourceLocation.class, UnmodifiableConfig.class, Map.class, Runnable.class);
- mainConstructor.setAccessible(true);
- info.setReturnValue((ConfigScreen)mainConstructor.newInstance(lastScreen, title, background, ConfigMenusForgeHelper.getValues(config.getSpec()), valueToData, (Runnable)(() -> ServerConfigUploader.saveAndUpload(config))));
- info.cancel();
- return;
- }
- catch (Exception e)
- {
- Loader.LOGGER.warn(ExceptionUtils.getStackTrace(e.getCause()));
- }
- }
-
- @Redirect(method = "<init>(Lnet/minecraft/client/gui/screens/Screen;Lnet/minecraft/network/chat/Component;Lnet/minecraft/resources/ResourceLocation;Lcom/electronwill/nightconfig/core/UnmodifiableConfig;Ljava/util/Map;[I)V",
- at = @At(value = "INVOKE", target = "Ljava/util/Collection;stream()Ljava/util/stream/Stream;", ordinal = 0, remap = false), remap = false)
- Stream<Object> filteredEntries(Collection<Object> values)
- {
- return values.stream().map(value -> {
- if (value instanceof ForgeConfigSpec.ConfigValue<?> configValue && configValue.get() instanceof UnmodifiableConfig config)
- {
- return config;
- }
- else
- {
- return value;
- }
- });
- }
-
- /// TODO: Add extended support for mutable subconfigs by adding an "Add new key" button and ability to delete keys.
-
- // @Shadow(remap = false)
- // @Final
- // @Mutable
- // private List<IEntryData> searchEntries;
-
- // @Shadow(remap = false)
- // @Final
- // @Mutable
- // private List<IEntryData> screenEntries;
-
- // @Shadow(remap = false)
- // @Final
- // @Mutable
- // Map<Object, IEntryData> valueToData;
-
- // @Shadow(remap = false)
- // EditBox searchTextField;
-
- // @Shadow(remap = false)
- // @Final
- // ResourceLocation background;
-
- // @Shadow(remap = false)
- // List<ConfigScreen.Entry> getConfigListEntries(List<IEntryData> entries, final String searchHighlight) { return null; }
-
- // @Inject(method = "getConfigListEntries(Ljava/lang/String;)Ljava/util/List;", at = @At("HEAD"), remap = false, cancellable = true)
- // private void getConfigListEntries(String query, CallbackInfoReturnable<List<ConfigScreen.Entry>> info)
- // {
- // query = query.toLowerCase(Locale.ROOT).trim();
- // if (query.isEmpty())
- // {
- // List<ConfigScreen.Entry> entries = Lists.newArrayList(getConfigListEntries(screenEntries, query));
-
- // // Add an "add new key" button if this is a dynamic subconfig. We can't be sure that's what this is,
- // // since we don't have access to the spec here, so we're going to have to make an assumption...
- // try
- // {
- // if (mainConfig != null && mainConfig.getClass().isAssignableFrom(Class.forName("com.electronwill.nightconfig.core.SimpleCommentedConfig")))
- // {
- // Class<?> categoryEntryClass = Class.forName("fuzs.configmenusforge.client.gui.screens.ConfigScreen$CategoryEntry");
-
- // Constructor<?> categoryEntryConstructor = categoryEntryClass.getDeclaredConstructor(ConfigScreen.class, CategoryEntryData.class, String.class);
- // categoryEntryConstructor.setAccessible(true);
- // ConfigScreen.Entry addNewKeyEntry = (ConfigScreen.Entry) categoryEntryConstructor.newInstance(this, new CategoryEntryData(null, null, null) {
- // // TODO: Make translatable
- // private static Component title = new TextComponent("Add new key");
- // @Override
- // public String getPath() { return null; }
- // @Override
- // public String getComment() { return null; }
- // @Override
- // public Component getTitle() { return title; }
- // @Override
- // public boolean mayResetValue() { return false; }
- // @Override
- // public boolean mayDiscardChanges() { return false; }
- // @Override
- // public void resetCurrentValue() { }
- // @Override
- // public void discardCurrentValue() { }
- // @Override
- // public void saveConfigValue() { }
- // @Override
- // public boolean category() { return false; }
- // }, null);
-
- // Field buttonField = categoryEntryClass.getDeclaredField("button");
- // UnsafeHacks.setField(buttonField, addNewKeyEntry, new Button(10, 5, 260, 20, new TextComponent("Add new key"), button -> {
- // searchTextField.setValue("");
- // searchTextField.setFocus(false);
- // Screen editScreen = new EditStringScreen((ConfigScreen)(Object)this, title, background, "", x -> true, currentValue -> {
- // ((Config)mainConfig).set(currentValue, "");
- // // Update screen and search entries lists.
- // List<IEntryData> newEntries = Lists.newArrayList();
- // ValueSpec newValueSpec = IcebergConfigSpec.createValueSpec(null, null, false, Object.class, () -> null, v -> v != null);
- // final EntryData.ConfigEntryData<?> data = new DynamicConfigEntryData<>(List.of(currentValue), "", newValueSpec, mainConfig);
- // valueToData = Maps.newLinkedHashMap(valueToData);
- // valueToData.put(currentValue, data);
- // gatherEntries(mainConfig, newEntries, valueToData);
- // searchEntries = newEntries;
- // screenEntries = mainConfig.valueMap().values().stream().map(valueToData::get).toList();
- // ((ConfigScreen)(Object)this).updateList(false);
- // });
- // final Minecraft minecraft = Minecraft.getInstance();
- // minecraft.setScreen(editScreen);
- // }));
-
- // entries.add(addNewKeyEntry);
- // }
- // }
- // catch (Exception e)
- // {
- // Loader.LOGGER.info(ExceptionUtils.getStackTrace(e));
- // }
-
- // info.setReturnValue(entries);
- // }
- // else
- // {
- // info.setReturnValue(getConfigListEntries(searchEntries, query));
- // }
-
- // info.cancel();
- // }
-
- @Inject(method = "gatherEntriesRecursive(Lcom/electronwill/nightconfig/core/UnmodifiableConfig;Ljava/util/Map;)Ljava/util/List;",
- at = @At("HEAD"), remap = false, cancellable = true)
- private void gatherEntriesRecursiveSubconfigSupport(UnmodifiableConfig mainConfig, Map<Object, IEntryData> allEntries, CallbackInfoReturnable<List<IEntryData>> info)
- {
- // Store this config for later.
- this.mainConfig = mainConfig;
-
- List<IEntryData> entries = Lists.newArrayList();
- gatherEntries(mainConfig, entries, allEntries);
- info.setReturnValue(ImmutableList.copyOf(entries));
- info.cancel();
- }
-
- @Unique
- private static void gatherEntries(UnmodifiableConfig mainConfig, List<IEntryData> entries, Map<Object, IEntryData> entryMap)
- {
- for (Object value : mainConfig.valueMap().values())
- {
- if (entryMap.get(value) != null)
- {
- entries.add(entryMap.get(value));
- }
- if (value instanceof UnmodifiableConfig config)
- {
- gatherEntries(config, entries, entryMap);
- }
- else if (value instanceof ForgeConfigSpec.ConfigValue<?> configValue && configValue.get() instanceof UnmodifiableConfig config)
- {
- if (entryMap.get(config) != null)
- {
- entries.add(entryMap.get(config));
- }
- gatherEntries(config, entries, entryMap);
- }
- }
- }
-}
diff --git a/src/main/java/com/anthonyhilyard/iceberg/mixin/ConfigMenusForgeIEntryDataMixin.java b/src/main/java/com/anthonyhilyard/iceberg/mixin/ConfigMenusForgeIEntryDataMixin.java
deleted file mode 100644
index 9bd54f6..0000000
--- a/src/main/java/com/anthonyhilyard/iceberg/mixin/ConfigMenusForgeIEntryDataMixin.java
+++ /dev/null
@@ -1,56 +0,0 @@
-package com.anthonyhilyard.iceberg.mixin;
-
-import java.util.Map;
-
-import com.anthonyhilyard.iceberg.util.ConfigMenusForgeHelper;
-import com.electronwill.nightconfig.core.UnmodifiableConfig;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Maps;
-
-import org.spongepowered.asm.mixin.Mixin;
-import org.spongepowered.asm.mixin.Overwrite;
-
-import fuzs.configmenusforge.client.gui.data.IEntryData;
-import net.minecraftforge.fml.config.IConfigSpec;
-import net.minecraftforge.fml.config.ModConfig;
-
-@Mixin(IEntryData.class)
-public interface ConfigMenusForgeIEntryDataMixin
-{
- /**
- * @author Iceberg
- * @reason Overwriting makeValueToDataMap to allow classes other than ForgeConfigSpec to be supported.
- */
- @Overwrite(remap = false)
- public static Map<Object, IEntryData> makeValueToDataMap(ModConfig config)
- {
- if (checkInvalid(config))
- {
- return ImmutableMap.of();
- }
- Map<Object, IEntryData> allData = Maps.newHashMap();
- UnmodifiableConfig spec = config.getSpec();
- ConfigMenusForgeHelper.makeValueToDataMap(spec, ConfigMenusForgeHelper.getValues(spec), config.getConfigData(), allData, "");
- return ImmutableMap.copyOf(allData);
- }
-
- /**
- * @author Iceberg
- * @reason Overwriting checkInvalid to allow classes other than ForgeConfigSpec to be supported.
- */
- @Overwrite(remap = false)
- public static boolean checkInvalid(ModConfig config)
- {
- IConfigSpec<?> spec = config.getSpec();
-
- // True / false means the config class has been cached, null means it's new.
- Boolean cachedValue = ConfigMenusForgeHelper.cachedValidity(spec.getClass());
- if (cachedValue == null)
- {
- // It's not cached, so do the lookup via MethodHandles API and cache the results.
- ConfigMenusForgeHelper.cacheClass(spec.getClass());
- }
-
- return config.getConfigData() == null || !ConfigMenusForgeHelper.cachedValidity(spec.getClass()) || !ConfigMenusForgeHelper.isLoaded(spec);
- }
-}
diff --git a/src/main/java/com/anthonyhilyard/iceberg/mixin/ConfigMenusForgeServerConfigUploaderMixin.java b/src/main/java/com/anthonyhilyard/iceberg/mixin/ConfigMenusForgeServerConfigUploaderMixin.java
deleted file mode 100644
index 003251f..0000000
--- a/src/main/java/com/anthonyhilyard/iceberg/mixin/ConfigMenusForgeServerConfigUploaderMixin.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package com.anthonyhilyard.iceberg.mixin;
-
-import java.io.ByteArrayOutputStream;
-
-import com.anthonyhilyard.iceberg.util.ConfigMenusForgeHelper;
-import com.electronwill.nightconfig.toml.TomlFormat;
-
-import org.spongepowered.asm.mixin.Mixin;
-import org.spongepowered.asm.mixin.injection.Inject;
-import org.spongepowered.asm.mixin.injection.At;
-import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
-
-import fuzs.configmenusforge.ConfigMenusForge;
-import fuzs.configmenusforge.client.util.ModConfigSync;
-import fuzs.configmenusforge.client.util.ServerConfigUploader;
-import fuzs.configmenusforge.network.client.message.C2SSendConfigMessage;
-import net.minecraft.client.Minecraft;
-import net.minecraftforge.fml.config.ModConfig;
-
-@Mixin(ServerConfigUploader.class)
-public class ConfigMenusForgeServerConfigUploaderMixin
-{
- @Inject(method = "saveAndUpload", at = @At("HEAD"), remap = false, cancellable = true)
- private static void saveAndUpload(ModConfig config, CallbackInfo info)
- {
- ConfigMenusForgeHelper.save(config.getSpec());
- ModConfigSync.fireReloadingEvent(config);
- if (config.getType() == ModConfig.Type.SERVER)
- {
- final Minecraft minecraft = Minecraft.getInstance();
- if (minecraft.getConnection() != null && !minecraft.isLocalServer())
- {
- final ByteArrayOutputStream stream = new ByteArrayOutputStream();
- TomlFormat.instance().createWriter().write(config.getConfigData(), stream);
- ConfigMenusForge.NETWORK.sendToServer(new C2SSendConfigMessage(config.getFileName(), stream.toByteArray()));
- }
- }
- info.cancel();
- }
-}
diff --git a/src/main/java/com/anthonyhilyard/iceberg/mixin/ForgeConfigMenusPlugin.java b/src/main/java/com/anthonyhilyard/iceberg/mixin/ForgeConfigMenusPlugin.java
deleted file mode 100644
index 99f08c3..0000000
--- a/src/main/java/com/anthonyhilyard/iceberg/mixin/ForgeConfigMenusPlugin.java
+++ /dev/null
@@ -1,61 +0,0 @@
-package com.anthonyhilyard.iceberg.mixin;
-
-import java.util.List;
-import java.util.Set;
-
-import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
-import org.objectweb.asm.tree.ClassNode;
-import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
-import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
-
-import net.minecraftforge.fml.loading.FMLLoader;
-import net.minecraftforge.fml.loading.LoadingModList;
-import net.minecraftforge.fml.loading.moddiscovery.ModInfo;
-
-public class ForgeConfigMenusPlugin implements IMixinConfigPlugin
-{
- private LoadingModList loadingModList = null;
-
- @Override
- public void onLoad(String mixinPackage) { }
-
- @Override
- public String getRefMapperConfig() { return null; }
-
- @Override
- public boolean shouldApplyMixin(String targetClassName, String mixinClassName)
- {
- if (mixinClassName.toLowerCase().contains("configmenusforge"))
- {
- if (loadingModList == null)
- {
- loadingModList = FMLLoader.getLoadingModList();
- }
-
- // Check if Config Menus for Forge is available.
- for (ModInfo modInfo : loadingModList.getMods())
- {
- // If config menus for forge is loaded AND it is version 3.1.0, load our mixins.
- if (modInfo.getModId().equals("configmenusforge") && modInfo.getVersion().compareTo(new DefaultArtifactVersion("3.1.0")) == 0)
- {
- return true;
- }
- }
-
- return false;
- }
- return true;
- }
-
- @Override
- public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) { }
-
- @Override
- public List<String> getMixins() { return null; }
-
- @Override
- public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { }
-
- @Override
- public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { }
-} \ No newline at end of file
diff --git a/src/main/java/com/anthonyhilyard/iceberg/registry/AutoRegistry.java b/src/main/java/com/anthonyhilyard/iceberg/registry/AutoRegistry.java
index 59803ae..ddf43f0 100644
--- a/src/main/java/com/anthonyhilyard/iceberg/registry/AutoRegistry.java
+++ b/src/main/java/com/anthonyhilyard/iceberg/registry/AutoRegistry.java
@@ -1,178 +1,178 @@
-package com.anthonyhilyard.iceberg.registry;
-
-import java.lang.reflect.Field;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.function.Consumer;
-import java.util.function.Supplier;
-
-import net.minecraft.world.entity.Entity;
-import net.minecraft.world.entity.EntityType;
-import net.minecraft.world.entity.LivingEntity;
-import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
-import net.minecraft.resources.ResourceLocation;
-import net.minecraft.sounds.SoundEvent;
-import net.minecraftforge.event.RegistryEvent;
-import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
-import net.minecraftforge.registries.ForgeRegistries;
-import net.minecraftforge.registries.IForgeRegistry;
-import net.minecraftforge.registries.IForgeRegistryEntry;
-import net.minecraftforge.event.entity.EntityAttributeCreationEvent;
-
-/**
- * Extend this class to have all registerable fields be automatically registered in Forge. Easy. (Just no renderers.)
- */
-public abstract class AutoRegistry
-{
- protected static String MODID = null;
-
- private static boolean entityCreationRegistered = false;
-
- private static Map<EntityType<?>, Supplier<AttributeSupplier.Builder>> entityAttributes = new HashMap<>();
-
- private static Map<String, EntityType<? extends Entity>> registeredEntityTypes = new HashMap<>();
-
- public static void init(String ModID)
- {
- MODID = ModID;
- }
-
- @SuppressWarnings("unchecked")
- protected AutoRegistry()
- {
- try
- {
- // Iterate through every built-in Forge registry...
- for (Field field : ForgeRegistries.class.getDeclaredFields())
- {
- Object fieldObj = field.get(null);
- if (fieldObj instanceof IForgeRegistry)
- {
- // Grab the registry's supertype and add a generic listener for registry events.
- Class<IForgeRegistryEntry<?>> clazz = (Class<IForgeRegistryEntry<?>>)((IForgeRegistry<?>)fieldObj).getRegistrySuperType();
- FMLJavaModLoadingContext.get().getModEventBus().addGenericListener(clazz, (Consumer<RegistryEvent.Register<? extends IForgeRegistryEntry<?>>>)(e) -> registerAllOfType(clazz, e) );
- }
- }
- }
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
- }
-
- public static boolean isEntityTypeRegistered(String name)
- {
- return registeredEntityTypes.containsKey(name);
- }
-
- @SuppressWarnings("unchecked")
- public static <T extends Entity> EntityType<T> getEntityType(String name)
- {
- return (EntityType<T>) registeredEntityTypes.getOrDefault(name, null);
- }
-
- @SuppressWarnings("unchecked")
- private final <T extends IForgeRegistryEntry<T>> void registerAllOfType(Class<IForgeRegistryEntry<?>> type, RegistryEvent.Register<T> event)
- {
- try
- {
- // Loop through all fields we've declared and register them.
- for (Field field : this.getClass().getDeclaredFields())
- {
- // Grab the field and check if it is a Forge registry-compatible type.
- Object obj = field.get(this);
- if (type.isAssignableFrom(obj.getClass()))
- {
- // If this is an entity type field and we haven't already registered for the entity creation event, do so now.
- if (obj instanceof EntityType && !entityCreationRegistered)
- {
- FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onEntityCreation);
- entityCreationRegistered = true;
- }
-
- // If this field has a registry name, register it now.
- T entry = (T)obj;
- if (entry != null && entry.getRegistryName() != null)
- {
- event.getRegistry().register(entry);
- }
- }
- }
- }
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
- }
-
- protected static <T extends Entity> EntityType<T> registerEntity(String name, EntityType.Builder<T> builder)
- {
- return registerEntity(name, builder, (Supplier<AttributeSupplier.Builder>)null);
- }
-
- @SuppressWarnings("unchecked")
- protected static <T extends Entity> EntityType<T> registerEntity(String name, EntityType.Builder<T> builder, Supplier<AttributeSupplier.Builder> attributes)
- {
- if (MODID == null)
- {
- throw new RuntimeException("AutoRegistry was not initialized with mod id!");
- }
-
- // Build the entity type.
- ResourceLocation resourceLocation = new ResourceLocation(MODID, name);
- EntityType<T> entityType = (EntityType<T>) builder.build(name).setRegistryName(resourceLocation);
-
- // Add this entity type to the registered hashmap.
- registeredEntityTypes.put(name, entityType);
-
- // Store mob attributes if provided. These will be added in the attribute creation event below.
- if (attributes != null)
- {
- entityAttributes.put(entityType, attributes);
- }
-
- return entityType;
- }
-
- protected static SoundEvent registerSound(String name)
- {
- if (MODID == null)
- {
- throw new RuntimeException("AutoRegistry was not initialized with mod id!");
- }
-
- ResourceLocation resourceLocation = new ResourceLocation(MODID, name);
- return new SoundEvent(resourceLocation).setRegistryName(resourceLocation);
- }
-
- @SuppressWarnings("unchecked")
- private void onEntityCreation(EntityAttributeCreationEvent event)
- {
- for (Field field : this.getClass().getDeclaredFields())
- {
- try
- {
- // Grab the field and check if it is a Forge registry-compatible type.
- Object obj = field.get(this);
- if (EntityType.class.isAssignableFrom(obj.getClass()) && entityAttributes.containsKey(obj))
- {
- EntityType<? extends LivingEntity> entityType = (EntityType<? extends LivingEntity>) obj;
- if (entityType != null)
- {
- event.put(entityType, entityAttributes.get(obj).get().build());
- }
- }
- }
- catch (ClassCastException e)
- {
- // The class cast exception likely just means that we tried to convert an EntityType with generic type
- // parameter of something other than a LivingEntity subclass. This is fine, so continue.
- continue;
- }
- catch (IllegalAccessException e)
- {
- throw new RuntimeException(e);
- }
- }
- }
-} \ No newline at end of file
+// package com.anthonyhilyard.iceberg.registry;
+
+// import java.lang.reflect.Field;
+// import java.util.HashMap;
+// import java.util.Map;
+// import java.util.function.Consumer;
+// import java.util.function.Supplier;
+
+// import net.minecraft.world.entity.Entity;
+// import net.minecraft.world.entity.EntityType;
+// import net.minecraft.world.entity.LivingEntity;
+// import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
+// import net.minecraft.resources.ResourceLocation;
+// import net.minecraft.sounds.SoundEvent;
+// import net.minecraftforge.event.RegistryEvent;
+// import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
+// import net.minecraftforge.registries.ForgeRegistries;
+// import net.minecraftforge.registries.IForgeRegistry;
+// import net.minecraftforge.registries.IForgeRegistryEntry;
+// import net.minecraftforge.event.entity.EntityAttributeCreationEvent;
+
+// /**
+// * Extend this class to have all registerable fields be automatically registered in Forge. Easy. (Just no renderers.)
+// */
+// public abstract class AutoRegistry
+// {
+// protected static String MODID = null;
+
+// private static boolean entityCreationRegistered = false;
+
+// private static Map<EntityType<?>, Supplier<AttributeSupplier.Builder>> entityAttributes = new HashMap<>();
+
+// private static Map<String, EntityType<? extends Entity>> registeredEntityTypes = new HashMap<>();
+
+// public static void init(String ModID)
+// {
+// MODID = ModID;
+// }
+
+// @SuppressWarnings("unchecked")
+// protected AutoRegistry()
+// {
+// try
+// {
+// // Iterate through every built-in Forge registry...
+// for (Field field : ForgeRegistries.class.getDeclaredFields())
+// {
+// Object fieldObj = field.get(null);
+// if (fieldObj instanceof IForgeRegistry)
+// {
+// // Grab the registry's supertype and add a generic listener for registry events.
+// Class<?> clazz = (Class<?>)((IForgeRegistry<?>)fieldObj).//.getRegistrySuperType();
+// FMLJavaModLoadingContext.get().getModEventBus().addGenericListener(clazz, (Consumer<RegistryEvent.Register<? extends IForgeRegistryEntry<?>>>)(e) -> registerAllOfType(clazz, e) );
+// }
+// }
+// }
+// catch (Exception e)
+// {
+// throw new RuntimeException(e);
+// }
+// }
+
+// public static boolean isEntityTypeRegistered(String name)
+// {
+// return registeredEntityTypes.containsKey(name);
+// }
+
+// @SuppressWarnings("unchecked")
+// public static <T extends Entity> EntityType<T> getEntityType(String name)
+// {
+// return (EntityType<T>) registeredEntityTypes.getOrDefault(name, null);
+// }
+
+// @SuppressWarnings("unchecked")
+// private final <T extends IForgeRegistryEntry<T>> void registerAllOfType(Class<IForgeRegistryEntry<?>> type, RegistryEvent.Register<T> event)
+// {
+// try
+// {
+// // Loop through all fields we've declared and register them.
+// for (Field field : this.getClass().getDeclaredFields())
+// {
+// // Grab the field and check if it is a Forge registry-compatible type.
+// Object obj = field.get(this);
+// if (type.isAssignableFrom(obj.getClass()))
+// {
+// // If this is an entity type field and we haven't already registered for the entity creation event, do so now.
+// if (obj instanceof EntityType && !entityCreationRegistered)
+// {
+// FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onEntityCreation);
+// entityCreationRegistered = true;
+// }
+
+// // If this field has a registry name, register it now.
+// T entry = (T)obj;
+// if (entry != null && entry.getRegistryName() != null)
+// {
+// event.getRegistry().register(entry);
+// }
+// }
+// }
+// }
+// catch (Exception e)
+// {
+// throw new RuntimeException(e);
+// }
+// }
+
+// protected static <T extends Entity> EntityType<T> registerEntity(String name, EntityType.Builder<T> builder)
+// {
+// return registerEntity(name, builder, (Supplier<AttributeSupplier.Builder>)null);
+// }
+
+// @SuppressWarnings("unchecked")
+// protected static <T extends Entity> EntityType<T> registerEntity(String name, EntityType.Builder<T> builder, Supplier<AttributeSupplier.Builder> attributes)
+// {
+// if (MODID == null)
+// {
+// throw new RuntimeException("AutoRegistry was not initialized with mod id!");
+// }
+
+// // Build the entity type.
+// ResourceLocation resourceLocation = new ResourceLocation(MODID, name);
+// EntityType<T> entityType = (EntityType<T>) builder.build(name).setRegistryName(resourceLocation);
+
+// // Add this entity type to the registered hashmap.
+// registeredEntityTypes.put(name, entityType);
+
+// // Store mob attributes if provided. These will be added in the attribute creation event below.
+// if (attributes != null)
+// {
+// entityAttributes.put(entityType, attributes);
+// }
+
+// return entityType;
+// }
+
+// protected static SoundEvent registerSound(String name)
+// {
+// if (MODID == null)
+// {
+// throw new RuntimeException("AutoRegistry was not initialized with mod id!");
+// }
+
+// ResourceLocation resourceLocation = new ResourceLocation(MODID, name);
+// return new SoundEvent(resourceLocation).setRegistryName(resourceLocation);
+// }
+
+// @SuppressWarnings("unchecked")
+// private void onEntityCreation(EntityAttributeCreationEvent event)
+// {
+// for (Field field : this.getClass().getDeclaredFields())
+// {
+// try
+// {
+// // Grab the field and check if it is a Forge registry-compatible type.
+// Object obj = field.get(this);
+// if (EntityType.class.isAssignableFrom(obj.getClass()) && entityAttributes.containsKey(obj))
+// {
+// EntityType<? extends LivingEntity> entityType = (EntityType<? extends LivingEntity>) obj;
+// if (entityType != null)
+// {
+// event.put(entityType, entityAttributes.get(obj).get().build());
+// }
+// }
+// }
+// catch (ClassCastException e)
+// {
+// // The class cast exception likely just means that we tried to convert an EntityType with generic type
+// // parameter of something other than a LivingEntity subclass. This is fine, so continue.
+// continue;
+// }
+// catch (IllegalAccessException e)
+// {
+// throw new RuntimeException(e);
+// }
+// }
+// }
+// } \ No newline at end of file
diff --git a/src/main/java/com/anthonyhilyard/iceberg/registry/RendererRegistrar.java b/src/main/java/com/anthonyhilyard/iceberg/registry/RendererRegistrar.java
index 1b0a053..89d096a 100644
--- a/src/main/java/com/anthonyhilyard/iceberg/registry/RendererRegistrar.java
+++ b/src/main/java/com/anthonyhilyard/iceberg/registry/RendererRegistrar.java
@@ -1,36 +1,36 @@
-package com.anthonyhilyard.iceberg.registry;
+// package com.anthonyhilyard.iceberg.registry;
-import java.util.HashMap;
-import java.util.Map;
+// import java.util.HashMap;
+// import java.util.Map;
-import net.minecraft.world.entity.Entity;
-import net.minecraft.world.entity.EntityType;
-import net.minecraft.client.renderer.entity.EntityRendererProvider;
-import net.minecraftforge.client.event.EntityRenderersEvent;
+// import net.minecraft.world.entity.Entity;
+// import net.minecraft.world.entity.EntityType;
+// import net.minecraft.client.renderer.entity.EntityRendererProvider;
+// import net.minecraftforge.client.event.EntityRenderersEvent;
-public abstract class RendererRegistrar
-{
- private static Map<EntityType<? extends Entity>, EntityRendererProvider<?>> entityRenderers = new HashMap<>();
+// public abstract class RendererRegistrar
+// {
+// private static Map<EntityType<? extends Entity>, EntityRendererProvider<?>> entityRenderers = new HashMap<>();
- protected static <T extends Entity> void registerRenderer(String name, EntityRendererProvider<T> rendererProvider)
- {
- if (AutoRegistry.isEntityTypeRegistered(name))
- {
- // Store this renderer provider.
- entityRenderers.put(AutoRegistry.getEntityType(name), rendererProvider);
- }
- else
- {
- throw new RuntimeException("Tried to register a renderer for an unregistered entity type! Make sure you register renderers after entities.");
- }
- }
+// protected static <T extends Entity> void registerRenderer(String name, EntityRendererProvider<T> rendererProvider)
+// {
+// if (AutoRegistry.isEntityTypeRegistered(name))
+// {
+// // Store this renderer provider.
+// entityRenderers.put(AutoRegistry.getEntityType(name), rendererProvider);
+// }
+// else
+// {
+// throw new RuntimeException("Tried to register a renderer for an unregistered entity type! Make sure you register renderers after entities.");
+// }
+// }
- @SuppressWarnings({"unchecked", "unused"})
- private <T extends Entity> void onEntityCreation(EntityRenderersEvent.RegisterRenderers event)
- {
- for (EntityType<? extends Entity> entityType : entityRenderers.keySet())
- {
- event.registerEntityRenderer((EntityType<T>)entityType, (EntityRendererProvider<T>)entityRenderers.get(entityType));
- }
- }
-}
+// @SuppressWarnings({"unchecked", "unused"})
+// private <T extends Entity> void onEntityCreation(EntityRenderersEvent.RegisterRenderers event)
+// {
+// for (EntityType<? extends Entity> entityType : entityRenderers.keySet())
+// {
+// event.registerEntityRenderer((EntityType<T>)entityType, (EntityRendererProvider<T>)entityRenderers.get(entityType));
+// }
+// }
+// }
diff --git a/src/main/java/com/anthonyhilyard/iceberg/util/ConfigMenusForgeHelper.java b/src/main/java/com/anthonyhilyard/iceberg/util/ConfigMenusForgeHelper.java
index ad4f8d5..6907a3d 100644
--- a/src/main/java/com/anthonyhilyard/iceberg/util/ConfigMenusForgeHelper.java
+++ b/src/main/java/com/anthonyhilyard/iceberg/util/ConfigMenusForgeHelper.java
@@ -1,266 +1,265 @@
-package com.anthonyhilyard.iceberg.util;
-
-import java.lang.invoke.MethodHandle;
-import java.lang.invoke.MethodHandles;
-import java.lang.invoke.MethodType;
-import java.lang.reflect.Field;
-import java.util.List;
-import java.util.Map;
-import java.util.function.Supplier;
-import java.util.stream.Stream;
-
-import com.anthonyhilyard.iceberg.Loader;
-import com.electronwill.nightconfig.core.CommentedConfig;
-import com.electronwill.nightconfig.core.Config;
-import com.electronwill.nightconfig.core.UnmodifiableConfig;
-import com.google.common.collect.Maps;
-import com.google.common.base.Objects;
-import com.google.common.collect.Iterators;
-
-import org.apache.commons.lang3.exception.ExceptionUtils;
-
-import fuzs.configmenusforge.client.gui.data.EntryData;
-import fuzs.configmenusforge.client.gui.data.IEntryData;
-import net.minecraft.network.chat.Component;
-import net.minecraft.network.chat.TextComponent;
-import net.minecraftforge.common.ForgeConfigSpec;
-import net.minecraftforge.fml.unsafe.UnsafeHacks;
-
-public class ConfigMenusForgeHelper
-{
- private final static Map<Class<?>, List<MethodHandle>> configSpecMethodHandles = Maps.newHashMap();
- private final static Map<Class<?>, Boolean> cachedConfigSpecClasses = Maps.newHashMap();
- private final static MethodType getValuesMethodType = MethodType.methodType(UnmodifiableConfig.class);
- private final static MethodType isLoadedMethodType = MethodType.methodType(boolean.class);
- private final static MethodType saveMethodType = MethodType.methodType(void.class);
-
- private static Object callMethod(UnmodifiableConfig spec, int methodIndex)
- {
- Class<?> specClass = spec.getClass();
- if (!cachedConfigSpecClasses.containsKey(specClass))
- {
- cacheClass(specClass);
- }
-
- if (configSpecMethodHandles.containsKey(specClass))
- {
- try
- {
- return configSpecMethodHandles.get(specClass).get(methodIndex).invoke(spec);
- }
- catch (Throwable e)
- {
- Loader.LOGGER.warn(ExceptionUtils.getStackTrace(e));
- }
- }
- return null;
- }
-
- public static UnmodifiableConfig getValues(UnmodifiableConfig spec)
- {
- return (UnmodifiableConfig) callMethod(spec, 0);
- }
-
- public static boolean isLoaded(UnmodifiableConfig spec)
- {
- return (Boolean) callMethod(spec, 1);
- }
-
- public static void save(UnmodifiableConfig spec)
- {
- callMethod(spec, 2);
- }
-
- public static Boolean cachedValidity(Class<?> specClass)
- {
- return cachedConfigSpecClasses.getOrDefault(specClass, null);
- }
-
- public static void cacheClass(Class<?> specClass)
- {
- MethodHandle getValuesMethod = null;
- MethodHandle isLoadedMethod = null;
- MethodHandle saveMethod = null;
- try
- {
- getValuesMethod = MethodHandles.lookup().findVirtual(specClass, "getValues", getValuesMethodType);
- isLoadedMethod = MethodHandles.lookup().findVirtual(specClass, "isLoaded", isLoadedMethodType);
- saveMethod = MethodHandles.lookup().findVirtual(specClass, "save", saveMethodType);
- }
- catch (Throwable e)
- {
- Loader.LOGGER.warn(ExceptionUtils.getStackTrace(e));
- }
-
- // If we found valid getValues, isLoaded and save methods, add them to the cache.
- if (getValuesMethod != null && isLoadedMethod != null && saveMethod != null)
- {
- cachedConfigSpecClasses.put(specClass, true);
- configSpecMethodHandles.put(specClass, List.of(getValuesMethod, isLoadedMethod, saveMethod));
- }
- else
- {
- cachedConfigSpecClasses.put(specClass, false);
- }
- }
-
- /**
- * Changed spec from a ForgeConfigSpec to an UnmodifiableConfig.
- */
- public static void makeValueToDataMap(UnmodifiableConfig spec, UnmodifiableConfig values, CommentedConfig comments, Map<Object, IEntryData> allData, String basePath)
- {
- for (String path : values.valueMap().keySet())
- {
- String currentPath = basePath.isEmpty() ? path : basePath + "." + path;
- Object value = values.valueMap().get(path);
- if (value instanceof UnmodifiableConfig category)
- {
- final EntryData.CategoryEntryData data = new EntryData.CategoryEntryData(path, category, comments.getComment(path));
- allData.put(category, data);
- makeValueToDataMap(spec, category, (CommentedConfig) comments.valueMap().get(path), allData, currentPath);
- }
- else if (value instanceof ForgeConfigSpec.ConfigValue<?> configValue && configValue.get() instanceof UnmodifiableConfig category)
- {
- final EntryData.CategoryEntryData data = new DynamicCategoryEntryData(path, category, comments.getComment(path));
- allData.put(category, data);
- makeValueToDataMap(spec, category, (CommentedConfig) comments.valueMap().get(path), allData, currentPath);
- }
- else if (value instanceof ForgeConfigSpec.ConfigValue<?> configValue)
- {
- final EntryData.ConfigEntryData<?> data = new EntryData.ConfigEntryData<>(path, configValue, spec.getRaw(configValue.getPath()));
- allData.put(configValue, data);
- }
- // Allow non-configvalue values if the parent is a dynamic subconfig.
- else if (!(value instanceof ForgeConfigSpec.ConfigValue<?>) && allData.containsKey(values) && allData.get(values) instanceof DynamicCategoryEntryData)
- {
- final EntryData.ConfigEntryData<?> data = new DynamicConfigEntryData<>(List.of(currentPath.split("\\.")), value, spec.getRaw(currentPath), spec);
- allData.put(value, data);
- }
- }
- }
-
- public static class DynamicCategoryEntryData extends EntryData.CategoryEntryData
- {
- public DynamicCategoryEntryData(String path, UnmodifiableConfig config, String comment) {
- super(path, config, comment);
- }
- }
-
- public static class DynamicConfigEntryData<T> extends EntryData.ConfigEntryData<T>
- {
- private final ForgeConfigSpec.ValueSpec valueSpec;
- private T currentValue;
- private T configValue;
- private final List<String> fullPath;
- private final UnmodifiableConfig spec;
-
- private final static ForgeConfigSpec.ConfigValue<?> dummyConfigValue;
-
- private Component title;
-
- static
- {
- dummyConfigValue = UnsafeHacks.newInstance(ForgeConfigSpec.ConfigValue.class);
- try
- {
- Field specField = ForgeConfigSpec.ConfigValue.class.getDeclaredField("spec");
- UnsafeHacks.setField(specField, dummyConfigValue, UnsafeHacks.newInstance(ForgeConfigSpec.class));
- Field defaultSupplierField = ForgeConfigSpec.ConfigValue.class.getDeclaredField("defaultSupplier");
- UnsafeHacks.setField(defaultSupplierField, dummyConfigValue, (Supplier<?>)(() -> null));
- }
- catch (Exception e) { }
- }
-
- @SuppressWarnings("unchecked")
- public DynamicConfigEntryData(List<String> fullPath, T configValue, ForgeConfigSpec.ValueSpec valueSpec, UnmodifiableConfig spec)
- {
- super(fullPath.get(fullPath.size() - 1), (ForgeConfigSpec.ConfigValue<T>) dummyConfigValue, valueSpec);
- this.configValue = configValue;
- this.currentValue = configValue;
- this.valueSpec = valueSpec;
- this.fullPath = fullPath;
- this.spec = spec;
-
- // We will override the normal title functionality since we want it to be unformatted.
- this.title = new TextComponent(getPath());
- }
-
- @Override
- public Component getTitle()
- {
- return this.title;
- }
-
- @Override
- public boolean mayResetValue()
- {
- return !listSafeEquals(currentValue, getDefaultValue());
- }
-
- @Override
- public boolean mayDiscardChanges()
- {
- return listSafeEquals(configValue, currentValue);
- }
-
- private static <T> boolean listSafeEquals(T o1, T o2)
- {
- // Attempts to solve an issue where types of lists won't match when one is read from file
- // (due to enum being converted to string, long to int)
- if (o1 instanceof List<?> list1 && o2 instanceof List<?> list2)
- {
- final Stream<String> stream1 = list1.stream().map(o -> o instanceof Enum<?> e ? e.name() : o.toString());
- final Stream<String> stream2 = list2.stream().map(o -> o instanceof Enum<?> e ? e.name() : o.toString());
- return Iterators.elementsEqual(stream1.iterator(), stream2.iterator());
- }
- return Objects.equal(o1, o2);
- }
-
- @Override
- public void resetCurrentValue()
- {
- currentValue = getDefaultValue();
- }
-
- @Override
- public void discardCurrentValue()
- {
- currentValue = configValue;
- }
-
- @Override
- public void saveConfigValue()
- {
- try
- {
- Field childConfigField = spec.getClass().getDeclaredField("childConfig");
- Config childConfig = UnsafeHacks.getField(childConfigField, spec);
- childConfig.set(fullPath, currentValue);
- }
- catch (Exception e) { }
- configValue = currentValue;
- }
-
- @SuppressWarnings("unchecked")
- public T getDefaultValue()
- {
- return (T) valueSpec.getDefault();
- }
-
- public T getCurrentValue()
- {
- return currentValue;
- }
-
- public void setCurrentValue(T newValue)
- {
- currentValue = newValue;
- }
-
- @Override
- public List<String> getFullPath()
- {
- return fullPath;
- }
- }
-} \ No newline at end of file
+// package com.anthonyhilyard.iceberg.util;
+
+// import java.lang.invoke.MethodHandle;
+// import java.lang.invoke.MethodHandles;
+// import java.lang.invoke.MethodType;
+// import java.lang.reflect.Field;
+// import java.util.List;
+// import java.util.Map;
+// import java.util.function.Supplier;
+// import java.util.stream.Stream;
+
+// import com.anthonyhilyard.iceberg.Loader;
+// import com.electronwill.nightconfig.core.CommentedConfig;
+// import com.electronwill.nightconfig.core.Config;
+// import com.electronwill.nightconfig.core.UnmodifiableConfig;
+// import com.google.common.collect.Maps;
+// import com.google.common.base.Objects;
+// import com.google.common.collect.Iterators;
+
+// import org.apache.commons.lang3.exception.ExceptionUtils;
+
+// import fuzs.configmenusforge.client.gui.data.EntryData;
+// import fuzs.configmenusforge.client.gui.data.IEntryData;
+// import net.minecraft.network.chat.Component;
+// import net.minecraftforge.common.ForgeConfigSpec;
+// import net.minecraftforge.fml.unsafe.UnsafeHacks;
+
+// public class ConfigMenusForgeHelper
+// {
+// private final static Map<Class<?>, List<MethodHandle>> configSpecMethodHandles = Maps.newHashMap();
+// private final static Map<Class<?>, Boolean> cachedConfigSpecClasses = Maps.newHashMap();
+// private final static MethodType getValuesMethodType = MethodType.methodType(UnmodifiableConfig.class);
+// private final static MethodType isLoadedMethodType = MethodType.methodType(boolean.class);
+// private final static MethodType saveMethodType = MethodType.methodType(void.class);
+
+// private static Object callMethod(UnmodifiableConfig spec, int methodIndex)
+// {
+// Class<?> specClass = spec.getClass();
+// if (!cachedConfigSpecClasses.containsKey(specClass))
+// {
+// cacheClass(specClass);
+// }
+
+// if (configSpecMethodHandles.containsKey(specClass))
+// {
+// try
+// {
+// return configSpecMethodHandles.get(specClass).get(methodIndex).invoke(spec);
+// }
+// catch (Throwable e)
+// {
+// Loader.LOGGER.warn(ExceptionUtils.getStackTrace(e));
+// }
+// }
+// return null;
+// }
+
+// public static UnmodifiableConfig getValues(UnmodifiableConfig spec)
+// {
+// return (UnmodifiableConfig) callMethod(spec, 0);
+// }
+
+// public static boolean isLoaded(UnmodifiableConfig spec)
+// {
+// return (Boolean) callMethod(spec, 1);
+// }
+
+// public static void save(UnmodifiableConfig spec)
+// {
+// callMethod(spec, 2);
+// }
+
+// public static Boolean cachedValidity(Class<?> specClass)
+// {
+// return cachedConfigSpecClasses.getOrDefault(specClass, null);
+// }
+
+// public static void cacheClass(Class<?> specClass)
+// {
+// MethodHandle getValuesMethod = null;
+// MethodHandle isLoadedMethod = null;
+// MethodHandle saveMethod = null;
+// try
+// {
+// getValuesMethod = MethodHandles.lookup().findVirtual(specClass, "getValues", getValuesMethodType);
+// isLoadedMethod = MethodHandles.lookup().findVirtual(specClass, "isLoaded", isLoadedMethodType);
+// saveMethod = MethodHandles.lookup().findVirtual(specClass, "save", saveMethodType);
+// }
+// catch (Throwable e)
+// {
+// Loader.LOGGER.warn(ExceptionUtils.getStackTrace(e));
+// }
+
+// // If we found valid getValues, isLoaded and save methods, add them to the cache.
+// if (getValuesMethod != null && isLoadedMethod != null && saveMethod != null)
+// {
+// cachedConfigSpecClasses.put(specClass, true);
+// configSpecMethodHandles.put(specClass, List.of(getValuesMethod, isLoadedMethod, saveMethod));
+// }
+// else
+// {
+// cachedConfigSpecClasses.put(specClass, false);
+// }
+// }
+
+// /**
+// * Changed spec from a ForgeConfigSpec to an UnmodifiableConfig.
+// */
+// public static void makeValueToDataMap(UnmodifiableConfig spec, UnmodifiableConfig values, CommentedConfig comments, Map<Object, IEntryData> allData, String basePath)
+// {
+// for (String path : values.valueMap().keySet())
+// {
+// String currentPath = basePath.isEmpty() ? path : basePath + "." + path;
+// Object value = values.valueMap().get(path);
+// if (value instanceof UnmodifiableConfig category)
+// {
+// final EntryData.CategoryEntryData data = new EntryData.CategoryEntryData(path, category, comments.getComment(path));
+// allData.put(category, data);
+// makeValueToDataMap(spec, category, (CommentedConfig) comments.valueMap().get(path), allData, currentPath);
+// }
+// else if (value instanceof ForgeConfigSpec.ConfigValue<?> configValue && configValue.get() instanceof UnmodifiableConfig category)
+// {
+// final EntryData.CategoryEntryData data = new DynamicCategoryEntryData(path, category, comments.getComment(path));
+// allData.put(category, data);
+// makeValueToDataMap(spec, category, (CommentedConfig) comments.valueMap().get(path), allData, currentPath);
+// }
+// else if (value instanceof ForgeConfigSpec.ConfigValue<?> configValue)
+// {
+// final EntryData.ConfigEntryData<?> data = new EntryData.ConfigEntryData<>(path, configValue, spec.getRaw(configValue.getPath()));
+// allData.put(configValue, data);
+// }
+// // Allow non-configvalue values if the parent is a dynamic subconfig.
+// else if (!(value instanceof ForgeConfigSpec.ConfigValue<?>) && allData.containsKey(values) && allData.get(values) instanceof DynamicCategoryEntryData)
+// {
+// final EntryData.ConfigEntryData<?> data = new DynamicConfigEntryData<>(List.of(currentPath.split("\\.")), value, spec.getRaw(currentPath), spec);
+// allData.put(value, data);
+// }
+// }
+// }
+
+// public static class DynamicCategoryEntryData extends EntryData.CategoryEntryData
+// {
+// public DynamicCategoryEntryData(String path, UnmodifiableConfig config, String comment) {
+// super(path, config, comment);
+// }
+// }
+
+// public static class DynamicConfigEntryData<T> extends EntryData.ConfigEntryData<T>
+// {
+// private final ForgeConfigSpec.ValueSpec valueSpec;
+// private T currentValue;
+// private T configValue;
+// private final List<String> fullPath;
+// private final UnmodifiableConfig spec;
+
+// private final static ForgeConfigSpec.ConfigValue<?> dummyConfigValue;
+
+// private Component title;
+
+// static
+// {
+// dummyConfigValue = UnsafeHacks.newInstance(ForgeConfigSpec.ConfigValue.class);
+// try
+// {
+// Field specField = ForgeConfigSpec.ConfigValue.class.getDeclaredField("spec");
+// UnsafeHacks.setField(specField, dummyConfigValue, UnsafeHacks.newInstance(ForgeConfigSpec.class));
+// Field defaultSupplierField = ForgeConfigSpec.ConfigValue.class.getDeclaredField("defaultSupplier");
+// UnsafeHacks.setField(defaultSupplierField, dummyConfigValue, (Supplier<?>)(() -> null));
+// }
+// catch (Exception e) { }
+// }
+
+// @SuppressWarnings("unchecked")
+// public DynamicConfigEntryData(List<String> fullPath, T configValue, ForgeConfigSpec.ValueSpec valueSpec, UnmodifiableConfig spec)
+// {
+// super(fullPath.get(fullPath.size() - 1), (ForgeConfigSpec.ConfigValue<T>) dummyConfigValue, valueSpec);
+// this.configValue = configValue;
+// this.currentValue = configValue;
+// this.valueSpec = valueSpec;
+// this.fullPath = fullPath;
+// this.spec = spec;
+
+// // We will override the normal title functionality since we want it to be unformatted.
+// this.title = Component.literal(getPath());
+// }
+
+// @Override
+// public Component getTitle()
+// {
+// return this.title;
+// }
+
+// @Override
+// public boolean mayResetValue()
+// {
+// return !listSafeEquals(currentValue, getDefaultValue());
+// }
+
+// @Override
+// public boolean mayDiscardChanges()
+// {
+// return listSafeEquals(configValue, currentValue);
+// }
+
+// private static <T> boolean listSafeEquals(T o1, T o2)
+// {
+// // Attempts to solve an issue where types of lists won't match when one is read from file
+// // (due to enum being converted to string, long to int)
+// if (o1 instanceof List<?> list1 && o2 instanceof List<?> list2)
+// {
+// final Stream<String> stream1 = list1.stream().map(o -> o instanceof Enum<?> e ? e.name() : o.toString());
+// final Stream<String> stream2 = list2.stream().map(o -> o instanceof Enum<?> e ? e.name() : o.toString());
+// return Iterators.elementsEqual(stream1.iterator(), stream2.iterator());
+// }
+// return Objects.equal(o1, o2);
+// }
+
+// @Override
+// public void resetCurrentValue()
+// {
+// currentValue = getDefaultValue();
+// }
+
+// @Override
+// public void discardCurrentValue()
+// {
+// currentValue = configValue;
+// }
+
+// @Override
+// public void saveConfigValue()
+// {
+// try
+// {
+// Field childConfigField = spec.getClass().getDeclaredField("childConfig");
+// Config childConfig = UnsafeHacks.getField(childConfigField, spec);
+// childConfig.set(fullPath, currentValue);
+// }
+// catch (Exception e) { }
+// configValue = currentValue;
+// }
+
+// @SuppressWarnings("unchecked")
+// public T getDefaultValue()
+// {
+// return (T) valueSpec.getDefault();
+// }
+
+// public T getCurrentValue()
+// {
+// return currentValue;
+// }
+
+// public void setCurrentValue(T newValue)
+// {
+// currentValue = newValue;
+// }
+
+// @Override
+// public List<String> getFullPath()
+// {
+// return fullPath;
+// }
+// }
+// } \ No newline at end of file
diff --git a/src/main/java/com/anthonyhilyard/iceberg/util/DynamicResourcePack.java b/src/main/java/com/anthonyhilyard/iceberg/util/DynamicResourcePack.java
index 127fc60..a59449a 100644
--- a/src/main/java/com/anthonyhilyard/iceberg/util/DynamicResourcePack.java
+++ b/src/main/java/com/anthonyhilyard/iceberg/util/DynamicResourcePack.java
@@ -99,13 +99,13 @@ public class DynamicResourcePack implements PackResources
}
@Override
- public Collection<ResourceLocation> getResources(PackType type, String namespace, String path, int maxDepth, Predicate<String> filter)
+ public Collection<ResourceLocation> getResources(PackType type, String namespace, String path, Predicate<ResourceLocation> filter)
{
return dynamicResourceMap.entrySet().stream()
.filter(entry -> entry.getKey().namespace.contentEquals(namespace))
.filter(entry -> entry.getKey().path.startsWith(path))
.filter(entry -> entry.getKey().type.contentEquals(type.getDirectory()))
- .filter(entry -> filter.test(entry.getKey().path))
+ .filter(entry -> filter.test(new ResourceLocation(entry.getKey().namespace, entry.getKey().path)))
.map(entry -> new ResourceLocation(namespace, entry.getKey().path))
.collect(Collectors.toList());
}
diff --git a/src/main/java/com/anthonyhilyard/iceberg/util/Selectors.java b/src/main/java/com/anthonyhilyard/iceberg/util/Selectors.java
index 7c12330..cfbc203 100644
--- a/src/main/java/com/anthonyhilyard/iceberg/util/Selectors.java
+++ b/src/main/java/com/anthonyhilyard/iceberg/util/Selectors.java
@@ -20,6 +20,7 @@ import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.Rarity;
import net.minecraft.world.item.TooltipFlag;
+import net.minecraftforge.registries.ForgeRegistries;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
@@ -150,7 +151,7 @@ public class Selectors
@SuppressWarnings("deprecation")
public static boolean itemMatches(ItemStack item, String selector)
{
- String itemResourceLocation = item.getItem().getRegistryName().toString();
+ String itemResourceLocation = ForgeRegistries.ITEMS.getKey(item.getItem()).toString();
// Item ID
if (selector.equals(itemResourceLocation) || selector.equals(itemResourceLocation.replace("minecraft:", "")))
{
diff --git a/src/main/java/com/anthonyhilyard/iceberg/util/StringRecomposer.java b/src/main/java/com/anthonyhilyard/iceberg/util/StringRecomposer.java
index 4ad448d..bf87e67 100644
--- a/src/main/java/com/anthonyhilyard/iceberg/util/StringRecomposer.java
+++ b/src/main/java/com/anthonyhilyard/iceberg/util/StringRecomposer.java
@@ -8,7 +8,7 @@ import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent
import net.minecraft.network.chat.FormattedText;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.Style;
-import net.minecraft.network.chat.TextComponent;
+import net.minecraft.network.chat.Component;
import net.minecraft.util.FormattedCharSink;
public class StringRecomposer
@@ -31,7 +31,7 @@ public class StringRecomposer
private static class RecomposerSink implements FormattedCharSink
{
private StringBuilder builder = new StringBuilder();
- private MutableComponent text = new TextComponent("").withStyle(Style.EMPTY);
+ private MutableComponent text = Component.literal("").withStyle(Style.EMPTY);
@Override
public boolean accept(int index, Style style, int charCode)
@@ -40,7 +40,7 @@ public class StringRecomposer
if (!style.equals(text.getStyle()))
{
- text.append(new TextComponent(builder.toString()).withStyle(style));
+ text.append(Component.literal(builder.toString()).withStyle(style));
builder.setLength(0);
}
return true;
@@ -48,7 +48,7 @@ public class StringRecomposer
public FormattedText getFormattedText()
{
- text.append(new TextComponent(builder.toString()).withStyle(text.getStyle()));
+ text.append(Component.literal(builder.toString()).withStyle(text.getStyle()));
return text;
}
}