添加推行载具和轮椅吸附实体功能
This commit is contained in:
parent
74d953a8ec
commit
22a2d6aebc
4 changed files with 94 additions and 34 deletions
|
@ -4,10 +4,15 @@ import com.atsuishio.superbwarfare.entity.projectile.ProjectileEntity;
|
||||||
import com.atsuishio.superbwarfare.init.ModDamageTypes;
|
import com.atsuishio.superbwarfare.init.ModDamageTypes;
|
||||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import net.minecraft.network.syncher.EntityDataAccessor;
|
||||||
|
import net.minecraft.network.syncher.EntityDataSerializers;
|
||||||
|
import net.minecraft.network.syncher.SynchedEntityData;
|
||||||
|
import net.minecraft.sounds.SoundEvent;
|
||||||
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.MoverType;
|
import net.minecraft.world.entity.MoverType;
|
||||||
import net.minecraft.world.entity.item.ItemEntity;
|
import net.minecraft.world.entity.item.ItemEntity;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.entity.projectile.Projectile;
|
import net.minecraft.world.entity.projectile.Projectile;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.entity.EntityTypeTest;
|
import net.minecraft.world.level.entity.EntityTypeTest;
|
||||||
|
@ -15,7 +20,7 @@ import net.minecraft.world.phys.Vec3;
|
||||||
import org.joml.Math;
|
import org.joml.Math;
|
||||||
|
|
||||||
public class MobileVehicleEntity extends EnergyVehicleEntity {
|
public class MobileVehicleEntity extends EnergyVehicleEntity {
|
||||||
public float power;
|
public static final EntityDataAccessor<Float> POWER = SynchedEntityData.defineId(MobileVehicleEntity.class, EntityDataSerializers.FLOAT);
|
||||||
public boolean leftInputDown;
|
public boolean leftInputDown;
|
||||||
public boolean rightInputDown;
|
public boolean rightInputDown;
|
||||||
public boolean forwardInputDown;
|
public boolean forwardInputDown;
|
||||||
|
@ -28,11 +33,22 @@ public class MobileVehicleEntity extends EnergyVehicleEntity {
|
||||||
super(pEntityType, pLevel);
|
super(pEntityType, pLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void playerTouch(Player pPlayer) {
|
||||||
|
if (pPlayer.isCrouching() && !this.level().isClientSide) {
|
||||||
|
double entitySize = pPlayer.getBbWidth() * pPlayer.getBbHeight();
|
||||||
|
double thisSize = this.getBbWidth() * this.getBbHeight();
|
||||||
|
double f = Math.min(entitySize / thisSize, 2);
|
||||||
|
double f1 = Math.min(thisSize / entitySize, 4);
|
||||||
|
this.setDeltaMovement(this.getDeltaMovement().add(new Vec3(pPlayer.position().vectorTo(this.position()).toVector3f()).scale(0.15 * f * pPlayer.getDeltaMovement().length())));
|
||||||
|
pPlayer.setDeltaMovement(pPlayer.getDeltaMovement().add(new Vec3(this.position().vectorTo(pPlayer.position()).toVector3f()).scale(0.1 * f1 * pPlayer.getDeltaMovement().length())));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void baseTick() {
|
public void baseTick() {
|
||||||
super.baseTick();
|
super.baseTick();
|
||||||
crushEntities(this.getDeltaMovement());
|
crushEntities(this.getDeltaMovement());
|
||||||
|
|
||||||
this.move(MoverType.SELF, this.getDeltaMovement());
|
this.move(MoverType.SELF, this.getDeltaMovement());
|
||||||
this.refreshDimensions();
|
this.refreshDimensions();
|
||||||
}
|
}
|
||||||
|
@ -42,8 +58,9 @@ public class MobileVehicleEntity extends EnergyVehicleEntity {
|
||||||
* @param velocity 动量
|
* @param velocity 动量
|
||||||
*/
|
*/
|
||||||
public void crushEntities(Vec3 velocity) {
|
public void crushEntities(Vec3 velocity) {
|
||||||
|
if (velocity.horizontalDistance() < 0.1) return;
|
||||||
var frontBox = getBoundingBox().move(velocity.scale(0.5));
|
var frontBox = getBoundingBox().move(velocity.scale(0.5));
|
||||||
var velAdd = velocity.add(0, 0, 0).scale(1.3);
|
var velAdd = velocity.add(0, 0, 0).scale(0.9);
|
||||||
for (var entity : level().getEntities(EntityTypeTest.forClass(Entity.class), frontBox, entity -> entity != this && entity != getFirstPassenger() && entity.getVehicle() == null)) {
|
for (var entity : level().getEntities(EntityTypeTest.forClass(Entity.class), frontBox, entity -> entity != this && entity != getFirstPassenger() && entity.getVehicle() == null)) {
|
||||||
|
|
||||||
double entitySize = entity.getBbWidth() * entity.getBbHeight();
|
double entitySize = entity.getBbWidth() * entity.getBbHeight();
|
||||||
|
@ -51,8 +68,8 @@ public class MobileVehicleEntity extends EnergyVehicleEntity {
|
||||||
double f = Math.min(entitySize / thisSize, 2);
|
double f = Math.min(entitySize / thisSize, 2);
|
||||||
double f1 = Math.min(thisSize / entitySize, 4);
|
double f1 = Math.min(thisSize / entitySize, 4);
|
||||||
|
|
||||||
if (entity.isAlive() && entity.getVehicle() == null && !(entity instanceof ItemEntity || entity instanceof Projectile || entity instanceof ProjectileEntity)) {
|
if (entity.isAlive() && !(entity instanceof ItemEntity || entity instanceof Projectile || entity instanceof ProjectileEntity)) {
|
||||||
if (velocity.horizontalDistance() > 0.5) {
|
if (velocity.horizontalDistance() > 0.4) {
|
||||||
if (!this.level().isClientSide) {
|
if (!this.level().isClientSide) {
|
||||||
this.level().playSound(null, this, ModSounds.VEHICLE_STRIKE.get(), this.getSoundSource(), 1, 1);
|
this.level().playSound(null, this, ModSounds.VEHICLE_STRIKE.get(), this.getSoundSource(), 1, 1);
|
||||||
}
|
}
|
||||||
|
@ -60,7 +77,7 @@ public class MobileVehicleEntity extends EnergyVehicleEntity {
|
||||||
this.push(-f * velAdd.x, -f * velAdd.y, -f * velAdd.z);
|
this.push(-f * velAdd.x, -f * velAdd.y, -f * velAdd.z);
|
||||||
}
|
}
|
||||||
entity.push(f1 * velAdd.x, f1 * velAdd.y, f1 * velAdd.z);
|
entity.push(f1 * velAdd.x, f1 * velAdd.y, f1 * velAdd.z);
|
||||||
entity.hurt(ModDamageTypes.causeVehicleStrikeDamage(this.level().registryAccess(), this, this.getFirstPassenger() == null ? this : this.getFirstPassenger()), (float) (thisSize * 60 * (velocity.horizontalDistance() - 0.5)));
|
entity.hurt(ModDamageTypes.causeVehicleStrikeDamage(this.level().registryAccess(), this, this.getFirstPassenger() == null ? this : this.getFirstPassenger()), (float) (thisSize * 40 * (velocity.horizontalDistance() - 0.4)));
|
||||||
} else {
|
} else {
|
||||||
entity.push(0.2 * f1 * velAdd.x, 0.2 * f1 * velAdd.y, 0.2 * f1 * velAdd.z);
|
entity.push(0.2 * f1 * velAdd.x, 0.2 * f1 * velAdd.y, 0.2 * f1 * velAdd.z);
|
||||||
}
|
}
|
||||||
|
@ -68,9 +85,14 @@ public class MobileVehicleEntity extends EnergyVehicleEntity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SoundEvent getEngineSound() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void defineSynchedData() {
|
protected void defineSynchedData() {
|
||||||
super.defineSynchedData();
|
super.defineSynchedData();
|
||||||
|
this.entityData.define(POWER, 0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -80,7 +80,6 @@ import java.util.List;
|
||||||
import static com.atsuishio.superbwarfare.tools.ParticleTool.sendParticle;
|
import static com.atsuishio.superbwarfare.tools.ParticleTool.sendParticle;
|
||||||
|
|
||||||
public class SpeedboatEntity extends MobileVehicleEntity implements GeoEntity, IChargeEntity, IVehicleEntity, HasCustomInventoryScreen, ContainerEntity {
|
public class SpeedboatEntity extends MobileVehicleEntity implements GeoEntity, IChargeEntity, IVehicleEntity, HasCustomInventoryScreen, ContainerEntity {
|
||||||
public static final EntityDataAccessor<Float> POWER = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.FLOAT);
|
|
||||||
public static final EntityDataAccessor<Integer> FIRE_ANIM = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.INT);
|
public static final EntityDataAccessor<Integer> FIRE_ANIM = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.INT);
|
||||||
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<Integer> HEAT = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.INT);
|
public static final EntityDataAccessor<Integer> HEAT = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.INT);
|
||||||
|
@ -116,7 +115,6 @@ public class SpeedboatEntity extends MobileVehicleEntity implements GeoEntity, I
|
||||||
@Override
|
@Override
|
||||||
protected void defineSynchedData() {
|
protected void defineSynchedData() {
|
||||||
super.defineSynchedData();
|
super.defineSynchedData();
|
||||||
this.entityData.define(POWER, 0f);
|
|
||||||
this.entityData.define(AMMO, 0);
|
this.entityData.define(AMMO, 0);
|
||||||
this.entityData.define(FIRE_ANIM, 0);
|
this.entityData.define(FIRE_ANIM, 0);
|
||||||
this.entityData.define(DELTA_ROT, 0f);
|
this.entityData.define(DELTA_ROT, 0f);
|
||||||
|
@ -237,7 +235,7 @@ public class SpeedboatEntity extends MobileVehicleEntity implements GeoEntity, I
|
||||||
if (this.level() instanceof ServerLevel serverLevel && this.isInWater() && this.getDeltaMovement().length() > 0.1) {
|
if (this.level() instanceof ServerLevel serverLevel && this.isInWater() && this.getDeltaMovement().length() > 0.1) {
|
||||||
sendParticle(serverLevel, ParticleTypes.CLOUD, this.getX() + 0.5 * this.getDeltaMovement().x, this.getY() + getSubmergedHeight(this) - 0.2, this.getZ() + 0.5 * this.getDeltaMovement().z, (int)(2 + 4 * this.getDeltaMovement().length()), 0.65, 0, 0.65, 0, true);
|
sendParticle(serverLevel, ParticleTypes.CLOUD, this.getX() + 0.5 * this.getDeltaMovement().x, this.getY() + getSubmergedHeight(this) - 0.2, this.getZ() + 0.5 * this.getDeltaMovement().z, (int)(2 + 4 * this.getDeltaMovement().length()), 0.65, 0, 0.65, 0, true);
|
||||||
sendParticle(serverLevel, ParticleTypes.BUBBLE_COLUMN_UP, this.getX() + 0.5 * this.getDeltaMovement().x, this.getY() + getSubmergedHeight(this) - 0.2, this.getZ() + 0.5 * this.getDeltaMovement().z, (int)(2 + 10 * this.getDeltaMovement().length()), 0.65, 0, 0.65, 0, true);
|
sendParticle(serverLevel, ParticleTypes.BUBBLE_COLUMN_UP, this.getX() + 0.5 * this.getDeltaMovement().x, this.getY() + getSubmergedHeight(this) - 0.2, this.getZ() + 0.5 * this.getDeltaMovement().z, (int)(2 + 10 * this.getDeltaMovement().length()), 0.65, 0, 0.65, 0, true);
|
||||||
sendParticle(serverLevel, ParticleTypes.BUBBLE_COLUMN_UP, this.getX() - 4.5 * this.getLookAngle().x, this.getY() - 0.25, this.getZ() - 4.5 * this.getLookAngle().z, (int)(40 * Mth.abs(power)), 0.15, 0.15, 0.15, 0.02, true);
|
sendParticle(serverLevel, ParticleTypes.BUBBLE_COLUMN_UP, this.getX() - 4.5 * this.getLookAngle().x, this.getY() - 0.25, this.getZ() - 4.5 * this.getLookAngle().z, (int)(40 * Mth.abs(this.entityData.get(POWER))), 0.15, 0.15, 0.15, 0.02, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
collideBlock();
|
collideBlock();
|
||||||
|
@ -444,8 +442,8 @@ public class SpeedboatEntity extends MobileVehicleEntity implements GeoEntity, I
|
||||||
public void setRudderRot(float pRudderRot) {
|
public void setRudderRot(float pRudderRot) {
|
||||||
this.rudderRot = pRudderRot;
|
this.rudderRot = pRudderRot;
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
protected SoundEvent getEngineSound() {
|
public SoundEvent getEngineSound() {
|
||||||
return ModSounds.BOAT_ENGINE.get();
|
return ModSounds.BOAT_ENGINE.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -80,6 +80,11 @@ public class VehicleEntity extends Entity {
|
||||||
player.setXRot(this.getXRot());
|
player.setXRot(this.getXRot());
|
||||||
player.setYRot(this.getYRot());
|
player.setYRot(this.getYRot());
|
||||||
return player.startRiding(this) ? InteractionResult.CONSUME : InteractionResult.PASS;
|
return player.startRiding(this) ? InteractionResult.CONSUME : InteractionResult.PASS;
|
||||||
|
} else if (!(this.getFirstPassenger() instanceof Player)) {
|
||||||
|
this.getFirstPassenger().stopRiding();
|
||||||
|
player.setXRot(this.getXRot());
|
||||||
|
player.setYRot(this.getYRot());
|
||||||
|
return player.startRiding(this) ? InteractionResult.CONSUME : InteractionResult.PASS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (!this.level().isClientSide) {
|
} else if (!this.level().isClientSide) {
|
||||||
|
@ -87,6 +92,11 @@ public class VehicleEntity extends Entity {
|
||||||
player.setXRot(this.getXRot());
|
player.setXRot(this.getXRot());
|
||||||
player.setYRot(this.getYRot());
|
player.setYRot(this.getYRot());
|
||||||
return player.startRiding(this) ? InteractionResult.CONSUME : InteractionResult.PASS;
|
return player.startRiding(this) ? InteractionResult.CONSUME : InteractionResult.PASS;
|
||||||
|
} else if (!(this.getFirstPassenger() instanceof Player)) {
|
||||||
|
this.getFirstPassenger().stopRiding();
|
||||||
|
player.setXRot(this.getXRot());
|
||||||
|
player.setYRot(this.getYRot());
|
||||||
|
return player.startRiding(this) ? InteractionResult.CONSUME : InteractionResult.PASS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return InteractionResult.PASS;
|
return InteractionResult.PASS;
|
||||||
|
|
|
@ -13,17 +13,17 @@ import net.minecraft.network.protocol.Packet;
|
||||||
import net.minecraft.network.protocol.game.ClientGamePacketListener;
|
import net.minecraft.network.protocol.game.ClientGamePacketListener;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
import net.minecraft.sounds.SoundEvent;
|
||||||
import net.minecraft.sounds.SoundEvents;
|
import net.minecraft.sounds.SoundEvents;
|
||||||
import net.minecraft.sounds.SoundSource;
|
import net.minecraft.sounds.SoundSource;
|
||||||
import net.minecraft.util.Mth;
|
import net.minecraft.util.Mth;
|
||||||
import net.minecraft.world.damagesource.DamageSource;
|
import net.minecraft.world.damagesource.DamageSource;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.*;
|
||||||
import net.minecraft.world.entity.EntityDimensions;
|
import net.minecraft.world.entity.animal.WaterAnimal;
|
||||||
import net.minecraft.world.entity.EntityType;
|
|
||||||
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.Explosion;
|
import net.minecraft.world.level.Explosion;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
|
import net.minecraft.world.phys.Vec3;
|
||||||
import net.minecraftforge.network.NetworkHooks;
|
import net.minecraftforge.network.NetworkHooks;
|
||||||
import net.minecraftforge.network.PlayMessages;
|
import net.minecraftforge.network.PlayMessages;
|
||||||
import org.joml.Math;
|
import org.joml.Math;
|
||||||
|
@ -32,6 +32,8 @@ import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache
|
||||||
import software.bernie.geckolib.core.animation.AnimatableManager;
|
import software.bernie.geckolib.core.animation.AnimatableManager;
|
||||||
import software.bernie.geckolib.util.GeckoLibUtil;
|
import software.bernie.geckolib.util.GeckoLibUtil;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class WheelChairEntity extends MobileVehicleEntity implements GeoEntity, IVehicleEntity {
|
public class WheelChairEntity extends MobileVehicleEntity implements GeoEntity, IVehicleEntity {
|
||||||
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
|
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
|
||||||
public static final float MAX_HEALTH = 50;
|
public static final float MAX_HEALTH = 50;
|
||||||
|
@ -52,6 +54,20 @@ public class WheelChairEntity extends MobileVehicleEntity implements GeoEntity,
|
||||||
this.setMaxUpStep(1.1f);
|
this.setMaxUpStep(1.1f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void playerTouch(Player pPlayer) {
|
||||||
|
if (this.position().distanceTo(pPlayer.position()) > 1.25) return;
|
||||||
|
if (!this.level().isClientSide) {
|
||||||
|
double entitySize = pPlayer.getBbWidth() * pPlayer.getBbHeight();
|
||||||
|
double thisSize = this.getBbWidth() * this.getBbHeight();
|
||||||
|
double f = Math.min(entitySize / thisSize, 2);
|
||||||
|
double f1 = Math.min(thisSize / entitySize, 4);
|
||||||
|
this.setDeltaMovement(this.getDeltaMovement().add(new Vec3(pPlayer.position().vectorTo(this.position()).toVector3f()).scale(0.3 * f * pPlayer.getDeltaMovement().length())));
|
||||||
|
this.setYRot(pPlayer.getYHeadRot());
|
||||||
|
pPlayer.setDeltaMovement(pPlayer.getDeltaMovement().add(new Vec3(this.position().vectorTo(pPlayer.position()).toVector3f()).scale(0.01 * f1 * pPlayer.getDeltaMovement().length())));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void defineSynchedData() {
|
protected void defineSynchedData() {
|
||||||
super.defineSynchedData();
|
super.defineSynchedData();
|
||||||
|
@ -77,11 +93,6 @@ public class WheelChairEntity extends MobileVehicleEntity implements GeoEntity,
|
||||||
return NetworkHooks.getEntitySpawningPacket(this);
|
return NetworkHooks.getEntitySpawningPacket(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getPassengersRidingOffset() {
|
|
||||||
return super.getPassengersRidingOffset() - 0.05;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hurt(DamageSource source, float amount) {
|
public boolean hurt(DamageSource source, float amount) {
|
||||||
super.hurt(source, amount);
|
super.hurt(source, amount);
|
||||||
|
@ -112,16 +123,28 @@ public class WheelChairEntity extends MobileVehicleEntity implements GeoEntity,
|
||||||
} else {
|
} else {
|
||||||
this.setDeltaMovement(this.getDeltaMovement().multiply(0.99, 0.95, 0.99));
|
this.setDeltaMovement(this.getDeltaMovement().multiply(0.99, 0.95, 0.99));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (level().isClientSide && this.getEnergy() > 0) {
|
|
||||||
level().playLocalSound(this.getX(), this.getY() + this.getBbHeight() * 0.5, this.getZ(), ModSounds.WHEEL_CHAIR_ENGINE.get(), this.getSoundSource(), (float) (0.2 * this.getDeltaMovement().length()), (random.nextFloat() * 0.1f + 0.7f), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.setSprinting(this.getDeltaMovement().horizontalDistance() > 0.15);
|
this.setSprinting(this.getDeltaMovement().horizontalDistance() > 0.15);
|
||||||
|
attractEntity();
|
||||||
this.refreshDimensions();
|
this.refreshDimensions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasEnoughSpaceFor(Entity pEntity) {
|
||||||
|
return pEntity.getBbWidth() < this.getBbWidth();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void attractEntity() {
|
||||||
|
List<Entity> list = this.level().getEntities(this, this.getBoundingBox().inflate(0.2F, -0.01F, 0.2F));
|
||||||
|
if (!list.isEmpty()) {
|
||||||
|
boolean flag = !this.level().isClientSide && !(this.getControllingPassenger() instanceof Player);
|
||||||
|
|
||||||
|
for (Entity entity : list) {
|
||||||
|
if (!entity.hasPassenger(this) && flag && !entity.isPassenger() && this.hasEnoughSpaceFor(entity) && (entity instanceof LivingEntity || entity instanceof MortarEntity) && !(entity instanceof WaterAnimal) && !(entity instanceof Player)) {
|
||||||
|
entity.startRiding(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void travel() {
|
public void travel() {
|
||||||
Entity passenger = this.getPassengers().isEmpty() ? null : this.getPassengers().get(0);
|
Entity passenger = this.getPassengers().isEmpty() ? null : this.getPassengers().get(0);
|
||||||
|
@ -133,20 +156,23 @@ public class WheelChairEntity extends MobileVehicleEntity implements GeoEntity,
|
||||||
this.rightInputDown = false;
|
this.rightInputDown = false;
|
||||||
this.forwardInputDown = false;
|
this.forwardInputDown = false;
|
||||||
this.backInputDown = false;
|
this.backInputDown = false;
|
||||||
} else {
|
} else if (passenger instanceof Player) {
|
||||||
|
if (level().isClientSide) {
|
||||||
|
level().playLocalSound(this.getX(), this.getY() + this.getBbHeight() * 0.5, this.getZ(), this.getEngineSound(), this.getSoundSource(), Math.min((this.forwardInputDown || this.backInputDown ? 7.5f : 5f) * 2 * Mth.abs(this.entityData.get(POWER)), 0.25f), (random.nextFloat() * 0.1f + 1f), false);
|
||||||
|
}
|
||||||
diffY = Math.clamp(-90f, 90f, Mth.wrapDegrees(passenger.getYHeadRot() - this.getYRot()));
|
diffY = Math.clamp(-90f, 90f, Mth.wrapDegrees(passenger.getYHeadRot() - this.getYRot()));
|
||||||
this.setYRot(this.getYRot() + Mth.clamp(0.4f * diffY, -5f, 5f));
|
this.setYRot(this.getYRot() + Mth.clamp(0.4f * diffY, -5f, 5f));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.forwardInputDown) {
|
if (this.forwardInputDown) {
|
||||||
power += 0.01f;
|
this.entityData.set(POWER, this.entityData.get(POWER) + 0.01f);
|
||||||
if (this.getEnergy() <= 0 && passenger instanceof Player player) {
|
if (this.getEnergy() <= 0 && passenger instanceof Player player) {
|
||||||
moveWithOutPower(player, true);
|
moveWithOutPower(player, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.backInputDown) {
|
if (this.backInputDown) {
|
||||||
power -= 0.01f;
|
this.entityData.set(POWER, this.entityData.get(POWER) - 0.01f);
|
||||||
if (this.getEnergy() <= 0 && passenger instanceof Player player) {
|
if (this.getEnergy() <= 0 && passenger instanceof Player player) {
|
||||||
moveWithOutPower(player, false);
|
moveWithOutPower(player, false);
|
||||||
}
|
}
|
||||||
|
@ -158,7 +184,7 @@ public class WheelChairEntity extends MobileVehicleEntity implements GeoEntity,
|
||||||
}
|
}
|
||||||
this.extraEnergy(400);
|
this.extraEnergy(400);
|
||||||
this.setDeltaMovement(this.getDeltaMovement().add(0, 0.48, 0));
|
this.setDeltaMovement(this.getDeltaMovement().add(0, 0.48, 0));
|
||||||
jumpCoolDown = 5;
|
jumpCoolDown = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.forwardInputDown || this.backInputDown) {
|
if (this.forwardInputDown || this.backInputDown) {
|
||||||
|
@ -172,7 +198,7 @@ public class WheelChairEntity extends MobileVehicleEntity implements GeoEntity,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
power *= 0.87f;
|
this.entityData.set(POWER, this.entityData.get(POWER) * 0.87f);
|
||||||
|
|
||||||
float angle = (float) calculateAngle(this.getDeltaMovement(), this.getViewVector(1));
|
float angle = (float) calculateAngle(this.getDeltaMovement(), this.getViewVector(1));
|
||||||
double s0;
|
double s0;
|
||||||
|
@ -190,12 +216,11 @@ public class WheelChairEntity extends MobileVehicleEntity implements GeoEntity,
|
||||||
// player.displayClientMessage(Component.literal("Angle:" + new java.text.DecimalFormat("##.##").format(this.getRightWheelRot())), true);
|
// player.displayClientMessage(Component.literal("Angle:" + new java.text.DecimalFormat("##.##").format(this.getRightWheelRot())), true);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
this.setDeltaMovement(this.getDeltaMovement().add(Mth.sin(-this.getYRot() * 0.017453292F) * (this.onGround() ? 1 : 0.1) * power, 0.0, Mth.cos(this.getYRot() * 0.017453292F) * (this.onGround() ? 1 : 0.1) * power));
|
this.setDeltaMovement(this.getDeltaMovement().add(Mth.sin(-this.getYRot() * 0.017453292F) * (this.onGround() ? 1 : 0.1) * this.entityData.get(POWER), 0.0, Mth.cos(this.getYRot() * 0.017453292F) * (this.onGround() ? 1 : 0.1) * this.entityData.get(POWER)));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void moveWithOutPower(Player player, boolean forward) {
|
public void moveWithOutPower(Player player, boolean forward) {
|
||||||
power += (forward ? 0.015f : -0.015f);
|
this.entityData.set(POWER, this.entityData.get(POWER) + (forward ? 0.015f : -0.015f));
|
||||||
if (player instanceof ServerPlayer serverPlayer) {
|
if (player instanceof ServerPlayer serverPlayer) {
|
||||||
serverPlayer.level().playSound(null, serverPlayer.getOnPos(), SoundEvents.BOAT_PADDLE_LAND, SoundSource.PLAYERS, 1, 1);
|
serverPlayer.level().playSound(null, serverPlayer.getOnPos(), SoundEvents.BOAT_PADDLE_LAND, SoundSource.PLAYERS, 1, 1);
|
||||||
}
|
}
|
||||||
|
@ -206,6 +231,11 @@ public class WheelChairEntity extends MobileVehicleEntity implements GeoEntity,
|
||||||
this.backInputDown = false;
|
this.backInputDown = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SoundEvent getEngineSound() {
|
||||||
|
return ModSounds.WHEEL_CHAIR_ENGINE.get();
|
||||||
|
}
|
||||||
|
|
||||||
public float getLeftWheelRot() {
|
public float getLeftWheelRot() {
|
||||||
return this.leftWheelRot;
|
return this.leftWheelRot;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue