diff options
Diffstat (limited to 'src')
6 files changed, 45 insertions, 138 deletions
diff --git a/src/main/java/com/anthonyhilyard/iceberg/config/IcebergConfigSpec.java b/src/main/java/com/anthonyhilyard/iceberg/config/IcebergConfigSpec.java index 01a5e40..89b81b2 100644 --- a/src/main/java/com/anthonyhilyard/iceberg/config/IcebergConfigSpec.java +++ b/src/main/java/com/anthonyhilyard/iceberg/config/IcebergConfigSpec.java @@ -3,7 +3,6 @@ package com.anthonyhilyard.iceberg.config; import java.io.File; import java.lang.reflect.Field; import java.util.Collections; -import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; import java.util.List; @@ -23,6 +22,7 @@ import net.minecraftforge.fml.Logging; import net.minecraftforge.fml.config.IConfigSpec; import net.minecraftforge.fml.unsafe.UnsafeHacks; +import org.apache.commons.lang3.exception.ExceptionUtils; import org.apache.commons.lang3.tuple.Pair; import org.apache.logging.log4j.LogManager; @@ -48,18 +48,20 @@ import com.google.common.collect.Lists; */ public class IcebergConfigSpec extends UnmodifiableConfigWrapper<UnmodifiableConfig> implements IConfigSpec<IcebergConfigSpec> { - private Map<List<String>, String> levelComments = new HashMap<>(); + private Map<List<String>, String> levelComments; + private Map<List<String>, String> levelTranslationKeys; private UnmodifiableConfig values; private Config childConfig; private boolean isCorrecting = false; - private IcebergConfigSpec(UnmodifiableConfig storage, UnmodifiableConfig values, Map<List<String>, String> levelComments) + private IcebergConfigSpec(UnmodifiableConfig storage, UnmodifiableConfig values, Map<List<String>, String> levelComments, Map<List<String>, String> levelTranslationKeys) { super(storage); this.values = values; this.levelComments = levelComments; + this.levelTranslationKeys = levelTranslationKeys; // Update the filewatcher's default instance to have a more sensible exception handler. try @@ -72,6 +74,16 @@ public class IcebergConfigSpec extends UnmodifiableConfigWrapper<UnmodifiableCon catch (Exception e) {} } + public String getLevelComment(List<String> path) + { + return levelComments.get(path); + } + + public String getLevelTranslationKey(List<String> path) + { + return levelTranslationKeys.get(path); + } + public void setConfig(CommentedConfig config) { this.childConfig = config; @@ -391,7 +403,10 @@ public class IcebergConfigSpec extends UnmodifiableConfigWrapper<UnmodifiableCon UnsafeHacks.setField(supplierField, result, defaultSupplier); UnsafeHacks.setField(validatorField, result, validator); } - catch (Exception e) { } + catch (Exception e) { + Loader.LOGGER.warn("Failed to instantiate ValueSpec!"); + Loader.LOGGER.warn(ExceptionUtils.getStackTrace(e)); + } return result; } @@ -476,26 +491,34 @@ public class IcebergConfigSpec extends UnmodifiableConfigWrapper<UnmodifiableCon Field valuesField = ForgeConfigSpec.Builder.class.getDeclaredField("values"); Field storageField = ForgeConfigSpec.Builder.class.getDeclaredField("storage"); Field levelCommentsField = ForgeConfigSpec.Builder.class.getDeclaredField("levelComments"); + Field levelTranslationKeysField = ForgeConfigSpec.Builder.class.getDeclaredField("levelTranslationKeys"); List<ConfigValue<?>> values = UnsafeHacks.<List<ConfigValue<?>>>getField(valuesField, this); Config storage = UnsafeHacks.<Config>getField(storageField, this); Map<List<String>, String> levelComments = UnsafeHacks.<Map<List<String>, String>>getField(levelCommentsField, this); + Map<List<String>, String> levelTranslationKeys = UnsafeHacks.<Map<List<String>, String>>getField(levelTranslationKeysField, this); Config valueCfg = Config.of(Config.getDefaultMapCreator(true, true), InMemoryFormat.withSupport(ConfigValue.class::isAssignableFrom)); values.forEach(v -> valueCfg.set(v.getPath(), v)); - final IcebergConfigSpec ret = new IcebergConfigSpec(storage, valueCfg, levelComments); + final IcebergConfigSpec ret = new IcebergConfigSpec(storage, valueCfg, levelComments, levelTranslationKeys); values.forEach(v -> { try { Field specField = ConfigValue.class.getDeclaredField("spec"); UnsafeHacks.setField(specField, v, ret); } - catch (Exception e) { } + catch (Exception e) { + Loader.LOGGER.warn("Failed to create spec field {}!", v.toString()); + Loader.LOGGER.warn(ExceptionUtils.getStackTrace(e)); + } }); result = ret; } - catch (Exception e) { } + catch (Exception e) { + Loader.LOGGER.warn("Failed to build IcebergConfigSpec!"); + Loader.LOGGER.warn(ExceptionUtils.getStackTrace(e)); + } return result; } diff --git a/src/main/java/com/anthonyhilyard/iceberg/events/EntityFluidEvent.java b/src/main/java/com/anthonyhilyard/iceberg/events/EntityFluidEvent.java deleted file mode 100644 index d2abcb2..0000000 --- a/src/main/java/com/anthonyhilyard/iceberg/events/EntityFluidEvent.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.anthonyhilyard.iceberg.events; - -import net.minecraft.world.entity.Entity; -import net.minecraft.world.level.material.Fluid; -import net.minecraftforge.event.entity.EntityEvent; - -public class EntityFluidEvent extends EntityEvent -{ - private final Fluid fluid; - - private EntityFluidEvent(Entity entity, Fluid fluid) - { - super(entity); - this.fluid = fluid; - } - - public Fluid getFluid() - { - return fluid; - } - - /** - * This event is fired when an entity enters a fluid to at least eye-level. - * If this is a player, they will see the "submerged in fluid" effect at this point. - * <br> - * This event is not {@link net.minecraftforge.eventbus.api.Cancelable}.<br> - * <br> - * This event does not have a result. {@link HasResult}<br> - * <br> - * This event is fired on the {@link MinecraftForge#EVENT_BUS}. - */ - public static class Entered extends EntityFluidEvent - { - public Entered(Entity entity, Fluid fluid) - { - super(entity, fluid); - } - } - - /** - * This event is fired when an entity was previously submerged in a fluid to at least eye-level and no longer are. - * If this is a player, they will no longer see the "submerged in fluid" effect at this point. - * <br> - * This event is not {@link net.minecraftforge.eventbus.api.Cancelable}.<br> - * <br> - * This event does not have a result. {@link HasResult}<br> - * <br> - * This event is fired on the {@link MinecraftForge#EVENT_BUS}. - */ - public static class Exited extends EntityFluidEvent - { - public Exited(Entity entity, Fluid fluid) - { - super(entity, fluid); - } - } -} diff --git a/src/main/java/com/anthonyhilyard/iceberg/mixin/EntityMixin.java b/src/main/java/com/anthonyhilyard/iceberg/mixin/EntityMixin.java deleted file mode 100644 index 8c03e8b..0000000 --- a/src/main/java/com/anthonyhilyard/iceberg/mixin/EntityMixin.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.anthonyhilyard.iceberg.mixin; - -import java.util.Objects; - -import com.anthonyhilyard.iceberg.events.EntityFluidEvent; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.At.Shift; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import net.minecraft.world.entity.Entity; -import net.minecraft.world.level.material.Fluid; -import net.minecraft.tags.Tag; -import net.minecraftforge.common.MinecraftForge; - -@Mixin(Entity.class) -public class EntityMixin -{ - private Fluid previousFluidOnEyes = null; - - @Shadow - protected Tag<Fluid> fluidOnEyes; - - @Inject(method = "updateFluidOnEyes", at = @At(value = "RETURN")) - public void onUpdateFluidOnEyes(CallbackInfo callbackInfo) - { - if (fluidOnEyes != null && fluidOnEyes.getValues().size() > 0) - { - previousFluidOnEyes = fluidOnEyes.getValues().get(0); - } - else if (previousFluidOnEyes != null) - { - // We were submerged in a fluid that we no longer are. - if (previousFluidOnEyes != null) - { - MinecraftForge.EVENT_BUS.post(new EntityFluidEvent.Exited((Entity)(Object)this, previousFluidOnEyes)); - } - previousFluidOnEyes = null; - } - } - - @Inject(method = "updateFluidOnEyes", - at = @At(value = "FIELD", target = "Lnet/minecraft/world/entity/Entity;fluidOnEyes:Lnet/minecraft/tags/Tag;", ordinal = 1, shift = Shift.AFTER)) - public void onUpdateFluidOnEyeAssign(CallbackInfo callbackInfo) - { - Fluid currentFluid = null; - if (fluidOnEyes != null && fluidOnEyes.getValues().size() > 0) - { - currentFluid = fluidOnEyes.getValues().get(0); - } - - if (!Objects.equals(previousFluidOnEyes, currentFluid)) - { - // We are now submerged in a fluid that doesn't match the previous one. - if (currentFluid != null) - { - MinecraftForge.EVENT_BUS.post(new EntityFluidEvent.Entered((Entity)(Object)this, currentFluid)); - } - } - } -} diff --git a/src/main/java/com/anthonyhilyard/iceberg/util/Selectors.java b/src/main/java/com/anthonyhilyard/iceberg/util/Selectors.java index 5099644..7c12330 100644 --- a/src/main/java/com/anthonyhilyard/iceberg/util/Selectors.java +++ b/src/main/java/com/anthonyhilyard/iceberg/util/Selectors.java @@ -1,15 +1,15 @@ package com.anthonyhilyard.iceberg.util; -import net.minecraft.world.item.ItemStack; - import java.util.Arrays; import java.util.HashMap; import java.util.Map; +import java.util.Optional; import java.util.function.BiPredicate; import java.util.List; import net.minecraft.client.Minecraft; +import net.minecraft.core.Registry; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NumericTag; import net.minecraft.nbt.Tag; @@ -17,9 +17,11 @@ import net.minecraft.nbt.ListTag; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.TextColor; import net.minecraft.resources.ResourceLocation; -import net.minecraft.tags.ItemTags; +import net.minecraft.tags.TagKey; import net.minecraft.world.item.Rarity; import net.minecraft.world.item.TooltipFlag; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; public class Selectors { @@ -31,7 +33,9 @@ public class Selectors }}; private static Map<String, BiPredicate<Tag, String>> nbtComparators = new HashMap<String, BiPredicate<Tag, String>>() {{ - put("=", (tag, value) -> tag.getAsString().contentEquals(value)); + put("=", (tag, value) -> { + return tag.getAsString().contentEquals(value); + }); put("!=", (tag, value) -> !tag.getAsString().contentEquals(value)); @@ -143,6 +147,7 @@ public class Selectors * @param selector A selector string to check against. * @return True if the item matches, false otherwise. */ + @SuppressWarnings("deprecation") public static boolean itemMatches(ItemStack item, String selector) { String itemResourceLocation = item.getItem().getRegistryName().toString(); @@ -179,7 +184,8 @@ public class Selectors // Item tag else if (selector.startsWith("$")) { - if (ItemTags.getAllTags().getTagOrEmpty(new ResourceLocation(selector.substring(1))).getValues().contains(item.getItem())) + Optional<TagKey<Item>> matchingTag = Registry.ITEM.getTagNames().filter(tagKey -> tagKey.location().equals(new ResourceLocation(selector.substring(1)))).findFirst(); + if (matchingTag.isPresent() && item.is(matchingTag.get())) { return true; } @@ -298,4 +304,4 @@ public class Selectors } return false; } -}
\ No newline at end of file +} diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index 8616362..d8a6b38 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -1,5 +1,5 @@ modLoader="javafml" -loaderVersion="[39,)" +loaderVersion="[40,)" license="CC BY-NC-ND 4.0" [[mods]] @@ -15,13 +15,13 @@ description="A library containing events, helpers, and utilities to make modding [[dependencies.iceberg]] modId="forge" mandatory=true - versionRange="[39,)" + versionRange="[40.1,)" ordering="NONE" side="BOTH" [[dependencies.iceberg]] modId="minecraft" mandatory=true - versionRange="[1.18.1,1.19)" + versionRange="[1.18.2,1.19)" ordering="NONE" side="BOTH"
\ No newline at end of file diff --git a/src/main/resources/iceberg.mixins.json b/src/main/resources/iceberg.mixins.json index d722775..1faddec 100644 --- a/src/main/resources/iceberg.mixins.json +++ b/src/main/resources/iceberg.mixins.json @@ -5,7 +5,6 @@ "refmap": "iceberg.refmap.json", "plugin": "com.anthonyhilyard.iceberg.mixin.ForgeConfigMenusPlugin", "mixins": [ - "EntityMixin", "PlayerAdvancementsMixin" ], "client": [ |