平滑炮塔的旋转,添加在船驾驶位空手右键进入瞄准视角
This commit is contained in:
parent
a7c206a95b
commit
a33ec13136
6 changed files with 72 additions and 23 deletions
|
@ -7,6 +7,7 @@ import com.atsuishio.superbwarfare.config.client.ReloadConfig;
|
||||||
import com.atsuishio.superbwarfare.entity.ICannonEntity;
|
import com.atsuishio.superbwarfare.entity.ICannonEntity;
|
||||||
import com.atsuishio.superbwarfare.entity.IVehicleEntity;
|
import com.atsuishio.superbwarfare.entity.IVehicleEntity;
|
||||||
import com.atsuishio.superbwarfare.entity.MortarEntity;
|
import com.atsuishio.superbwarfare.entity.MortarEntity;
|
||||||
|
import com.atsuishio.superbwarfare.entity.SpeedboatEntity;
|
||||||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||||
import com.atsuishio.superbwarfare.init.*;
|
import com.atsuishio.superbwarfare.init.*;
|
||||||
import com.atsuishio.superbwarfare.network.ModVariables;
|
import com.atsuishio.superbwarfare.network.ModVariables;
|
||||||
|
@ -103,7 +104,9 @@ public class ClickHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (button == GLFW.GLFW_MOUSE_BUTTON_RIGHT) {
|
if (button == GLFW.GLFW_MOUSE_BUTTON_RIGHT) {
|
||||||
if (player.getMainHandItem().is(ModTags.Items.GUN) || (player.isPassenger() && player.getVehicle() instanceof ICannonEntity)) {
|
if (stack.is(ModTags.Items.GUN)
|
||||||
|
|| (player.isPassenger() && player.getVehicle() instanceof ICannonEntity)
|
||||||
|
|| (player.getVehicle() != null && player.getVehicle() instanceof SpeedboatEntity boat && boat.getFirstPassenger() == player && stack.is(ItemStack.EMPTY.getItem()))) {
|
||||||
event.setCanceled(true);
|
event.setCanceled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -117,6 +120,7 @@ public class ClickHandler {
|
||||||
if ((player.getMainHandItem().is(ModTags.Items.GUN) && !(player.getVehicle() != null && player.getVehicle() instanceof ICannonEntity))
|
if ((player.getMainHandItem().is(ModTags.Items.GUN) && !(player.getVehicle() != null && player.getVehicle() instanceof ICannonEntity))
|
||||||
|| stack.is(ModItems.MONITOR.get())
|
|| stack.is(ModItems.MONITOR.get())
|
||||||
|| (player.getVehicle() != null && player.getVehicle() instanceof ICannonEntity)
|
|| (player.getVehicle() != null && player.getVehicle() instanceof ICannonEntity)
|
||||||
|
|| (player.getVehicle() != null && player.getVehicle() instanceof SpeedboatEntity boat && boat.getFirstPassenger() == player)
|
||||||
|| (stack.is(Items.SPYGLASS) && player.isScoping() && player.getOffhandItem().is(ModItems.FIRING_PARAMETERS.get()))) {
|
|| (stack.is(Items.SPYGLASS) && player.isScoping() && player.getOffhandItem().is(ModItems.FIRING_PARAMETERS.get()))) {
|
||||||
if (button == ModKeyMappings.FIRE.getKey().getValue()) {
|
if (button == ModKeyMappings.FIRE.getKey().getValue()) {
|
||||||
handleWeaponFirePress(player, stack);
|
handleWeaponFirePress(player, stack);
|
||||||
|
@ -238,6 +242,7 @@ public class ClickHandler {
|
||||||
if ((player.getMainHandItem().is(ModTags.Items.GUN) && !(player.getVehicle() != null && player.getVehicle() instanceof ICannonEntity))
|
if ((player.getMainHandItem().is(ModTags.Items.GUN) && !(player.getVehicle() != null && player.getVehicle() instanceof ICannonEntity))
|
||||||
|| stack.is(ModItems.MONITOR.get())
|
|| stack.is(ModItems.MONITOR.get())
|
||||||
|| (player.getVehicle() != null && player.getVehicle() instanceof ICannonEntity)
|
|| (player.getVehicle() != null && player.getVehicle() instanceof ICannonEntity)
|
||||||
|
|| (player.getVehicle() != null && player.getVehicle() instanceof SpeedboatEntity boat && boat.getFirstPassenger() == player)
|
||||||
|| (stack.is(Items.SPYGLASS) && player.isScoping() && player.getOffhandItem().is(ModItems.FIRING_PARAMETERS.get()))) {
|
|| (stack.is(Items.SPYGLASS) && player.isScoping() && player.getOffhandItem().is(ModItems.FIRING_PARAMETERS.get()))) {
|
||||||
if (key == ModKeyMappings.FIRE.getKey().getValue()) {
|
if (key == ModKeyMappings.FIRE.getKey().getValue()) {
|
||||||
handleWeaponFirePress(player, stack);
|
handleWeaponFirePress(player, stack);
|
||||||
|
|
|
@ -3,7 +3,6 @@ package com.atsuishio.superbwarfare.client.model.entity;
|
||||||
import com.atsuishio.superbwarfare.ModUtils;
|
import com.atsuishio.superbwarfare.ModUtils;
|
||||||
import com.atsuishio.superbwarfare.entity.SpeedboatEntity;
|
import com.atsuishio.superbwarfare.entity.SpeedboatEntity;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.util.Mth;
|
|
||||||
import software.bernie.geckolib.core.animatable.model.CoreGeoBone;
|
import software.bernie.geckolib.core.animatable.model.CoreGeoBone;
|
||||||
import software.bernie.geckolib.core.animation.AnimationState;
|
import software.bernie.geckolib.core.animation.AnimationState;
|
||||||
import software.bernie.geckolib.model.GeoModel;
|
import software.bernie.geckolib.model.GeoModel;
|
||||||
|
@ -35,10 +34,5 @@ public class SpeedboatModel extends GeoModel<SpeedboatEntity> {
|
||||||
|
|
||||||
rotor.setRotZ(5 * animatable.getEntityData().get(ROTOR));
|
rotor.setRotZ(5 * animatable.getEntityData().get(ROTOR));
|
||||||
duo.setRotY((animatable.getEntityData().get(POWER) > 0 ? -0.5f : 0.5f) * animatable.getEntityData().get(DELTA_ROT));
|
duo.setRotY((animatable.getEntityData().get(POWER) > 0 ? -0.5f : 0.5f) * animatable.getEntityData().get(DELTA_ROT));
|
||||||
|
|
||||||
CoreGeoBone turret = getAnimationProcessor().getBone("paota");
|
|
||||||
CoreGeoBone gun = getAnimationProcessor().getBone("gun");
|
|
||||||
turret.setRotY(animatable.getEntityData().get(GUN_YAW) * Mth.DEG_TO_RAD);
|
|
||||||
gun.setRotX(-animatable.getEntityData().get(GUN_PITCH) * Mth.DEG_TO_RAD);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import net.minecraft.client.renderer.entity.EntityRendererProvider;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.util.Mth;
|
import net.minecraft.util.Mth;
|
||||||
import software.bernie.geckolib.cache.object.BakedGeoModel;
|
import software.bernie.geckolib.cache.object.BakedGeoModel;
|
||||||
|
import software.bernie.geckolib.cache.object.GeoBone;
|
||||||
import software.bernie.geckolib.renderer.GeoEntityRenderer;
|
import software.bernie.geckolib.renderer.GeoEntityRenderer;
|
||||||
|
|
||||||
public class SpeedboatRenderer extends GeoEntityRenderer<SpeedboatEntity> {
|
public class SpeedboatRenderer extends GeoEntityRenderer<SpeedboatEntity> {
|
||||||
|
@ -41,6 +42,18 @@ public class SpeedboatRenderer extends GeoEntityRenderer<SpeedboatEntity> {
|
||||||
poseStack.popPose();
|
poseStack.popPose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void renderRecursively(PoseStack poseStack, SpeedboatEntity animatable, GeoBone bone, RenderType renderType, MultiBufferSource bufferSource, VertexConsumer buffer, boolean isReRender, float partialTick, int packedLight, int packedOverlay, float red, float green, float blue, float alpha) {
|
||||||
|
String name = bone.getName();
|
||||||
|
if (name.equals("paota")) {
|
||||||
|
bone.setRotY(Mth.lerp(partialTick, animatable.turretYRotO, animatable.getTurretYRot()) * Mth.DEG_TO_RAD);
|
||||||
|
}
|
||||||
|
if (name.equals("gun")) {
|
||||||
|
bone.setRotX(-Mth.lerp(partialTick, animatable.turretXRotO, animatable.getTurretXRot()) * Mth.DEG_TO_RAD);
|
||||||
|
}
|
||||||
|
super.renderRecursively(poseStack, animatable, bone, renderType, bufferSource, buffer, isReRender, partialTick, packedLight, packedOverlay, red, green, blue, alpha);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected float getDeathMaxRotation(SpeedboatEntity entityLivingBaseIn) {
|
protected float getDeathMaxRotation(SpeedboatEntity entityLivingBaseIn) {
|
||||||
return 0.0F;
|
return 0.0F;
|
||||||
|
|
|
@ -7,7 +7,6 @@ import com.atsuishio.superbwarfare.init.*;
|
||||||
import com.atsuishio.superbwarfare.item.ContainerBlockItem;
|
import com.atsuishio.superbwarfare.item.ContainerBlockItem;
|
||||||
import com.atsuishio.superbwarfare.tools.CustomExplosion;
|
import com.atsuishio.superbwarfare.tools.CustomExplosion;
|
||||||
import com.atsuishio.superbwarfare.tools.ParticleTool;
|
import com.atsuishio.superbwarfare.tools.ParticleTool;
|
||||||
import net.minecraft.commands.arguments.EntityAnchorArgument;
|
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.network.protocol.Packet;
|
import net.minecraft.network.protocol.Packet;
|
||||||
|
@ -57,8 +56,6 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity,
|
||||||
public static final EntityDataAccessor<Float> DELTA_ROT = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.FLOAT);
|
public static final EntityDataAccessor<Float> DELTA_ROT = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.FLOAT);
|
||||||
public static final EntityDataAccessor<Float> POWER = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.FLOAT);
|
public static final EntityDataAccessor<Float> POWER = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.FLOAT);
|
||||||
public static final EntityDataAccessor<Float> ROTOR = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.FLOAT);
|
public static final EntityDataAccessor<Float> ROTOR = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.FLOAT);
|
||||||
public static final EntityDataAccessor<Float> GUN_YAW = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.FLOAT);
|
|
||||||
public static final EntityDataAccessor<Float> GUN_PITCH = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.FLOAT);
|
|
||||||
|
|
||||||
public static final float MAX_HEALTH = CannonConfig.MK42_HP.get();
|
public static final float MAX_HEALTH = CannonConfig.MK42_HP.get();
|
||||||
|
|
||||||
|
@ -70,6 +67,14 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity,
|
||||||
private double lerpYRot;
|
private double lerpYRot;
|
||||||
private double lerpXRot;
|
private double lerpXRot;
|
||||||
|
|
||||||
|
public float turretYRot;
|
||||||
|
public float turretXRot;
|
||||||
|
public float turretYRotO;
|
||||||
|
public float turretXRotO;
|
||||||
|
|
||||||
|
public float rudderYRot;
|
||||||
|
public float rudderYRot0;
|
||||||
|
|
||||||
public SpeedboatEntity(PlayMessages.SpawnEntity packet, Level world) {
|
public SpeedboatEntity(PlayMessages.SpawnEntity packet, Level world) {
|
||||||
this(ModEntities.SPEEDBOAT.get(), world);
|
this(ModEntities.SPEEDBOAT.get(), world);
|
||||||
}
|
}
|
||||||
|
@ -86,8 +91,6 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity,
|
||||||
this.entityData.define(DELTA_ROT, 0f);
|
this.entityData.define(DELTA_ROT, 0f);
|
||||||
this.entityData.define(POWER, 0f);
|
this.entityData.define(POWER, 0f);
|
||||||
this.entityData.define(ROTOR, 0f);
|
this.entityData.define(ROTOR, 0f);
|
||||||
this.entityData.define(GUN_YAW, 0f);
|
|
||||||
this.entityData.define(GUN_PITCH, 0f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -335,7 +338,7 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity,
|
||||||
// Vec3 driverAngleVec = driver.getLookAngle().normalize();
|
// Vec3 driverAngleVec = driver.getLookAngle().normalize();
|
||||||
// double lookAngle = calculateAngle(driverAngleVec, rightVec);
|
// double lookAngle = calculateAngle(driverAngleVec, rightVec);
|
||||||
|
|
||||||
double gunAngle = -Math.clamp(-105f, 105f, Mth.wrapDegrees(driver.getYHeadRot() - this.getYRot()));
|
float gunAngle = -Math.clamp(-105f, 105f, Mth.wrapDegrees(driver.getYHeadRot() - this.getYRot()));
|
||||||
// if (lookAngle < 90) {
|
// if (lookAngle < 90) {
|
||||||
// gunAngle = calculateAngle(driver.getLookAngle(), this.getLookAngle());
|
// gunAngle = calculateAngle(driver.getLookAngle(), this.getLookAngle());
|
||||||
// } else {
|
// } else {
|
||||||
|
@ -348,17 +351,30 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity,
|
||||||
// gunAngle += 360;
|
// gunAngle += 360;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
this.entityData.set(GUN_YAW, (float) Mth.lerp(0.2, this.entityData.get(GUN_YAW), gunAngle));
|
// this.entityData.set(GUN_YAW, gunAngle);
|
||||||
|
// this.entityData.set(GUN_YAW_O, this.entityData.get(GUN_YAW));
|
||||||
|
|
||||||
float diffX = driver.getXRot() - this.getXRot();
|
turretYRotO = this.getTurretYRot();
|
||||||
this.entityData.set(GUN_PITCH, (float) Mth.lerp(0.1, this.entityData.get(GUN_PITCH), diffX));
|
turretXRotO = this.getTurretXRot();
|
||||||
|
|
||||||
|
this.setTurretYRot(gunAngle);
|
||||||
|
this.setTurretXRot(driver.getXRot() - this.getXRot());
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getRotY(EntityAnchorArgument.Anchor pAnchor, Vec3 pTarget) {
|
public float getTurretYRot() {
|
||||||
Vec3 vec3 = pAnchor.apply(this);
|
return this.turretYRot;
|
||||||
double d0 = (pTarget.x - vec3.x) * 0.2;
|
}
|
||||||
double d2 = (pTarget.z - vec3.z) * 0.2;
|
|
||||||
return Mth.wrapDegrees((float) (Mth.atan2(d2, d0) * 57.2957763671875) - 90.0F);
|
public void setTurretYRot(float pTurretYRot) {
|
||||||
|
this.turretYRot = pTurretYRot;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getTurretXRot() {
|
||||||
|
return this.turretXRot;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTurretXRot(float pTurretXRot) {
|
||||||
|
this.turretXRot = pTurretXRot;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleSetDiffY(float diffY) {
|
private void handleSetDiffY(float diffY) {
|
||||||
|
@ -455,7 +471,7 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity,
|
||||||
|
|
||||||
protected void clampRotation(Entity entity) {
|
protected void clampRotation(Entity entity) {
|
||||||
float f = Mth.wrapDegrees(entity.getXRot());
|
float f = Mth.wrapDegrees(entity.getXRot());
|
||||||
float f1 = Mth.clamp(f, -85.0F, 16.3F);
|
float f1 = Mth.clamp(f, -35.0F, 20F);
|
||||||
entity.xRotO += f1 - f;
|
entity.xRotO += f1 - f;
|
||||||
entity.setXRot(entity.getXRot() + f1 - f);
|
entity.setXRot(entity.getXRot() + f1 - f);
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ import com.atsuishio.superbwarfare.client.ClickHandler;
|
||||||
import com.atsuishio.superbwarfare.config.client.DisplayConfig;
|
import com.atsuishio.superbwarfare.config.client.DisplayConfig;
|
||||||
import com.atsuishio.superbwarfare.entity.DroneEntity;
|
import com.atsuishio.superbwarfare.entity.DroneEntity;
|
||||||
import com.atsuishio.superbwarfare.entity.ICannonEntity;
|
import com.atsuishio.superbwarfare.entity.ICannonEntity;
|
||||||
|
import com.atsuishio.superbwarfare.entity.SpeedboatEntity;
|
||||||
import com.atsuishio.superbwarfare.init.*;
|
import com.atsuishio.superbwarfare.init.*;
|
||||||
import com.atsuishio.superbwarfare.network.ModVariables;
|
import com.atsuishio.superbwarfare.network.ModVariables;
|
||||||
import com.atsuishio.superbwarfare.network.message.LaserShootMessage;
|
import com.atsuishio.superbwarfare.network.message.LaserShootMessage;
|
||||||
|
@ -694,6 +695,10 @@ public class ClientEventHandler {
|
||||||
if (player.getVehicle() != null && player.getVehicle() instanceof ICannonEntity) {
|
if (player.getVehicle() != null && player.getVehicle() instanceof ICannonEntity) {
|
||||||
event.setCanceled(true);
|
event.setCanceled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((player.getVehicle() != null && player.getVehicle() instanceof SpeedboatEntity boat && boat.getFirstPassenger() == player) && ClientEventHandler.zoom && stack.is(ItemStack.EMPTY.getItem())) {
|
||||||
|
event.setCanceled(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void handleWeaponSway(LivingEntity entity) {
|
private static void handleWeaponSway(LivingEntity entity) {
|
||||||
|
|
|
@ -39,6 +39,22 @@ public abstract class CameraMixin {
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
ItemStack stack = player.getMainHandItem();
|
ItemStack stack = player.getMainHandItem();
|
||||||
|
|
||||||
|
if ((player.getVehicle() != null && player.getVehicle() instanceof SpeedboatEntity boat && boat.getFirstPassenger() == player) && ClientEventHandler.zoom && stack.is(ItemStack.EMPTY.getItem())) {
|
||||||
|
float yRot = boat.getYRot();
|
||||||
|
if (yRot < 0) {
|
||||||
|
yRot += 360;
|
||||||
|
}
|
||||||
|
yRot = yRot + 90 % 360;
|
||||||
|
var CameraPos = new Vector3d(-0.6, 3.3, 0);
|
||||||
|
CameraPos.rotateZ(-boat.getXRot() * Mth.DEG_TO_RAD);
|
||||||
|
CameraPos.rotateY(-yRot * Mth.DEG_TO_RAD);
|
||||||
|
setRotation(player.getViewYRot(partialTicks), player.getViewXRot(partialTicks));
|
||||||
|
setPosition(Mth.lerp(partialTicks, boat.xo + CameraPos.x, boat.getX() + CameraPos.x), Mth.lerp(partialTicks, boat.yo + CameraPos.y, boat.getY() + CameraPos.y), Mth.lerp(partialTicks, boat.zo + CameraPos.z, boat.getZ() + CameraPos.z));
|
||||||
|
info.cancel();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (stack.is(ModItems.MONITOR.get()) && stack.getOrCreateTag().getBoolean("Using") && stack.getOrCreateTag().getBoolean("Linked")) {
|
if (stack.is(ModItems.MONITOR.get()) && stack.getOrCreateTag().getBoolean("Using") && stack.getOrCreateTag().getBoolean("Linked")) {
|
||||||
DroneEntity drone = EntityFindUtil.findDrone(player.level(), stack.getOrCreateTag().getString("LinkedDrone"));
|
DroneEntity drone = EntityFindUtil.findDrone(player.level(), stack.getOrCreateTag().getString("LinkedDrone"));
|
||||||
|
|
||||||
|
@ -73,7 +89,7 @@ public abstract class CameraMixin {
|
||||||
move(-getMaxZoom(16), 1.3, 0.0);
|
move(-getMaxZoom(16), 1.3, 0.0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (thirdPerson && entity.getVehicle() instanceof SpeedboatEntity) {
|
if (thirdPerson && entity.getVehicle() instanceof SpeedboatEntity && !ClientEventHandler.zoom) {
|
||||||
move(-getMaxZoom(3), 1, 0.0);
|
move(-getMaxZoom(3), 1, 0.0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue