尝试阻止外部stopRiding
This commit is contained in:
parent
c99f1a0213
commit
911c616f22
11 changed files with 65 additions and 14 deletions
|
@ -4,6 +4,7 @@ import com.atsuishio.superbwarfare.compat.CompatHolder;
|
||||||
import com.atsuishio.superbwarfare.compat.clothconfig.ClothConfigHelper;
|
import com.atsuishio.superbwarfare.compat.clothconfig.ClothConfigHelper;
|
||||||
import com.atsuishio.superbwarfare.config.client.ReloadConfig;
|
import com.atsuishio.superbwarfare.config.client.ReloadConfig;
|
||||||
import com.atsuishio.superbwarfare.entity.MortarEntity;
|
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.ArmedVehicleEntity;
|
||||||
import com.atsuishio.superbwarfare.entity.vehicle.base.CannonEntity;
|
import com.atsuishio.superbwarfare.entity.vehicle.base.CannonEntity;
|
||||||
import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity;
|
import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity;
|
||||||
|
@ -467,5 +468,8 @@ public class ClickHandler {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
PacketDistributor.sendToServer(new PlayerStopRidingMessage(0));
|
PacketDistributor.sendToServer(new PlayerStopRidingMessage(0));
|
||||||
|
|
||||||
|
CustomStopRiding customStopRiding = CustomStopRiding.getInstance(player);
|
||||||
|
customStopRiding.superbwarfare$stopRiding();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package com.atsuishio.superbwarfare.entity;
|
package com.atsuishio.superbwarfare.entity.mixin;
|
||||||
|
|
||||||
import net.minecraft.world.entity.npc.Villager;
|
import net.minecraft.world.entity.npc.Villager;
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package com.atsuishio.superbwarfare.entity;
|
package com.atsuishio.superbwarfare.entity.mixin;
|
||||||
|
|
||||||
import net.minecraft.world.entity.LivingEntity;
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
|
|
|
@ -5,8 +5,8 @@ import com.atsuishio.superbwarfare.component.ModDataComponents;
|
||||||
import com.atsuishio.superbwarfare.config.server.MiscConfig;
|
import com.atsuishio.superbwarfare.config.server.MiscConfig;
|
||||||
import com.atsuishio.superbwarfare.config.server.ProjectileConfig;
|
import com.atsuishio.superbwarfare.config.server.ProjectileConfig;
|
||||||
import com.atsuishio.superbwarfare.entity.DPSGeneratorEntity;
|
import com.atsuishio.superbwarfare.entity.DPSGeneratorEntity;
|
||||||
import com.atsuishio.superbwarfare.entity.ICustomKnockback;
|
|
||||||
import com.atsuishio.superbwarfare.entity.TargetEntity;
|
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.entity.vehicle.base.VehicleEntity;
|
||||||
import com.atsuishio.superbwarfare.init.*;
|
import com.atsuishio.superbwarfare.init.*;
|
||||||
import com.atsuishio.superbwarfare.network.message.receive.ClientIndicatorMessage;
|
import com.atsuishio.superbwarfare.network.message.receive.ClientIndicatorMessage;
|
||||||
|
|
|
@ -5,8 +5,8 @@ import com.atsuishio.superbwarfare.component.ModDataComponents;
|
||||||
import com.atsuishio.superbwarfare.config.common.GameplayConfig;
|
import com.atsuishio.superbwarfare.config.common.GameplayConfig;
|
||||||
import com.atsuishio.superbwarfare.config.server.MiscConfig;
|
import com.atsuishio.superbwarfare.config.server.MiscConfig;
|
||||||
import com.atsuishio.superbwarfare.config.server.VehicleConfig;
|
import com.atsuishio.superbwarfare.config.server.VehicleConfig;
|
||||||
import com.atsuishio.superbwarfare.entity.ICustomKnockback;
|
|
||||||
import com.atsuishio.superbwarfare.entity.TargetEntity;
|
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.LaserTowerEntity;
|
||||||
import com.atsuishio.superbwarfare.entity.vehicle.base.ArmedVehicleEntity;
|
import com.atsuishio.superbwarfare.entity.vehicle.base.ArmedVehicleEntity;
|
||||||
import com.atsuishio.superbwarfare.entity.vehicle.base.ContainerMobileVehicleEntity;
|
import com.atsuishio.superbwarfare.entity.vehicle.base.ContainerMobileVehicleEntity;
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package com.atsuishio.superbwarfare.mixins;
|
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 com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||||
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.entity.LivingEntity;
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1,38 +1,60 @@
|
||||||
package com.atsuishio.superbwarfare.mixins;
|
package com.atsuishio.superbwarfare.mixins;
|
||||||
|
|
||||||
|
import com.atsuishio.superbwarfare.entity.mixin.CustomStopRiding;
|
||||||
import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity;
|
import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity;
|
||||||
|
import net.minecraft.tags.BlockTags;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.entity.EntityType;
|
import net.minecraft.world.entity.EntityType;
|
||||||
import net.minecraft.world.entity.Pose;
|
import net.minecraft.world.entity.Pose;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
|
import net.minecraft.world.phys.Vec3;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
/**
|
|
||||||
* Code based on @Luke100000's ImmersiveAircraft
|
|
||||||
*/
|
|
||||||
@Mixin(value = Player.class, priority = 1145)
|
@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) {
|
public PlayerMixin(EntityType<?> type, Level world) {
|
||||||
super(type, world);
|
super(type, world);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Code based on @Luke100000's ImmersiveAircraft
|
||||||
|
*/
|
||||||
@Inject(method = "wantsToStopRiding", at = @At("HEAD"), cancellable = true)
|
@Inject(method = "wantsToStopRiding", at = @At("HEAD"), cancellable = true)
|
||||||
void shouldDismountInjection(CallbackInfoReturnable<Boolean> cir) {
|
public void shouldDismountInjection(CallbackInfoReturnable<Boolean> cir) {
|
||||||
if (this.getRootVehicle() instanceof VehicleEntity) {
|
if (this.getRootVehicle() instanceof VehicleEntity) {
|
||||||
cir.setReturnValue(false);
|
cir.setReturnValue(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(method = "updatePlayerPose()V", at = @At("TAIL"))
|
@Inject(method = "updatePlayerPose()V", at = @At("TAIL"))
|
||||||
void updatePostInjection(CallbackInfo ci) {
|
public void updatePostInjection(CallbackInfo ci) {
|
||||||
if (getRootVehicle() instanceof VehicleEntity) {
|
if (getRootVehicle() instanceof VehicleEntity) {
|
||||||
this.setPose(Pose.STANDING);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package com.atsuishio.superbwarfare.mixins;
|
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.nbt.CompoundTag;
|
||||||
import net.minecraft.world.entity.npc.Villager;
|
import net.minecraft.world.entity.npc.Villager;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.atsuishio.superbwarfare.network.message.send;
|
package com.atsuishio.superbwarfare.network.message.send;
|
||||||
|
|
||||||
import com.atsuishio.superbwarfare.Mod;
|
import com.atsuishio.superbwarfare.Mod;
|
||||||
|
import com.atsuishio.superbwarfare.entity.mixin.CustomStopRiding;
|
||||||
import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity;
|
import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import net.minecraft.network.codec.ByteBufCodecs;
|
import net.minecraft.network.codec.ByteBufCodecs;
|
||||||
|
@ -24,7 +25,9 @@ public record PlayerStopRidingMessage(int msgType) implements CustomPacketPayloa
|
||||||
var vehicle = player.getVehicle();
|
var vehicle = player.getVehicle();
|
||||||
if (!(vehicle instanceof VehicleEntity)) return;
|
if (!(vehicle instanceof VehicleEntity)) return;
|
||||||
|
|
||||||
player.stopRiding();
|
CustomStopRiding customStopRiding = CustomStopRiding.getInstance(player);
|
||||||
|
customStopRiding.superbwarfare$stopRiding();
|
||||||
|
|
||||||
player.setJumping(false);
|
player.setJumping(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package com.atsuishio.superbwarfare.perk.ammo;
|
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.item.gun.data.GunData;
|
||||||
import com.atsuishio.superbwarfare.perk.AmmoPerk;
|
import com.atsuishio.superbwarfare.perk.AmmoPerk;
|
||||||
import com.atsuishio.superbwarfare.perk.Perk;
|
import com.atsuishio.superbwarfare.perk.Perk;
|
||||||
|
|
Loading…
Add table
Reference in a new issue