diff --git a/src/main/java/com/github/shap_po/shappoli/integration/walkers/WalkersIntegration.java b/src/main/java/com/github/shap_po/shappoli/integration/walkers/WalkersIntegration.java index 201b96c..235808d 100644 --- a/src/main/java/com/github/shap_po/shappoli/integration/walkers/WalkersIntegration.java +++ b/src/main/java/com/github/shap_po/shappoli/integration/walkers/WalkersIntegration.java @@ -1,5 +1,6 @@ package com.github.shap_po.shappoli.integration.walkers; +import com.github.shap_po.shappoli.integration.walkers.events.ShapeEventHandler; import com.github.shap_po.shappoli.integration.walkers.power.factory.PowerFactories; import com.github.shap_po.shappoli.integration.walkers.power.factory.ability.ShapeAbilities; import com.github.shap_po.shappoli.integration.walkers.power.factory.action.BiEntityActions; @@ -15,6 +16,7 @@ public static void register() { EntityConditions.register(); ShapeAbilities.register(); + ShapeEventHandler.register(); ShappoliWalkersShapeAbilityTypeRegistry.register(); } } diff --git a/src/main/java/com/github/shap_po/shappoli/integration/walkers/events/ShapeEventHandler.java b/src/main/java/com/github/shap_po/shappoli/integration/walkers/events/ShapeEventHandler.java new file mode 100644 index 0000000..198270b --- /dev/null +++ b/src/main/java/com/github/shap_po/shappoli/integration/walkers/events/ShapeEventHandler.java @@ -0,0 +1,23 @@ +package com.github.shap_po.shappoli.integration.walkers.events; + +import com.github.shap_po.shappoli.integration.walkers.power.ActionOnShapeChangePower; +import com.github.shap_po.shappoli.integration.walkers.power.PreventShapeChangePower; +import io.github.apace100.apoli.component.PowerHolderComponent; +import net.minecraft.entity.LivingEntity; +import net.minecraft.util.ActionResult; +import tocraft.walkers.api.events.ShapeEvents; + +public class ShapeEventHandler { + public static void register() { + ShapeEvents.SWAP_SHAPE.register((player, to) -> { + LivingEntity shape = to == null ? player : to; + if (PowerHolderComponent.hasPower(player, PreventShapeChangePower.class, p -> p.doesApply(shape))) { + return ActionResult.FAIL; + } + + PowerHolderComponent.withPowers(player, ActionOnShapeChangePower.class, p -> p.doesApply(shape), p -> p.apply(shape)); + + return ActionResult.PASS; + }); + } +} diff --git a/src/main/java/com/github/shap_po/shappoli/mixin/integration/walkers/PlayerShapeMixin.java b/src/main/java/com/github/shap_po/shappoli/mixin/integration/walkers/PlayerShapeMixin.java deleted file mode 100644 index 874b30f..0000000 --- a/src/main/java/com/github/shap_po/shappoli/mixin/integration/walkers/PlayerShapeMixin.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.github.shap_po.shappoli.mixin.integration.walkers; - -import com.github.shap_po.shappoli.integration.walkers.power.ActionOnShapeChangePower; -import com.github.shap_po.shappoli.integration.walkers.power.PreventShapeChangePower; -import io.github.apace100.apoli.component.PowerHolderComponent; -import net.minecraft.entity.LivingEntity; -import net.minecraft.server.network.ServerPlayerEntity; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import tocraft.walkers.api.PlayerShape; - -@Mixin(PlayerShape.class) -public class PlayerShapeMixin { - @Inject(method = "updateShapes", at = @At(value = "HEAD"), cancellable = true) - private static void shappoli$preventShapeChange(ServerPlayerEntity player, LivingEntity entity, CallbackInfoReturnable cir) { - LivingEntity shape = entity == null ? player : entity; - if (PowerHolderComponent.hasPower(player, PreventShapeChangePower.class, p -> p.doesApply(shape))) { - cir.setReturnValue(false); - } - } - - @Inject(method = "updateShapes", at = @At(value = "RETURN")) - private static void shappoli$onShapeChange(ServerPlayerEntity player, LivingEntity entity, CallbackInfoReturnable cir) { - LivingEntity shape = entity == null ? player : entity; - if (cir.getReturnValue()) { - PowerHolderComponent.withPowers(player, ActionOnShapeChangePower.class, p -> p.doesApply(shape), p -> p.apply(shape)); - } - } -} diff --git a/src/main/resources/shappoli.mixins.json b/src/main/resources/shappoli.mixins.json index f6ac39d..2663ec1 100644 --- a/src/main/resources/shappoli.mixins.json +++ b/src/main/resources/shappoli.mixins.json @@ -16,7 +16,6 @@ "integration.trinkets.TrinketInventoryMixin", "integration.trinkets.TrinketSlotMixin", "integration.walkers.PlayerAbilitiesMixin", - "integration.walkers.PlayerShapeMixin", "integration.walkers.ServerNetworkingMixin" ], "client": [