添加更多载具的后座力

This commit is contained in:
Atsuihsio 2025-03-19 05:58:14 +08:00
parent 25067360f6
commit a829085b6d
10 changed files with 8118 additions and 8015 deletions

View file

@ -18,6 +18,8 @@ import software.bernie.geckolib.cache.object.BakedGeoModel;
import software.bernie.geckolib.cache.object.GeoBone;
import software.bernie.geckolib.renderer.GeoEntityRenderer;
import static com.atsuishio.superbwarfare.entity.vehicle.base.MobileVehicleEntity.YAW;
public class Bmp2Renderer extends GeoEntityRenderer<Bmp2Entity> {
public Bmp2Renderer(EntityRendererProvider.Context renderManager) {
@ -77,6 +79,33 @@ public class Bmp2Renderer extends GeoEntityRenderer<Bmp2Entity> {
bone.setRotZ((float) (0.5 * (Math.random() - 0.5)));
}
if (name.equals("base")) {
Player player = Minecraft.getInstance().player;
bone.setHidden(ClientEventHandler.zoomVehicle && animatable.getFirstPassenger() == player);
float a = animatable.getEntityData().get(YAW);
float r = (Mth.abs(a) - 90f) / 90f;
bone.setPosZ(r * Mth.lerp(partialTick, (float) animatable.recoilShakeO, (float) animatable.getRecoilShake()) * 0.125f);
bone.setRotX(r * Mth.lerp(partialTick, (float) animatable.recoilShakeO, (float) animatable.getRecoilShake()) * Mth.DEG_TO_RAD * 0.06f);
float r2;
if (Mth.abs(a) <= 90f) {
r2 = a / 90f;
} else {
if (a < 0) {
r2 = - (180f + a) / 90f;
} else {
r2 = (180f - a) / 90f;
}
}
bone.setPosX(r2 * Mth.lerp(partialTick, (float) animatable.recoilShakeO, (float) animatable.getRecoilShake()) * 0.125f);
bone.setRotZ(r2 * Mth.lerp(partialTick, (float) animatable.recoilShakeO, (float) animatable.getRecoilShake()) * Mth.DEG_TO_RAD * 0.2f);
}
for (int i = 0; i < 51; i++) {
float tO = animatable.leftTrackO + 2 * i;
float t = animatable.getLeftTrack() + 2 * i;

View file

@ -18,6 +18,8 @@ import software.bernie.geckolib.cache.object.BakedGeoModel;
import software.bernie.geckolib.cache.object.GeoBone;
import software.bernie.geckolib.renderer.GeoEntityRenderer;
import static com.atsuishio.superbwarfare.entity.vehicle.base.MobileVehicleEntity.YAW;
public class Lav150Renderer extends GeoEntityRenderer<Lav150Entity> {
public Lav150Renderer(EntityRendererProvider.Context renderManager) {
@ -64,6 +66,34 @@ public class Lav150Renderer extends GeoEntityRenderer<Lav150Entity> {
if (name.equals("wheel4")) {
bone.setRotX(1.5f * Mth.lerp(partialTick, animatable.leftWheelRotO, animatable.getLeftWheelRot()));
}
if (name.equals("base")) {
Player player = Minecraft.getInstance().player;
bone.setHidden(ClientEventHandler.zoomVehicle && animatable.getFirstPassenger() == player);
float a = animatable.getEntityData().get(YAW);
float r = (Mth.abs(a) - 90f) / 90f;
bone.setPosZ(r * Mth.lerp(partialTick, (float) animatable.recoilShakeO, (float) animatable.getRecoilShake()) * 0.2f);
bone.setRotX(r * Mth.lerp(partialTick, (float) animatable.recoilShakeO, (float) animatable.getRecoilShake()) * Mth.DEG_TO_RAD * 0.3f);
float r2;
if (Mth.abs(a) <= 90f) {
r2 = a / 90f;
} else {
if (a < 0) {
r2 = - (180f + a) / 90f;
} else {
r2 = (180f - a) / 90f;
}
}
bone.setPosX(r2 * Mth.lerp(partialTick, (float) animatable.recoilShakeO, (float) animatable.getRecoilShake()) * 0.15f);
bone.setRotZ(r2 * Mth.lerp(partialTick, (float) animatable.recoilShakeO, (float) animatable.getRecoilShake()) * Mth.DEG_TO_RAD * 0.5f);
}
if (name.equals("cannon")) {
Player player = Minecraft.getInstance().player;

View file

@ -5,18 +5,23 @@ import com.atsuishio.superbwarfare.client.layer.SpeedBoatLayer;
import com.atsuishio.superbwarfare.client.layer.SpeedBoatPowerLayer;
import com.atsuishio.superbwarfare.client.model.entity.SpeedboatModel;
import com.atsuishio.superbwarfare.entity.vehicle.SpeedboatEntity;
import com.atsuishio.superbwarfare.event.ClientEventHandler;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.math.Axis;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.player.Player;
import software.bernie.geckolib.cache.object.BakedGeoModel;
import software.bernie.geckolib.cache.object.GeoBone;
import software.bernie.geckolib.renderer.GeoEntityRenderer;
import static com.atsuishio.superbwarfare.entity.vehicle.base.MobileVehicleEntity.YAW;
public class SpeedboatRenderer extends GeoEntityRenderer<SpeedboatEntity> {
public SpeedboatRenderer(EntityRendererProvider.Context renderManager) {
@ -51,6 +56,33 @@ public class SpeedboatRenderer extends GeoEntityRenderer<SpeedboatEntity> {
@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("root")) {
Player player = Minecraft.getInstance().player;
bone.setHidden(ClientEventHandler.zoomVehicle && animatable.getFirstPassenger() == player);
float a = animatable.getEntityData().get(YAW);
float r = (Mth.abs(a) - 90f) / 90f;
bone.setPosZ(r * Mth.lerp(partialTick, (float) animatable.recoilShakeO, (float) animatable.getRecoilShake()) * 0.125f);
bone.setRotX(r * Mth.lerp(partialTick, (float) animatable.recoilShakeO, (float) animatable.getRecoilShake()) * Mth.DEG_TO_RAD * 0.5f);
float r2;
if (Mth.abs(a) <= 90f) {
r2 = a / 90f;
} else {
if (a < 0) {
r2 = - (180f + a) / 90f;
} else {
r2 = (180f - a) / 90f;
}
}
bone.setPosX(r2 * Mth.lerp(partialTick, (float) animatable.recoilShakeO, (float) animatable.getRecoilShake()) * 0.125f);
bone.setRotZ(r2 * Mth.lerp(partialTick, (float) animatable.recoilShakeO, (float) animatable.getRecoilShake()) * Mth.DEG_TO_RAD * 0.75f);
}
if (name.equals("Rotor")) {
bone.setRotZ(Mth.lerp(partialTick, animatable.rotorRotO, animatable.getRotorRot()));
}

View file

@ -63,6 +63,7 @@ import java.util.Comparator;
import static com.atsuishio.superbwarfare.tools.ParticleTool.sendParticle;
public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntity, LandArmorEntity, WeaponVehicleEntity {
public static final EntityDataAccessor<Integer> CANNON_FIRE_TIME = SynchedEntityData.defineId(Bmp2Entity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Integer> LOADED_MISSILE = SynchedEntityData.defineId(Bmp2Entity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Integer> MISSILE_COUNT = SynchedEntityData.defineId(Bmp2Entity.class, EntityDataSerializers.INT);
@ -113,6 +114,7 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit
@Override
protected void defineSynchedData() {
super.defineSynchedData();
this.entityData.define(CANNON_FIRE_TIME, 0);
this.entityData.define(LOADED_MISSILE, 0);
this.entityData.define(MISSILE_COUNT, 0);
}
@ -311,6 +313,9 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit
}
}
this.entityData.set(CANNON_RECOIL_TIME, 40);
this.entityData.set(YAW, getTurretYRot());
this.entityData.set(HEAT, this.entityData.get(HEAT) + 7);
this.entityData.set(FIRE_ANIM, 3);

View file

@ -272,6 +272,9 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt
}
}
this.entityData.set(CANNON_RECOIL_TIME, 40);
this.entityData.set(YAW, getTurretYRot());
this.entityData.set(HEAT, this.entityData.get(HEAT) + 7);
this.entityData.set(FIRE_ANIM, 3);

View file

@ -230,6 +230,9 @@ public class SpeedboatEntity extends ContainerMobileVehicleEntity implements Geo
}
}
this.entityData.set(CANNON_RECOIL_TIME, 30);
this.entityData.set(YAW, getTurretYRot());
this.entityData.set(HEAT, this.entityData.get(HEAT) + 4);
this.entityData.set(FIRE_ANIM, 3);

View file

@ -66,7 +66,6 @@ import java.util.Comparator;
import static com.atsuishio.superbwarfare.tools.ParticleTool.sendParticle;
public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEntity, LandArmorEntity, WeaponVehicleEntity {
public static final EntityDataAccessor<Integer> CANNON_FIRE_TIME = SynchedEntityData.defineId(Yx100Entity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Integer> MG_AMMO = SynchedEntityData.defineId(Yx100Entity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Integer> LOADED_AMMO = SynchedEntityData.defineId(Yx100Entity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Integer> GUN_FIRE_TIME = SynchedEntityData.defineId(Yx100Entity.class, EntityDataSerializers.INT);
@ -141,7 +140,6 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
super.defineSynchedData();
this.entityData.define(MG_AMMO, 0);
this.entityData.define(LOADED_AMMO, 0);
this.entityData.define(CANNON_FIRE_TIME, 0);
this.entityData.define(GUN_FIRE_TIME, 0);
}
@ -213,10 +211,6 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
setRightTrack(0);
}
if (this.entityData.get(CANNON_FIRE_TIME) > 0) {
this.entityData.set(CANNON_FIRE_TIME, this.entityData.get(CANNON_FIRE_TIME) - 1);
}
if (this.entityData.get(GUN_FIRE_TIME) > 0) {
this.entityData.set(GUN_FIRE_TIME, this.entityData.get(GUN_FIRE_TIME) - 1);
}
@ -254,8 +248,6 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
collideHardBlock();
}
this.setRecoilShake(Math.pow(entityData.get(CANNON_FIRE_TIME), 4) * 0.0000007 * Math.sin(0.2 * Math.PI * (entityData.get(CANNON_FIRE_TIME) - 2.5)));
turretAngle(5, 5);
gunnerAngle(15, 15);
lowHealthWarning();
@ -330,7 +322,7 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
}
}
this.entityData.set(CANNON_FIRE_TIME, 40);
this.entityData.set(CANNON_RECOIL_TIME, 40);
this.entityData.set(LOADED_AMMO, 0);
this.consumeEnergy(10000);
this.entityData.set(YAW, getTurretYRot());
@ -646,7 +638,7 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
}
private PlayState cannonShootPredicate(AnimationState<Yx100Entity> event) {
if (this.entityData.get(CANNON_FIRE_TIME) > 0) {
if (this.entityData.get(CANNON_RECOIL_TIME) > 0) {
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.yx100.fire"));
}
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.yx100.idle"));

View file

@ -37,6 +37,8 @@ import org.joml.Math;
import org.joml.Vector3f;
public abstract class MobileVehicleEntity extends EnergyVehicleEntity {
public static final EntityDataAccessor<Integer> CANNON_RECOIL_TIME = SynchedEntityData.defineId(MobileVehicleEntity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Float> POWER = SynchedEntityData.defineId(MobileVehicleEntity.class, EntityDataSerializers.FLOAT);
public static final EntityDataAccessor<Float> YAW = SynchedEntityData.defineId(MobileVehicleEntity.class, EntityDataSerializers.FLOAT);
@ -167,6 +169,12 @@ public abstract class MobileVehicleEntity extends EnergyVehicleEntity {
this.level().playSound(null, this.getOnPos(), ModSounds.MINIGUN_OVERHEAT.get(), SoundSource.PLAYERS, 1, 1);
}
if (this.entityData.get(CANNON_RECOIL_TIME) > 0) {
this.entityData.set(CANNON_RECOIL_TIME, this.entityData.get(CANNON_RECOIL_TIME) - 1);
}
this.setRecoilShake(java.lang.Math.pow(entityData.get(CANNON_RECOIL_TIME), 4) * 0.0000007 * java.lang.Math.sin(0.2 * java.lang.Math.PI * (entityData.get(CANNON_RECOIL_TIME) - 2.5)));
preventStacking();
crushEntities(this.getDeltaMovement());
if (!(this instanceof DroneEntity)) {
@ -448,6 +456,7 @@ public abstract class MobileVehicleEntity extends EnergyVehicleEntity {
@Override
protected void defineSynchedData() {
super.defineSynchedData();
this.entityData.define(CANNON_RECOIL_TIME, 0);
this.entityData.define(POWER, 0f);
this.entityData.define(YAW, 0f);
this.entityData.define(AMMO, 0);

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff