添加起落架功能
This commit is contained in:
parent
876b9ef7b6
commit
a0f250ba03
3 changed files with 103 additions and 14 deletions
|
@ -15,6 +15,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.GEAR_ROT;
|
||||
|
||||
public class A10Renderer extends GeoEntityRenderer<A10Entity> {
|
||||
|
||||
public A10Renderer(EntityRendererProvider.Context renderManager) {
|
||||
|
@ -64,6 +66,9 @@ public class A10Renderer extends GeoEntityRenderer<A10Entity> {
|
|||
if (name.equals("weiyiL") || name.equals("weiyiR")) {
|
||||
bone.setRotY(Mth.clamp(Mth.lerp(partialTick, animatable.flap3RotO, animatable.getFlap3Rot()), -20f, 20f) * Mth.DEG_TO_RAD);
|
||||
}
|
||||
if (name.equals("gear") || name.equals("gear2") || name.equals("gear3")) {
|
||||
bone.setRotX(Mth.lerp(partialTick, animatable.gearRotO, animatable.getEntityData().get(GEAR_ROT)) * Mth.DEG_TO_RAD);
|
||||
}
|
||||
super.renderRecursively(poseStack, animatable, bone, renderType, bufferSource, buffer, isReRender, partialTick, packedLight, packedOverlay, color);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,10 +13,12 @@ import com.atsuishio.superbwarfare.init.ModDamageTypes;
|
|||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.tools.CustomExplosion;
|
||||
import com.atsuishio.superbwarfare.tools.EntityFindUtil;
|
||||
import com.atsuishio.superbwarfare.tools.FormatTool;
|
||||
import com.atsuishio.superbwarfare.tools.ParticleTool;
|
||||
import com.mojang.math.Axis;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.syncher.SynchedEntityData;
|
||||
|
@ -27,10 +29,12 @@ import net.minecraft.util.Mth;
|
|||
import net.minecraft.world.damagesource.DamageTypes;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.MoverType;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.Explosion;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.neoforged.neoforge.event.EventHooks;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.joml.Math;
|
||||
|
@ -44,6 +48,8 @@ import software.bernie.geckolib.util.GeckoLibUtil;
|
|||
public class A10Entity extends MobileVehicleEntity implements GeoEntity {
|
||||
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
|
||||
private float yRotSync;
|
||||
private boolean fly;
|
||||
private int flyTime;
|
||||
|
||||
|
||||
public A10Entity(EntityType<A10Entity> type, Level world) {
|
||||
|
@ -174,7 +180,7 @@ public class A10Entity extends MobileVehicleEntity implements GeoEntity {
|
|||
}
|
||||
|
||||
if (backInputDown) {
|
||||
this.entityData.set(POWER, Math.max(this.entityData.get(POWER) - 0.002f, onGround() ? -0.2f : 0.01f));
|
||||
this.entityData.set(POWER, Math.max(this.entityData.get(POWER) - 0.002f, onGround() ? -0.04f : 0.01f));
|
||||
}
|
||||
|
||||
if (!onGround()) {
|
||||
|
@ -187,10 +193,7 @@ public class A10Entity extends MobileVehicleEntity implements GeoEntity {
|
|||
// 刹车
|
||||
if (upInputDown) {
|
||||
this.entityData.set(POWER, this.entityData.get(POWER) * 0.8f);
|
||||
this.setDeltaMovement(this.getDeltaMovement().multiply(0.9, 1, 0.9));
|
||||
}
|
||||
if (!(backInputDown || forwardInputDown)) {
|
||||
this.setDeltaMovement(this.getDeltaMovement().multiply(0.97, 1, 0.97));
|
||||
this.setDeltaMovement(this.getDeltaMovement().multiply(0.91, 1, 0.91));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -218,6 +221,28 @@ public class A10Entity extends MobileVehicleEntity implements GeoEntity {
|
|||
|
||||
setFlap3Rot(diffY * 0.7f);
|
||||
|
||||
if (!onGround() && getDeltaMovement().dot(getViewVector(1)) * 72 > 150) {
|
||||
flyTime = Math.min(flyTime + 1, 20);
|
||||
}
|
||||
|
||||
if (getDeltaMovement().dot(getViewVector(1)) * 72 < 150 && fly) {
|
||||
flyTime = Math.max(flyTime - 1, 0);
|
||||
}
|
||||
|
||||
if (!fly && flyTime == 20) {
|
||||
fly = true;
|
||||
}
|
||||
|
||||
if (fly && flyTime == 0) {
|
||||
fly = false;
|
||||
}
|
||||
|
||||
if (fly) {
|
||||
entityData.set(GEAR_ROT, Math.min(entityData.get(GEAR_ROT) + 5, 85));
|
||||
} else {
|
||||
entityData.set(GEAR_ROT, Math.max(entityData.get(GEAR_ROT) - 5, 0));
|
||||
}
|
||||
|
||||
player.displayClientMessage(Component.literal("speed: " + FormatTool.format2D(getDeltaMovement().dot(getViewVector(1)) * 72)), true);
|
||||
}
|
||||
|
||||
|
@ -228,7 +253,60 @@ public class A10Entity extends MobileVehicleEntity implements GeoEntity {
|
|||
|
||||
double flapAngle = (getFlap1LRot() + getFlap1RRot()) / 2;
|
||||
|
||||
setDeltaMovement(getDeltaMovement().add(0.0f, Mth.clamp(Math.sin((onGround() ? 25 + flapAngle : -(getXRot() - 25) + flapAngle) * Mth.DEG_TO_RAD) * Math.sin((90 - this.getXRot()) * Mth.DEG_TO_RAD) * getDeltaMovement().dot(getViewVector(1)) * 0.06, -0.04, 0.065), 0.0f));
|
||||
setDeltaMovement(getDeltaMovement().add(0.0f, Mth.clamp(Math.sin((onGround() ? 17 + flapAngle : -(getXRot() - 17) + flapAngle) * Mth.DEG_TO_RAD) * Math.sin((90 - this.getXRot()) * Mth.DEG_TO_RAD) * getDeltaMovement().dot(getViewVector(1)) * 0.06, -0.04, 0.065), 0.0f));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void move(@NotNull MoverType movementType, @NotNull Vec3 movement) {
|
||||
if (!this.level().isClientSide()) {
|
||||
MobileVehicleEntity.IGNORE_ENTITY_GROUND_CHECK_STEPPING = true;
|
||||
}
|
||||
if (level() instanceof ServerLevel && canCollideBlockBeastly()) {
|
||||
collideBlockBeastly();
|
||||
}
|
||||
|
||||
super.move(movementType, movement);
|
||||
if (level() instanceof ServerLevel) {
|
||||
if (this.horizontalCollision) {
|
||||
collideBlock();
|
||||
if (canCollideHardBlock()) {
|
||||
collideHardBlock();
|
||||
}
|
||||
}
|
||||
|
||||
if (lastTickSpeed < 0.3 || collisionCoolDown > 0) return;
|
||||
Entity driver = EntityFindUtil.findEntity(this.level(), this.entityData.get(LAST_DRIVER_UUID));
|
||||
|
||||
if ((verticalCollision)) {
|
||||
if (entityData.get(GEAR_ROT) > 10 || (Mth.abs(getRoll()) > 20)) {
|
||||
this.hurt(ModDamageTypes.causeVehicleStrikeDamage(this.level().registryAccess(), this, driver == null ? this : driver), (float) ((8 + Mth.abs(getRoll() * 0.2f)) * (lastTickSpeed - 0.3) * (lastTickSpeed - 0.3)));
|
||||
if (!this.level().isClientSide) {
|
||||
this.level().playSound(null, this, ModSounds.VEHICLE_STRIKE.get(), this.getSoundSource(), 1, 1);
|
||||
}
|
||||
this.bounceVertical(Direction.getNearest(this.getDeltaMovement().x(), this.getDeltaMovement().y(), this.getDeltaMovement().z()).getOpposite());
|
||||
} else {
|
||||
if (Mth.abs((float) lastTickVerticalSpeed) > 0.4) {
|
||||
this.hurt(ModDamageTypes.causeVehicleStrikeDamage(this.level().registryAccess(), this, driver == null ? this : driver), (float) (96 * ((Mth.abs((float) lastTickVerticalSpeed) - 0.4) * (lastTickSpeed - 0.3) * (lastTickSpeed - 0.3))));
|
||||
if (!this.level().isClientSide) {
|
||||
this.level().playSound(null, this, ModSounds.VEHICLE_STRIKE.get(), this.getSoundSource(), 1, 1);
|
||||
}
|
||||
this.bounceVertical(Direction.getNearest(this.getDeltaMovement().x(), this.getDeltaMovement().y(), this.getDeltaMovement().z()).getOpposite());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (this.horizontalCollision) {
|
||||
this.hurt(ModDamageTypes.causeVehicleStrikeDamage(this.level().registryAccess(), this, driver == null ? this : driver), (float) (126 * ((lastTickSpeed - 0.4) * (lastTickSpeed - 0.4))));
|
||||
this.bounceHorizontal(Direction.getNearest(this.getDeltaMovement().x(), this.getDeltaMovement().y(), this.getDeltaMovement().z()).getOpposite());
|
||||
if (!this.level().isClientSide) {
|
||||
this.level().playSound(null, this, ModSounds.VEHICLE_STRIKE.get(), this.getSoundSource(), 1, 1);
|
||||
}
|
||||
collisionCoolDown = 4;
|
||||
crash = true;
|
||||
this.entityData.set(POWER, 0.8f * entityData.get(POWER));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -50,7 +50,6 @@ import java.util.List;
|
|||
import java.util.stream.StreamSupport;
|
||||
|
||||
public abstract class MobileVehicleEntity extends EnergyVehicleEntity implements ControllableVehicle {
|
||||
|
||||
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);
|
||||
|
@ -61,6 +60,7 @@ public abstract class MobileVehicleEntity extends EnergyVehicleEntity implements
|
|||
|
||||
public static final EntityDataAccessor<Integer> AMMO = SynchedEntityData.defineId(MobileVehicleEntity.class, EntityDataSerializers.INT);
|
||||
public static final EntityDataAccessor<Integer> DECOY_COUNT = SynchedEntityData.defineId(MobileVehicleEntity.class, EntityDataSerializers.INT);
|
||||
public static final EntityDataAccessor<Integer> GEAR_ROT = SynchedEntityData.defineId(MobileVehicleEntity.class, EntityDataSerializers.INT);
|
||||
|
||||
public int decoyReloadCoolDown;
|
||||
public static boolean IGNORE_ENTITY_GROUND_CHECK_STEPPING = false;
|
||||
|
@ -114,6 +114,8 @@ public abstract class MobileVehicleEntity extends EnergyVehicleEntity implements
|
|||
public float flap2RRotO;
|
||||
public float flap3Rot;
|
||||
public float flap3RotO;
|
||||
public float gearRot;
|
||||
public float gearRotO;
|
||||
|
||||
public MobileVehicleEntity(EntityType<?> pEntityType, Level pLevel) {
|
||||
super(pEntityType, pLevel);
|
||||
|
@ -186,6 +188,7 @@ public abstract class MobileVehicleEntity extends EnergyVehicleEntity implements
|
|||
flap2LRotO = this.getFlap2LRot();
|
||||
flap2RRotO = this.getFlap2RRot();
|
||||
flap3RotO = this.getFlap3Rot();
|
||||
gearRotO = entityData.get(GEAR_ROT);
|
||||
|
||||
super.baseTick();
|
||||
|
||||
|
@ -533,7 +536,7 @@ public abstract class MobileVehicleEntity extends EnergyVehicleEntity implements
|
|||
|
||||
if ((verticalCollision)) {
|
||||
if (this instanceof HelicopterEntity) {
|
||||
this.hurt(ModDamageTypes.causeVehicleStrikeDamage(this.level().registryAccess(), this, driver == null ? this : driver), (float) (20 * ((lastTickSpeed - 0.3) * (lastTickSpeed - 0.3))));
|
||||
this.hurt(ModDamageTypes.causeVehicleStrikeDamage(this.level().registryAccess(), this, driver == null ? this : driver), (float) (60 * ((lastTickSpeed - 0.3) * (lastTickSpeed - 0.3))));
|
||||
this.bounceVertical(Direction.getNearest(this.getDeltaMovement().x(), this.getDeltaMovement().y(), this.getDeltaMovement().z()).getOpposite());
|
||||
} else if (Mth.abs((float) lastTickVerticalSpeed) > 0.4) {
|
||||
this.hurt(ModDamageTypes.causeVehicleStrikeDamage(this.level().registryAccess(), this, driver == null ? this : driver), (float) (96 * ((Mth.abs((float) lastTickVerticalSpeed) - 0.4) * (lastTickSpeed - 0.3) * (lastTickSpeed - 0.3))));
|
||||
|
@ -552,7 +555,7 @@ public abstract class MobileVehicleEntity extends EnergyVehicleEntity implements
|
|||
}
|
||||
collisionCoolDown = 4;
|
||||
crash = true;
|
||||
this.entityData.set(POWER, 0.4f * entityData.get(POWER));
|
||||
this.entityData.set(POWER, 0.8f * entityData.get(POWER));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -816,7 +819,8 @@ public abstract class MobileVehicleEntity extends EnergyVehicleEntity implements
|
|||
.define(AMMO, 0)
|
||||
.define(FIRE_ANIM, 0)
|
||||
.define(COAX_HEAT, 0)
|
||||
.define(DECOY_COUNT, 0);
|
||||
.define(DECOY_COUNT, 0)
|
||||
.define(GEAR_ROT, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -824,6 +828,7 @@ public abstract class MobileVehicleEntity extends EnergyVehicleEntity implements
|
|||
super.readAdditionalSaveData(compound);
|
||||
this.entityData.set(POWER, compound.getFloat("Power"));
|
||||
this.entityData.set(DECOY_COUNT, compound.getInt("DecoyCount"));
|
||||
this.entityData.set(GEAR_ROT, compound.getInt("GearRot"));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -831,6 +836,7 @@ public abstract class MobileVehicleEntity extends EnergyVehicleEntity implements
|
|||
super.addAdditionalSaveData(compound);
|
||||
compound.putFloat("Power", this.entityData.get(POWER));
|
||||
compound.putInt("DecoyCount", this.entityData.get(DECOY_COUNT));
|
||||
compound.putInt("GearRot", this.entityData.get(GEAR_ROT));
|
||||
}
|
||||
|
||||
public boolean canCrushEntities() {
|
||||
|
|
Loading…
Add table
Reference in a new issue