From 2b89689c62dd1ca32a1ec59d08c622573d077fdc Mon Sep 17 00:00:00 2001 From: Pug <81167232+MerchantPug@users.noreply.github.com> Date: Tue, 5 Dec 2023 10:51:34 +1100 Subject: [PATCH] Apoli: Fix EdwinMindcraft/origins-architectury#391 --- .../apoli/mixin/LivingEntityMixin.java | 10 ++++++ .../apoli/mixin/PlayerEntityMixin.java | 11 ------- .../action/bientity/SimpleBiEntityAction.java | 7 ++-- .../data/apoliforge/powers/dismount.json | 32 +++++++++++++++++++ .../data/apoliforge/powers/pick_up.json | 19 +++++++++++ 5 files changed, 64 insertions(+), 15 deletions(-) create mode 100644 src/test/resources/data/apoliforge/powers/dismount.json create mode 100644 src/test/resources/data/apoliforge/powers/pick_up.json diff --git a/src/main/java/io/github/apace100/apoli/mixin/LivingEntityMixin.java b/src/main/java/io/github/apace100/apoli/mixin/LivingEntityMixin.java index 04b7bd6c3..7a94d70d6 100644 --- a/src/main/java/io/github/apace100/apoli/mixin/LivingEntityMixin.java +++ b/src/main/java/io/github/apace100/apoli/mixin/LivingEntityMixin.java @@ -11,6 +11,7 @@ import io.github.edwinmindcraft.apoli.api.configuration.FieldConfiguration; import io.github.edwinmindcraft.apoli.api.power.configuration.ConfiguredPower; import io.github.edwinmindcraft.apoli.common.ApoliCommon; +import io.github.edwinmindcraft.apoli.common.network.S2CPlayerDismount; import io.github.edwinmindcraft.apoli.common.network.S2CSyncAttacker; import io.github.edwinmindcraft.apoli.common.power.*; import io.github.edwinmindcraft.apoli.common.power.configuration.ActionOnItemUseConfiguration; @@ -21,6 +22,7 @@ import io.github.edwinmindcraft.apoli.common.util.LivingDamageCache; import net.minecraft.core.Holder; import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerPlayer; import net.minecraft.tags.DamageTypeTags; import net.minecraft.world.InteractionHand; import net.minecraft.world.damagesource.CombatRules; @@ -233,6 +235,14 @@ private void allowFreezingPower(CallbackInfoReturnable cir) { if (IPowerContainer.hasPower(this, ApoliPowers.FREEZE.get())) cir.setReturnValue(true); } + // Moved from PlayerEntityMixin. + @Inject(method = "stopRiding", at = @At("HEAD")) + private void sendPlayerDismountPacket(CallbackInfo ci) { + if (!this.level().isClientSide() && this.getVehicle() instanceof ServerPlayer player) { + ApoliCommon.CHANNEL.send(PacketDistributor.PLAYER.with(() -> player), new S2CPlayerDismount(this.getId())); + } + } + // SetEntityGroupPower @Inject(at = @At("HEAD"), method = "getMobType", cancellable = true) public void getGroup(CallbackInfoReturnable info) { diff --git a/src/main/java/io/github/apace100/apoli/mixin/PlayerEntityMixin.java b/src/main/java/io/github/apace100/apoli/mixin/PlayerEntityMixin.java index 3d08c20c5..711538211 100644 --- a/src/main/java/io/github/apace100/apoli/mixin/PlayerEntityMixin.java +++ b/src/main/java/io/github/apace100/apoli/mixin/PlayerEntityMixin.java @@ -3,15 +3,12 @@ import io.github.apace100.apoli.access.ModifiableFoodEntity; import io.github.edwinmindcraft.apoli.api.component.IPowerContainer; import io.github.edwinmindcraft.apoli.api.power.configuration.ConfiguredPower; -import io.github.edwinmindcraft.apoli.common.ApoliCommon; -import io.github.edwinmindcraft.apoli.common.network.S2CPlayerDismount; import io.github.edwinmindcraft.apoli.common.power.ModifyFoodPower; import io.github.edwinmindcraft.apoli.common.power.configuration.ModifyFoodConfiguration; import io.github.edwinmindcraft.apoli.common.registry.ApoliPowers; import io.github.edwinmindcraft.apoli.common.util.CoreUtils; import io.github.edwinmindcraft.apoli.common.util.LivingDamageCache; import net.minecraft.commands.CommandSource; -import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.Nameable; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.*; @@ -22,7 +19,6 @@ import net.minecraft.world.level.Level; import net.minecraft.world.phys.Vec3; import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.network.PacketDistributor; import org.apache.commons.lang3.mutable.MutableObject; import org.jetbrains.annotations.NotNull; import org.spongepowered.asm.mixin.Mixin; @@ -87,13 +83,6 @@ private ItemStack modifyEatenItemStack(ItemStack original) { return stack.getValue(); } - @Inject(method = "removeVehicle", at = @At("HEAD")) - private void sendPlayerDismountPacket(CallbackInfo ci) { - if (!this.level().isClientSide() && this.getVehicle() instanceof ServerPlayer player) { - ApoliCommon.CHANNEL.send(PacketDistributor.PLAYER.with(() -> player), new S2CPlayerDismount(this.getId())); - } - } - // ModifyExhaustion @ModifyVariable(at = @At("HEAD"), method = "causeFoodExhaustion", ordinal = 0, name = "exhaustion", argsOnly = true) private float modifyExhaustion(float exhaustionIn) { diff --git a/src/main/java/io/github/edwinmindcraft/apoli/common/action/bientity/SimpleBiEntityAction.java b/src/main/java/io/github/edwinmindcraft/apoli/common/action/bientity/SimpleBiEntityAction.java index 7c5cea84f..be921fa24 100644 --- a/src/main/java/io/github/edwinmindcraft/apoli/common/action/bientity/SimpleBiEntityAction.java +++ b/src/main/java/io/github/edwinmindcraft/apoli/common/action/bientity/SimpleBiEntityAction.java @@ -2,14 +2,10 @@ import io.github.edwinmindcraft.apoli.api.configuration.NoConfiguration; import io.github.edwinmindcraft.apoli.api.power.factory.BiEntityAction; -import io.github.edwinmindcraft.apoli.common.ApoliCommon; -import io.github.edwinmindcraft.apoli.common.network.S2CPlayerMount; -import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.TamableAnimal; import net.minecraft.world.entity.animal.Animal; import net.minecraft.world.entity.player.Player; -import net.minecraftforge.network.PacketDistributor; import java.util.function.BiConsumer; @@ -17,9 +13,12 @@ public class SimpleBiEntityAction extends BiEntityAction { public static void mount(Entity actor, Entity target) { actor.startRiding(target, true); + // The below is unnecessary as the client will execute the above before the server. + /* if (!actor.level().isClientSide() && target instanceof ServerPlayer player) { ApoliCommon.CHANNEL.send(PacketDistributor.PLAYER.with(() -> player), new S2CPlayerMount(actor.getId(), target.getId())); } + */ } public static void setInLove(Entity actor, Entity target) { diff --git a/src/test/resources/data/apoliforge/powers/dismount.json b/src/test/resources/data/apoliforge/powers/dismount.json new file mode 100644 index 000000000..b26200fc0 --- /dev/null +++ b/src/test/resources/data/apoliforge/powers/dismount.json @@ -0,0 +1,32 @@ +{ + "type": "apoli:active_self", + "cooldown": 1, + "key": { + "key": "key.use", + "continuous": false + }, + "entity_action": { + "type": "apoli:passenger_action", + "bientity_action": { + "type": "apoli:and", + "actions": [ + { + "type": "apoli:actor_action", + "action": { + "type": "apoli:dismount" + } + }, + { + "type": "apoli:target_action", + "action": { + "type": "apoli:swing_hand", + "hand": "MAIN_HAND" + } + } + ] + } + }, + "condition": { + "type": "apoli:sneaking" + } +} \ No newline at end of file diff --git a/src/test/resources/data/apoliforge/powers/pick_up.json b/src/test/resources/data/apoliforge/powers/pick_up.json new file mode 100644 index 000000000..ba00c9b81 --- /dev/null +++ b/src/test/resources/data/apoliforge/powers/pick_up.json @@ -0,0 +1,19 @@ +{ + "type": "apoli:action_on_entity_use", + "bientity_action": { + "type": "apoli:invert", + "action": { + "type": "apoli:mount" + } + }, + "item_condition": { + "type": "apoli:empty" + }, + "hands": [ + "main_hand" + ], + "condition": { + "type": "apoli:sneaking", + "inverted": true + } +} \ No newline at end of file