diff options
-rw-r--r-- | .vs/Iceberg-Fabric-1.18/v17/.suo | bin | 0 -> 14336 bytes | |||
-rw-r--r-- | .vs/VSWorkspaceState.json | 6 | ||||
-rw-r--r-- | .vs/slnx.sqlite | bin | 0 -> 90112 bytes | |||
-rw-r--r-- | src/main/java/com/anthonyhilyard/iceberg/IcebergClient.java | 2 | ||||
-rw-r--r-- | src/main/java/com/anthonyhilyard/iceberg/events/CriterionCallback.java | 4 | ||||
-rw-r--r-- | src/main/java/com/anthonyhilyard/iceberg/events/EntityFluidEvents.java | 44 | ||||
-rw-r--r-- | src/main/java/com/anthonyhilyard/iceberg/events/ToggleableEvent.java | 69 | ||||
-rw-r--r-- | src/main/java/com/anthonyhilyard/iceberg/mixin/EntityMixin.java | 63 | ||||
-rw-r--r-- | src/main/java/com/anthonyhilyard/iceberg/util/Selectors.java | 14 | ||||
-rw-r--r-- | src/main/resources/iceberg.mixins.json | 1 |
10 files changed, 84 insertions, 119 deletions
diff --git a/.vs/Iceberg-Fabric-1.18/v17/.suo b/.vs/Iceberg-Fabric-1.18/v17/.suo Binary files differnew file mode 100644 index 0000000..8effe01 --- /dev/null +++ b/.vs/Iceberg-Fabric-1.18/v17/.suo diff --git a/.vs/VSWorkspaceState.json b/.vs/VSWorkspaceState.json new file mode 100644 index 0000000..6b61141 --- /dev/null +++ b/.vs/VSWorkspaceState.json @@ -0,0 +1,6 @@ +{ + "ExpandedNodes": [ + "" + ], + "PreviewInSolutionExplorer": false +}
\ No newline at end of file diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite Binary files differnew file mode 100644 index 0000000..87a95ba --- /dev/null +++ b/.vs/slnx.sqlite diff --git a/src/main/java/com/anthonyhilyard/iceberg/IcebergClient.java b/src/main/java/com/anthonyhilyard/iceberg/IcebergClient.java index 9074aa3..8218f71 100644 --- a/src/main/java/com/anthonyhilyard/iceberg/IcebergClient.java +++ b/src/main/java/com/anthonyhilyard/iceberg/IcebergClient.java @@ -9,8 +9,6 @@ public class IcebergClient implements ClientModInitializer { // Event testing. // CriterionCallback.EVENT.register((player, advancement, criterion) -> { Loader.LOGGER.info("CriterionCallback: {}, {}, {}", player.getName().getString(), advancement.getId().toString(), criterion); }); - // EntityFluidEvents.ENTERED.register((entity, fluid) -> { Loader.LOGGER.info("EntityFluidEvents.ENTERED: {}, {}", entity.getName().getString(), Registry.FLUID.getKey(fluid).toString()); }); - // EntityFluidEvents.EXITED.register((entity, fluid) -> { Loader.LOGGER.info("EntityFluidEvents.EXITED: {}, {}", entity.getName().getString(), Registry.FLUID.getKey(fluid).toString()); }); // NewItemPickupCallback.EVENT.register((uuid, itemStack) -> { Loader.LOGGER.info("NewItemPickupCallback: {}, {}", uuid.toString(), itemStack.getDisplayName().getString()); }); // RenderTickEvents.START.register((timer) -> { Loader.LOGGER.info("RenderTickEvents.START: {}", timer); }); // RenderTooltipEvents.PRE.register((stack, components, poseStack, x, y, screenWidth, screenHeight, maxWidth, font, comparison) -> { diff --git a/src/main/java/com/anthonyhilyard/iceberg/events/CriterionCallback.java b/src/main/java/com/anthonyhilyard/iceberg/events/CriterionCallback.java index f46f082..0486304 100644 --- a/src/main/java/com/anthonyhilyard/iceberg/events/CriterionCallback.java +++ b/src/main/java/com/anthonyhilyard/iceberg/events/CriterionCallback.java @@ -1,7 +1,5 @@ package com.anthonyhilyard.iceberg.events; -import net.fabricmc.fabric.api.event.Event; -import net.fabricmc.fabric.api.event.EventFactory; import net.minecraft.advancements.Advancement; import net.minecraft.world.entity.player.Player; @@ -10,7 +8,7 @@ import net.minecraft.world.entity.player.Player; */ public interface CriterionCallback { - Event<CriterionCallback> EVENT = EventFactory.createArrayBacked(CriterionCallback.class, + ToggleableEvent<CriterionCallback> EVENT = ToggleableEvent.create(CriterionCallback.class, (listeners) -> (player, advancement, criterionKey) -> { for (CriterionCallback listener : listeners) { diff --git a/src/main/java/com/anthonyhilyard/iceberg/events/EntityFluidEvents.java b/src/main/java/com/anthonyhilyard/iceberg/events/EntityFluidEvents.java deleted file mode 100644 index 3ffea9a..0000000 --- a/src/main/java/com/anthonyhilyard/iceberg/events/EntityFluidEvents.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.anthonyhilyard.iceberg.events; - -import net.fabricmc.fabric.api.event.Event; -import net.fabricmc.fabric.api.event.EventFactory; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.level.material.Fluid; - - -public final class EntityFluidEvents -{ - public EntityFluidEvents() { } - - /** - * Called when an Entity enters a new fluid. - */ - public static final Event<EntityFluidEvents.Entered> ENTERED = EventFactory.createArrayBacked(EntityFluidEvents.Entered.class, callbacks -> (entity, fluid) -> { - for (EntityFluidEvents.Entered callback : callbacks) - { - callback.onEntered(entity, fluid); - } - }); - - /** - * Called when an Entity exits a fluid. - */ - public static final Event<EntityFluidEvents.Exited> EXITED = EventFactory.createArrayBacked(EntityFluidEvents.Exited.class, callbacks -> (entity, fluid) -> { - for (EntityFluidEvents.Exited callback : callbacks) - { - callback.onExited(entity, fluid); - } - }); - - @FunctionalInterface - public interface Entered - { - void onEntered(Entity entity, Fluid fluid); - } - - @FunctionalInterface - public interface Exited - { - void onExited(Entity entity, Fluid fluid); - } -}
\ No newline at end of file diff --git a/src/main/java/com/anthonyhilyard/iceberg/events/ToggleableEvent.java b/src/main/java/com/anthonyhilyard/iceberg/events/ToggleableEvent.java new file mode 100644 index 0000000..977587a --- /dev/null +++ b/src/main/java/com/anthonyhilyard/iceberg/events/ToggleableEvent.java @@ -0,0 +1,69 @@ +package com.anthonyhilyard.iceberg.events; + +import java.lang.reflect.Array; +import java.util.function.Function; + +import net.fabricmc.fabric.api.event.Event; +import net.fabricmc.fabric.api.event.EventFactory; + +public class ToggleableEvent<T> +{ + private T dummyInvoker; + private boolean disabled = false; + private Event<T> event; + + @SuppressWarnings("unchecked") + private ToggleableEvent(Class<? super T> type, Function<T[], T> invokerFactory) + { + event = EventFactory.createArrayBacked(type, invokerFactory); + this.dummyInvoker = invokerFactory.apply((T[]) Array.newInstance(type, 0)); + } + + public static <T> ToggleableEvent<T> create(Class<? super T> type, Function<T[], T> invokerFactory) + { + return new ToggleableEvent<>(type, invokerFactory); + } + + public void register(T listener) + { + event.register(listener); + } + + public T invoker() + { + if (!disabled) + { + return event.invoker(); + } + else + { + return dummyInvoker; + } + } + + public boolean disable() + { + if (disabled) + { + return false; + } + else + { + disabled = true; + return true; + } + } + + public boolean enable() + { + if (!disabled) + { + return false; + } + else + { + disabled = false; + return true; + } + } +} 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 5d02156..0000000 --- a/src/main/java/com/anthonyhilyard/iceberg/mixin/EntityMixin.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.anthonyhilyard.iceberg.mixin; - -import java.util.Objects; - -import com.anthonyhilyard.iceberg.events.EntityFluidEvents; - -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; - -@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) - { - EntityFluidEvents.EXITED.invoker().onExited((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) - { - EntityFluidEvents.ENTERED.invoker().onEntered((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 04e46da..87b4d92 100644 --- a/src/main/java/com/anthonyhilyard/iceberg/util/Selectors.java +++ b/src/main/java/com/anthonyhilyard/iceberg/util/Selectors.java @@ -1,15 +1,14 @@ package com.anthonyhilyard.iceberg.util; -import net.minecraft.client.Minecraft; -import net.minecraft.core.Registry; -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 +16,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 { @@ -179,7 +180,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; } diff --git a/src/main/resources/iceberg.mixins.json b/src/main/resources/iceberg.mixins.json index c94d7b8..ed51f10 100644 --- a/src/main/resources/iceberg.mixins.json +++ b/src/main/resources/iceberg.mixins.json @@ -3,7 +3,6 @@ "package": "com.anthonyhilyard.iceberg.mixin", "compatibilityLevel": "JAVA_17", "mixins": [ - "EntityMixin", "PlayerAdvancementsMixin" ], "client": [ |