diff options
author | Anthony Hilyard <anthony.hilyard@gmail.com> | 2022-05-19 15:53:47 -0700 |
---|---|---|
committer | Anthony Hilyard <anthony.hilyard@gmail.com> | 2022-05-19 15:53:47 -0700 |
commit | fd1948939a5978832ce5da5bb2dbbd0df49a2ac3 (patch) | |
tree | 7856ada82a27bb0cf136fbbd9296aa351a85f22a /src/main/java | |
parent | 312cf6b1d2990d7632807dfa5ef93b8dd2cbb865 (diff) | |
download | Iceberg-fd1948939a5978832ce5da5bb2dbbd0df49a2ac3.tar.gz Iceberg-fd1948939a5978832ce5da5bb2dbbd0df49a2ac3.tar.bz2 Iceberg-fd1948939a5978832ce5da5bb2dbbd0df49a2ac3.zip |
Bumped required forge version to 40.1, fixed IcebergConfig crash.
Diffstat (limited to 'src/main/java')
4 files changed, 42 insertions, 134 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 +} |