尝试阻止外部stopRiding

This commit is contained in:
17146 2025-05-11 14:43:43 +08:00 committed by Light_Quanta
parent c99f1a0213
commit 911c616f22
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
11 changed files with 65 additions and 14 deletions

View file

@ -4,6 +4,7 @@ import com.atsuishio.superbwarfare.compat.CompatHolder;
import com.atsuishio.superbwarfare.compat.clothconfig.ClothConfigHelper;
import com.atsuishio.superbwarfare.config.client.ReloadConfig;
import com.atsuishio.superbwarfare.entity.MortarEntity;
import com.atsuishio.superbwarfare.entity.mixin.CustomStopRiding;
import com.atsuishio.superbwarfare.entity.vehicle.base.ArmedVehicleEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.CannonEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity;
@ -467,5 +468,8 @@ public class ClickHandler {
return;
}
PacketDistributor.sendToServer(new PlayerStopRidingMessage(0));
CustomStopRiding customStopRiding = CustomStopRiding.getInstance(player);
customStopRiding.superbwarfare$stopRiding();
}
}

View file

@ -1,4 +1,4 @@
package com.atsuishio.superbwarfare.entity;
package com.atsuishio.superbwarfare.entity.mixin;
import net.minecraft.world.entity.npc.Villager;

View file

@ -0,0 +1,12 @@
package com.atsuishio.superbwarfare.entity.mixin;
import net.minecraft.world.entity.Entity;
public interface CustomStopRiding {
static CustomStopRiding getInstance(Entity entity) {
return (CustomStopRiding) entity;
}
void superbwarfare$stopRiding();
}

View file

@ -1,4 +1,4 @@
package com.atsuishio.superbwarfare.entity;
package com.atsuishio.superbwarfare.entity.mixin;
import net.minecraft.world.entity.LivingEntity;

View file

@ -5,8 +5,8 @@ import com.atsuishio.superbwarfare.component.ModDataComponents;
import com.atsuishio.superbwarfare.config.server.MiscConfig;
import com.atsuishio.superbwarfare.config.server.ProjectileConfig;
import com.atsuishio.superbwarfare.entity.DPSGeneratorEntity;
import com.atsuishio.superbwarfare.entity.ICustomKnockback;
import com.atsuishio.superbwarfare.entity.TargetEntity;
import com.atsuishio.superbwarfare.entity.mixin.ICustomKnockback;
import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity;
import com.atsuishio.superbwarfare.init.*;
import com.atsuishio.superbwarfare.network.message.receive.ClientIndicatorMessage;

View file

@ -5,8 +5,8 @@ import com.atsuishio.superbwarfare.component.ModDataComponents;
import com.atsuishio.superbwarfare.config.common.GameplayConfig;
import com.atsuishio.superbwarfare.config.server.MiscConfig;
import com.atsuishio.superbwarfare.config.server.VehicleConfig;
import com.atsuishio.superbwarfare.entity.ICustomKnockback;
import com.atsuishio.superbwarfare.entity.TargetEntity;
import com.atsuishio.superbwarfare.entity.mixin.ICustomKnockback;
import com.atsuishio.superbwarfare.entity.vehicle.LaserTowerEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.ArmedVehicleEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.ContainerMobileVehicleEntity;

View file

@ -1,7 +1,9 @@
package com.atsuishio.superbwarfare.mixins;
import com.atsuishio.superbwarfare.entity.ICustomKnockback;
import com.atsuishio.superbwarfare.entity.mixin.ICustomKnockback;
import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity;
import com.atsuishio.superbwarfare.event.ClientEventHandler;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import org.spongepowered.asm.mixin.Mixin;
@ -39,4 +41,12 @@ public class LivingEntityMixin implements ICustomKnockback {
}
}
}
@Inject(method = "stopRiding()V", at = @At("HEAD"), cancellable = true)
public void stopRiding(CallbackInfo ci) {
Entity entity = ((LivingEntity) (Object) this).getVehicle();
if (entity instanceof VehicleEntity) {
ci.cancel();
}
}
}

View file

@ -1,38 +1,60 @@
package com.atsuishio.superbwarfare.mixins;
import com.atsuishio.superbwarfare.entity.mixin.CustomStopRiding;
import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity;
import net.minecraft.tags.BlockTags;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.Pose;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
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.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
/**
* Code based on @Luke100000's ImmersiveAircraft
*/
@Mixin(value = Player.class, priority = 1145)
public abstract class PlayerMixin extends Entity {
public abstract class PlayerMixin extends Entity implements CustomStopRiding {
public PlayerMixin(EntityType<?> type, Level world) {
super(type, world);
}
/**
* Code based on @Luke100000's ImmersiveAircraft
*/
@Inject(method = "wantsToStopRiding", at = @At("HEAD"), cancellable = true)
void shouldDismountInjection(CallbackInfoReturnable<Boolean> cir) {
public void shouldDismountInjection(CallbackInfoReturnable<Boolean> cir) {
if (this.getRootVehicle() instanceof VehicleEntity) {
cir.setReturnValue(false);
}
}
@Inject(method = "updatePlayerPose()V", at = @At("TAIL"))
void updatePostInjection(CallbackInfo ci) {
public void updatePostInjection(CallbackInfo ci) {
if (getRootVehicle() instanceof VehicleEntity) {
this.setPose(Pose.STANDING);
}
}
@Override
public void superbwarfare$stopRiding() {
Entity entity = this.getVehicle();
this.removeVehicle();
if (entity != null && entity != this.getVehicle() && !this.level().isClientSide) {
Vec3 vec3;
if (this.isRemoved()) {
vec3 = this.position();
} else if (!entity.isRemoved() && !this.level().getBlockState(entity.blockPosition()).is(BlockTags.PORTALS)) {
vec3 = entity.getDismountLocationForPassenger((Player) (Object) this);
} else {
double d0 = Math.max(this.getY(), entity.getY());
vec3 = new Vec3(this.getX(), d0, this.getZ());
}
this.dismountTo(vec3.x, vec3.y, vec3.z);
}
}
}

View file

@ -1,6 +1,6 @@
package com.atsuishio.superbwarfare.mixins;
import com.atsuishio.superbwarfare.entity.CupidLove;
import com.atsuishio.superbwarfare.entity.mixin.CupidLove;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.entity.npc.Villager;
import org.spongepowered.asm.mixin.Mixin;

View file

@ -1,6 +1,7 @@
package com.atsuishio.superbwarfare.network.message.send;
import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.entity.mixin.CustomStopRiding;
import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity;
import io.netty.buffer.ByteBuf;
import net.minecraft.network.codec.ByteBufCodecs;
@ -24,7 +25,9 @@ public record PlayerStopRidingMessage(int msgType) implements CustomPacketPayloa
var vehicle = player.getVehicle();
if (!(vehicle instanceof VehicleEntity)) return;
player.stopRiding();
CustomStopRiding customStopRiding = CustomStopRiding.getInstance(player);
customStopRiding.superbwarfare$stopRiding();
player.setJumping(false);
}

View file

@ -1,6 +1,6 @@
package com.atsuishio.superbwarfare.perk.ammo;
import com.atsuishio.superbwarfare.entity.CupidLove;
import com.atsuishio.superbwarfare.entity.mixin.CupidLove;
import com.atsuishio.superbwarfare.item.gun.data.GunData;
import com.atsuishio.superbwarfare.perk.AmmoPerk;
import com.atsuishio.superbwarfare.perk.Perk;