优化迫击炮,调整炮台的移动逻辑
This commit is contained in:
parent
3049430a6a
commit
f4e1f495f1
10 changed files with 188 additions and 148 deletions
|
@ -1,5 +1,6 @@
|
||||||
package com.atsuishio.superbwarfare.client.overlay;
|
package com.atsuishio.superbwarfare.client.overlay;
|
||||||
|
|
||||||
|
import com.atsuishio.superbwarfare.client.gui.RangeHelper;
|
||||||
import com.atsuishio.superbwarfare.entity.MortarEntity;
|
import com.atsuishio.superbwarfare.entity.MortarEntity;
|
||||||
import com.atsuishio.superbwarfare.tools.FormatTool;
|
import com.atsuishio.superbwarfare.tools.FormatTool;
|
||||||
import com.atsuishio.superbwarfare.tools.TraceTool;
|
import com.atsuishio.superbwarfare.tools.TraceTool;
|
||||||
|
@ -26,12 +27,18 @@ public class MortarInfoOverlay {
|
||||||
lookingEntity = TraceTool.findLookingEntity(player, 6);
|
lookingEntity = TraceTool.findLookingEntity(player, 6);
|
||||||
}
|
}
|
||||||
if (lookingEntity instanceof MortarEntity mortar) {
|
if (lookingEntity instanceof MortarEntity mortar) {
|
||||||
event.getGuiGraphics().drawString(Minecraft.getInstance().font, Component.translatable("tips.superbwarfare.mortar.yaw")
|
|
||||||
.append(Component.literal(FormatTool.format1D(mortar.getEntityData().get(MortarEntity.Y_ROT), "°"))),
|
player.displayClientMessage(Component.translatable("tips.superbwarfare.mortar.pitch").append(FormatTool.format1D(-mortar.getXRot(), "° "))
|
||||||
w / 2 + 12, h / 2 - 36, -1, false);
|
.append(Component.translatable("tips.superbwarfare.mortar.yaw")).append(FormatTool.format1D(mortar.getYRot(), "° "))
|
||||||
event.getGuiGraphics().drawString(Minecraft.getInstance().font, Component.translatable("tips.superbwarfare.mortar.pitch")
|
.append(Component.translatable("tips.superbwarfare.mortar.range")).append(FormatTool.format1D((int) RangeHelper.getRange(-mortar.getXRot()))).append("m")
|
||||||
.append(Component.literal(FormatTool.format1D(mortar.getEntityData().get(MortarEntity.PITCH), "°"))),
|
, true);
|
||||||
w / 2 + 12, h / 2 - 28, -1, false);
|
|
||||||
|
// event.getGuiGraphics().drawString(Minecraft.getInstance().font, Component.translatable("tips.superbwarfare.mortar.yaw")
|
||||||
|
// .append(Component.literal(FormatTool.format1D(mortar.getYRot(), "°"))),
|
||||||
|
// w / 2 + 12, h / 2 - 36, -1, false);
|
||||||
|
// event.getGuiGraphics().drawString(Minecraft.getInstance().font, Component.translatable("tips.superbwarfare.mortar.pitch")
|
||||||
|
// .append(Component.literal(FormatTool.format1D(-mortar.getXRot(), "°"))),
|
||||||
|
// w / 2 + 12, h / 2 - 28, -1, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,11 +3,10 @@ package com.atsuishio.superbwarfare.entity;
|
||||||
import com.atsuishio.superbwarfare.ModUtils;
|
import com.atsuishio.superbwarfare.ModUtils;
|
||||||
import com.atsuishio.superbwarfare.client.gui.RangeHelper;
|
import com.atsuishio.superbwarfare.client.gui.RangeHelper;
|
||||||
import com.atsuishio.superbwarfare.entity.projectile.MortarShellEntity;
|
import com.atsuishio.superbwarfare.entity.projectile.MortarShellEntity;
|
||||||
|
import com.atsuishio.superbwarfare.entity.vehicle.VehicleEntity;
|
||||||
import com.atsuishio.superbwarfare.init.ModEntities;
|
import com.atsuishio.superbwarfare.init.ModEntities;
|
||||||
import com.atsuishio.superbwarfare.init.ModItems;
|
import com.atsuishio.superbwarfare.init.ModItems;
|
||||||
import com.atsuishio.superbwarfare.init.ModParticleTypes;
|
|
||||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||||
import com.atsuishio.superbwarfare.tools.ParticleTool;
|
|
||||||
import net.minecraft.ChatFormatting;
|
import net.minecraft.ChatFormatting;
|
||||||
import net.minecraft.commands.arguments.EntityAnchorArgument;
|
import net.minecraft.commands.arguments.EntityAnchorArgument;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
|
@ -25,17 +24,19 @@ import net.minecraft.util.Mth;
|
||||||
import net.minecraft.world.InteractionHand;
|
import net.minecraft.world.InteractionHand;
|
||||||
import net.minecraft.world.InteractionResult;
|
import net.minecraft.world.InteractionResult;
|
||||||
import net.minecraft.world.damagesource.DamageSource;
|
import net.minecraft.world.damagesource.DamageSource;
|
||||||
import net.minecraft.world.damagesource.DamageTypes;
|
import net.minecraft.world.entity.EntityDimensions;
|
||||||
import net.minecraft.world.entity.*;
|
import net.minecraft.world.entity.EntityType;
|
||||||
|
import net.minecraft.world.entity.MoverType;
|
||||||
|
import net.minecraft.world.entity.Pose;
|
||||||
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.player.Player;
|
||||||
import net.minecraft.world.entity.projectile.ThrownPotion;
|
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import net.minecraftforge.items.ItemHandlerHelper;
|
import net.minecraftforge.items.ItemHandlerHelper;
|
||||||
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 software.bernie.geckolib.animatable.GeoEntity;
|
import software.bernie.geckolib.animatable.GeoEntity;
|
||||||
import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache;
|
import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache;
|
||||||
import software.bernie.geckolib.core.animation.AnimatableManager;
|
import software.bernie.geckolib.core.animation.AnimatableManager;
|
||||||
|
@ -45,22 +46,16 @@ import software.bernie.geckolib.core.animation.RawAnimation;
|
||||||
import software.bernie.geckolib.core.object.PlayState;
|
import software.bernie.geckolib.core.object.PlayState;
|
||||||
import software.bernie.geckolib.util.GeckoLibUtil;
|
import software.bernie.geckolib.util.GeckoLibUtil;
|
||||||
|
|
||||||
public class MortarEntity extends Entity implements GeoEntity, AnimatedEntity {
|
public class MortarEntity extends VehicleEntity implements GeoEntity, AnimatedEntity {
|
||||||
|
|
||||||
public static final EntityDataAccessor<Integer> FIRE_TIME = SynchedEntityData.defineId(MortarEntity.class, EntityDataSerializers.INT);
|
public static final EntityDataAccessor<Integer> FIRE_TIME = SynchedEntityData.defineId(MortarEntity.class, EntityDataSerializers.INT);
|
||||||
public static final EntityDataAccessor<Float> PITCH = SynchedEntityData.defineId(MortarEntity.class, EntityDataSerializers.FLOAT);
|
public static final EntityDataAccessor<Float> PITCH = SynchedEntityData.defineId(MortarEntity.class, EntityDataSerializers.FLOAT);
|
||||||
public static final EntityDataAccessor<Float> Y_ROT = SynchedEntityData.defineId(MortarEntity.class, EntityDataSerializers.FLOAT);
|
public static final EntityDataAccessor<Float> YAW = SynchedEntityData.defineId(MortarEntity.class, EntityDataSerializers.FLOAT);
|
||||||
public static final EntityDataAccessor<Float> HEALTH = SynchedEntityData.defineId(MortarEntity.class, EntityDataSerializers.FLOAT);
|
|
||||||
|
|
||||||
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
|
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
|
||||||
|
|
||||||
protected int interpolationSteps;
|
|
||||||
protected double serverYRot;
|
|
||||||
protected double serverXRot;
|
|
||||||
|
|
||||||
public MortarEntity(PlayMessages.SpawnEntity packet, Level world) {
|
public MortarEntity(PlayMessages.SpawnEntity packet, Level world) {
|
||||||
this(ModEntities.MORTAR.get(), world);
|
this(ModEntities.MORTAR.get(), world);
|
||||||
this.noCulling = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public MortarEntity(EntityType<MortarEntity> type, Level world) {
|
public MortarEntity(EntityType<MortarEntity> type, Level world) {
|
||||||
|
@ -69,10 +64,15 @@ public class MortarEntity extends Entity implements GeoEntity, AnimatedEntity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void defineSynchedData() {
|
protected void defineSynchedData() {
|
||||||
|
super.defineSynchedData();
|
||||||
this.entityData.define(FIRE_TIME, 0);
|
this.entityData.define(FIRE_TIME, 0);
|
||||||
this.entityData.define(PITCH, 70f);
|
this.entityData.define(PITCH, -70f);
|
||||||
this.entityData.define(Y_ROT, 0f);
|
this.entityData.define(YAW, 0f);
|
||||||
this.entityData.define(HEALTH, 100f);
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canBeCollidedWith() {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -92,55 +92,27 @@ public class MortarEntity extends Entity implements GeoEntity, AnimatedEntity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hurt(DamageSource source, float amount) {
|
public boolean hurt(DamageSource source, float amount) {
|
||||||
if (source.getDirectEntity() instanceof ThrownPotion || source.getDirectEntity() instanceof AreaEffectCloud)
|
super.hurt(source, amount);
|
||||||
return false;
|
|
||||||
if (source.is(DamageTypes.FALL))
|
|
||||||
return false;
|
|
||||||
if (source.is(DamageTypes.CACTUS))
|
|
||||||
return false;
|
|
||||||
if (source.is(DamageTypes.DROWN))
|
|
||||||
return false;
|
|
||||||
if (source.is(DamageTypes.LIGHTNING_BOLT))
|
|
||||||
return false;
|
|
||||||
if (source.is(DamageTypes.FALLING_ANVIL))
|
|
||||||
return false;
|
|
||||||
if (source.is(DamageTypes.DRAGON_BREATH))
|
|
||||||
return false;
|
|
||||||
if (source.is(DamageTypes.WITHER))
|
|
||||||
return false;
|
|
||||||
if (source.is(DamageTypes.WITHER_SKULL))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (this.level() instanceof ServerLevel serverLevel) {
|
|
||||||
ParticleTool.sendParticle(serverLevel, ModParticleTypes.FIRE_STAR.get(), this.getX(), this.getY() + 1, this.getZ(), 2, 0.05, 0.05, 0.05, 0.1, false);
|
|
||||||
}
|
|
||||||
this.level().playSound(null, this.getOnPos(), ModSounds.HIT.get(), SoundSource.PLAYERS, 1, 1);
|
this.level().playSound(null, this.getOnPos(), ModSounds.HIT.get(), SoundSource.PLAYERS, 1, 1);
|
||||||
this.entityData.set(HEALTH, this.entityData.get(HEALTH) - amount);
|
this.hurt(amount, source.getEntity(), true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addAdditionalSaveData(CompoundTag compound) {
|
public void addAdditionalSaveData(CompoundTag compound) {
|
||||||
compound.putInt("FireTime", this.entityData.get(FIRE_TIME));
|
super.addAdditionalSaveData(compound);
|
||||||
compound.putFloat("Pitch", this.entityData.get(PITCH));
|
compound.putFloat("Pitch", this.entityData.get(PITCH));
|
||||||
compound.putFloat("YRot", this.entityData.get(Y_ROT));
|
compound.putFloat("Yaw", this.entityData.get(YAW));
|
||||||
compound.putFloat("Health", this.entityData.get(HEALTH));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readAdditionalSaveData(CompoundTag compound) {
|
public void readAdditionalSaveData(CompoundTag compound) {
|
||||||
if (compound.contains("FireTime")) {
|
super.readAdditionalSaveData(compound);
|
||||||
this.entityData.set(FIRE_TIME, compound.getInt("FireTime"));
|
|
||||||
}
|
|
||||||
if (compound.contains("Pitch")) {
|
if (compound.contains("Pitch")) {
|
||||||
this.entityData.set(PITCH, compound.getFloat("Pitch"));
|
this.entityData.set(PITCH, compound.getFloat("Pitch"));
|
||||||
}
|
}
|
||||||
if (compound.contains("YRot")) {
|
if (compound.contains("YRot")) {
|
||||||
this.entityData.set(Y_ROT, compound.getFloat("YRot"));
|
this.entityData.set(YAW, compound.getFloat("Yaw"));
|
||||||
}
|
|
||||||
if (compound.contains("Health")) {
|
|
||||||
this.entityData.set(HEALTH, compound.getFloat("Health"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,7 +170,7 @@ public class MortarEntity extends Entity implements GeoEntity, AnimatedEntity {
|
||||||
ItemHandlerHelper.giveItemToPlayer(player, new ItemStack(ModItems.MORTAR_DEPLOYER.get()));
|
ItemHandlerHelper.giveItemToPlayer(player, new ItemStack(ModItems.MORTAR_DEPLOYER.get()));
|
||||||
return InteractionResult.SUCCESS;
|
return InteractionResult.SUCCESS;
|
||||||
}
|
}
|
||||||
this.entityData.set(Y_ROT, Mth.clamp(player.getYRot(), -180, 180));
|
entityData.set(YAW, player.getYRot());
|
||||||
}
|
}
|
||||||
|
|
||||||
return InteractionResult.SUCCESS;
|
return InteractionResult.SUCCESS;
|
||||||
|
@ -218,7 +190,7 @@ public class MortarEntity extends Entity implements GeoEntity, AnimatedEntity {
|
||||||
angles);
|
angles);
|
||||||
|
|
||||||
if (flag) {
|
if (flag) {
|
||||||
this.entityData.set(PITCH, (float) angles[1]);
|
entityData.set(PITCH, (float) -angles[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return flag;
|
return flag;
|
||||||
|
@ -228,13 +200,12 @@ public class MortarEntity extends Entity implements GeoEntity, AnimatedEntity {
|
||||||
Vec3 vec3 = pAnchor.apply(this);
|
Vec3 vec3 = pAnchor.apply(this);
|
||||||
double d0 = (pTarget.x - vec3.x) * 0.2;
|
double d0 = (pTarget.x - vec3.x) * 0.2;
|
||||||
double d2 = (pTarget.z - vec3.z) * 0.2;
|
double d2 = (pTarget.z - vec3.z) * 0.2;
|
||||||
this.entityData.set(Y_ROT, Mth.wrapDegrees((float) (Mth.atan2(d2, d0) * 57.2957763671875) - 90.0F));
|
entityData.set(YAW, Mth.wrapDegrees((float) (Mth.atan2(d2, d0) * 57.2957763671875) - 90.0F));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void lerpTo(double x, double y, double z, float yaw, float pitch, int interpolationSteps, boolean interpolate) {
|
public Vec3 getDeltaMovement() {
|
||||||
serverXRot = pitch;
|
return new Vec3(0, Math.min(super.getDeltaMovement().y, 0), 0);
|
||||||
this.interpolationSteps = 10;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -243,36 +214,49 @@ public class MortarEntity extends Entity implements GeoEntity, AnimatedEntity {
|
||||||
if (this.entityData.get(FIRE_TIME) > 0) {
|
if (this.entityData.get(FIRE_TIME) > 0) {
|
||||||
this.entityData.set(FIRE_TIME, this.entityData.get(FIRE_TIME) - 1);
|
this.entityData.set(FIRE_TIME, this.entityData.get(FIRE_TIME) - 1);
|
||||||
}
|
}
|
||||||
this.setXRot(-Mth.clamp(entityData.get(PITCH), 20, 89));
|
|
||||||
this.xRotO = this.getXRot();
|
|
||||||
this.setYRot(entityData.get(Y_ROT));
|
|
||||||
this.setYBodyRot(this.getYRot());
|
|
||||||
this.setYHeadRot(this.getYRot());
|
|
||||||
this.yRotO = this.getYRot();
|
|
||||||
this.setRot(this.getYRot(), this.getXRot());
|
|
||||||
|
|
||||||
this.setDeltaMovement(this.getDeltaMovement().add(0.0, -0.04, 0.0));
|
|
||||||
|
|
||||||
if (!this.level().noCollision(this.getBoundingBox())) {
|
|
||||||
this.moveTowardsClosestSpace(this.getX(), (this.getBoundingBox().minY + this.getBoundingBox().maxY) / 2.0, this.getZ());
|
|
||||||
}
|
|
||||||
|
|
||||||
this.move(MoverType.SELF, this.getDeltaMovement());
|
this.move(MoverType.SELF, this.getDeltaMovement());
|
||||||
float f = 0.98F;
|
|
||||||
if (this.onGround()) {
|
if (this.onGround()) {
|
||||||
BlockPos pos = this.getBlockPosBelowThatAffectsMyMovement();
|
this.setDeltaMovement(Vec3.ZERO);
|
||||||
f = this.level().getBlockState(pos).getFriction(this.level(), pos, this) * 0.98F;
|
} else {
|
||||||
|
this.setDeltaMovement(this.getDeltaMovement().add(0.0, -0.04, 0.0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleClientSync() {
|
||||||
|
if (isControlledByLocalInstance()) {
|
||||||
|
interpolationSteps = 0;
|
||||||
|
syncPacketPositionCodec(getX(), getY(), getZ());
|
||||||
|
}
|
||||||
|
if (interpolationSteps <= 0) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setDeltaMovement(this.getDeltaMovement().multiply(f, 0.98, f));
|
double interpolatedYaw = Mth.wrapDegrees(serverYRot - (double) getYRot());
|
||||||
if (this.onGround()) {
|
setYRot(getYRot() + (float) interpolatedYaw / (float) interpolationSteps);
|
||||||
this.setDeltaMovement(this.getDeltaMovement().multiply(1.0, -0.9, 1.0));
|
setXRot(getXRot() + (float) (serverXRot - (double) getXRot()) / (float) interpolationSteps);
|
||||||
}
|
setRot(getYRot(), getXRot());
|
||||||
|
|
||||||
if (this.entityData.get(HEALTH) <= 0) {
|
}
|
||||||
destroy();
|
|
||||||
}
|
@Override
|
||||||
this.refreshDimensions();
|
public void lerpTo(double x, double y, double z, float yaw, float pitch, int interpolationSteps, boolean interpolate) {
|
||||||
|
serverYRot = yaw;
|
||||||
|
serverXRot = pitch;
|
||||||
|
this.interpolationSteps = 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void travel() {
|
||||||
|
float diffY;
|
||||||
|
float diffX;
|
||||||
|
|
||||||
|
diffY = (float) Mth.wrapDegrees(entityData.get(YAW) - this.getYRot());
|
||||||
|
diffX = (float) Mth.wrapDegrees(entityData.get(PITCH) - this.getXRot());
|
||||||
|
|
||||||
|
this.setYRot(this.getYRot() + Mth.clamp(0.5f * diffY, -20f, 20f));
|
||||||
|
this.setXRot(Mth.clamp(this.getXRot() + Mth.clamp(0.5f * diffX, -20f, 20f), -89, -20));
|
||||||
}
|
}
|
||||||
|
|
||||||
private PlayState movementPredicate(AnimationState<MortarEntity> event) {
|
private PlayState movementPredicate(AnimationState<MortarEntity> event) {
|
||||||
|
@ -282,7 +266,8 @@ public class MortarEntity extends Entity implements GeoEntity, AnimatedEntity {
|
||||||
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.mortar.idle"));
|
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.mortar.idle"));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void destroy() {
|
@Override
|
||||||
|
public void destroy() {
|
||||||
if (this.level() instanceof ServerLevel level) {
|
if (this.level() instanceof ServerLevel level) {
|
||||||
var x = this.getX();
|
var x = this.getX();
|
||||||
var y = this.getY();
|
var y = this.getY();
|
||||||
|
@ -295,6 +280,11 @@ public class MortarEntity extends Entity implements GeoEntity, AnimatedEntity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getMaxHealth() {
|
||||||
|
return 100;
|
||||||
|
}
|
||||||
|
|
||||||
public String getSyncedAnimation() {
|
public String getSyncedAnimation() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -256,8 +256,30 @@ public class AnnihilatorEntity extends EnergyVehicleEntity implements GeoEntity,
|
||||||
if (passenger instanceof ServerPlayer serverPlayer && this.entityData.get(COOL_DOWN) == 20) {
|
if (passenger instanceof ServerPlayer serverPlayer && this.entityData.get(COOL_DOWN) == 20) {
|
||||||
SoundTool.playLocalSound(serverPlayer, ModSounds.ANNIHILATOR_RELOAD.get(), 1, 1);
|
SoundTool.playLocalSound(serverPlayer, ModSounds.ANNIHILATOR_RELOAD.get(), 1, 1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.refreshDimensions();
|
@Override
|
||||||
|
public void handleClientSync() {
|
||||||
|
if (isControlledByLocalInstance()) {
|
||||||
|
interpolationSteps = 0;
|
||||||
|
syncPacketPositionCodec(getX(), getY(), getZ());
|
||||||
|
}
|
||||||
|
if (interpolationSteps <= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
double interpolatedYaw = Mth.wrapDegrees(serverYRot - (double) getYRot());
|
||||||
|
setYRot(getYRot() + (float) interpolatedYaw / (float) interpolationSteps);
|
||||||
|
setXRot(getXRot() + (float) (serverXRot - (double) getXRot()) / (float) interpolationSteps);
|
||||||
|
setRot(getYRot(), getXRot());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void lerpTo(double x, double y, double z, float yaw, float pitch, int interpolationSteps, boolean interpolate) {
|
||||||
|
serverYRot = yaw;
|
||||||
|
serverXRot = pitch;
|
||||||
|
this.interpolationSteps = 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
private float laserLength(Vec3 pos, Entity cannon) {
|
private float laserLength(Vec3 pos, Entity cannon) {
|
||||||
|
|
|
@ -249,7 +249,30 @@ public class LaserTowerEntity extends EnergyVehicleEntity implements GeoEntity,
|
||||||
this.setDeltaMovement(this.getDeltaMovement().add(0.0, -0.04, 0.0));
|
this.setDeltaMovement(this.getDeltaMovement().add(0.0, -0.04, 0.0));
|
||||||
}
|
}
|
||||||
autoAim();
|
autoAim();
|
||||||
this.refreshDimensions();
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleClientSync() {
|
||||||
|
if (isControlledByLocalInstance()) {
|
||||||
|
interpolationSteps = 0;
|
||||||
|
syncPacketPositionCodec(getX(), getY(), getZ());
|
||||||
|
}
|
||||||
|
if (interpolationSteps <= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
double interpolatedYaw = Mth.wrapDegrees(serverYRot - (double) getYRot());
|
||||||
|
setYRot(getYRot() + (float) interpolatedYaw / (float) interpolationSteps);
|
||||||
|
setXRot(getXRot() + (float) (serverXRot - (double) getXRot()) / (float) interpolationSteps);
|
||||||
|
setRot(getYRot(), getXRot());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void lerpTo(double x, double y, double z, float yaw, float pitch, int interpolationSteps, boolean interpolate) {
|
||||||
|
serverYRot = yaw;
|
||||||
|
serverXRot = pitch;
|
||||||
|
this.interpolationSteps = 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package com.atsuishio.superbwarfare.entity.vehicle;
|
package com.atsuishio.superbwarfare.entity.vehicle;
|
||||||
|
|
||||||
import com.atsuishio.superbwarfare.ModUtils;
|
import com.atsuishio.superbwarfare.ModUtils;
|
||||||
import com.atsuishio.superbwarfare.client.gui.RangeHelper;
|
|
||||||
import com.atsuishio.superbwarfare.config.server.ExplosionConfig;
|
import com.atsuishio.superbwarfare.config.server.ExplosionConfig;
|
||||||
import com.atsuishio.superbwarfare.config.server.VehicleConfig;
|
import com.atsuishio.superbwarfare.config.server.VehicleConfig;
|
||||||
import com.atsuishio.superbwarfare.entity.projectile.CannonShellEntity;
|
import com.atsuishio.superbwarfare.entity.projectile.CannonShellEntity;
|
||||||
|
@ -12,8 +11,6 @@ import com.atsuishio.superbwarfare.tools.CustomExplosion;
|
||||||
import com.atsuishio.superbwarfare.tools.EntityFindUtil;
|
import com.atsuishio.superbwarfare.tools.EntityFindUtil;
|
||||||
import com.atsuishio.superbwarfare.tools.ParticleTool;
|
import com.atsuishio.superbwarfare.tools.ParticleTool;
|
||||||
import com.atsuishio.superbwarfare.tools.SoundTool;
|
import com.atsuishio.superbwarfare.tools.SoundTool;
|
||||||
import net.minecraft.commands.arguments.EntityAnchorArgument;
|
|
||||||
import net.minecraft.core.BlockPos;
|
|
||||||
import net.minecraft.core.particles.ParticleTypes;
|
import net.minecraft.core.particles.ParticleTypes;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.network.protocol.Packet;
|
import net.minecraft.network.protocol.Packet;
|
||||||
|
@ -191,8 +188,30 @@ public class Mk42Entity extends VehicleEntity implements GeoEntity, ICannonEntit
|
||||||
}
|
}
|
||||||
|
|
||||||
lowHealthWarning();
|
lowHealthWarning();
|
||||||
|
}
|
||||||
|
|
||||||
this.refreshDimensions();
|
@Override
|
||||||
|
public void handleClientSync() {
|
||||||
|
if (isControlledByLocalInstance()) {
|
||||||
|
interpolationSteps = 0;
|
||||||
|
syncPacketPositionCodec(getX(), getY(), getZ());
|
||||||
|
}
|
||||||
|
if (interpolationSteps <= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
double interpolatedYaw = Mth.wrapDegrees(serverYRot - (double) getYRot());
|
||||||
|
setYRot(getYRot() + (float) interpolatedYaw / (float) interpolationSteps);
|
||||||
|
setXRot(getXRot() + (float) (serverXRot - (double) getXRot()) / (float) interpolationSteps);
|
||||||
|
setRot(getYRot(), getXRot());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void lerpTo(double x, double y, double z, float yaw, float pitch, int interpolationSteps, boolean interpolate) {
|
||||||
|
serverYRot = yaw;
|
||||||
|
serverXRot = pitch;
|
||||||
|
this.interpolationSteps = 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -332,50 +351,14 @@ public class Mk42Entity extends VehicleEntity implements GeoEntity, ICannonEntit
|
||||||
float diffX = 0;
|
float diffX = 0;
|
||||||
|
|
||||||
if (passenger instanceof Player player) {
|
if (passenger instanceof Player player) {
|
||||||
if (player.getOffhandItem().getItem() == ModItems.FIRING_PARAMETERS.get()) {
|
diffY = Math.clamp(-90f, 90f, Mth.wrapDegrees(passenger.getYHeadRot() - this.getYRot()));
|
||||||
if (setTarget(player.getOffhandItem())) {
|
diffX = passenger.getXRot() - 1.3f - this.getXRot();
|
||||||
diffY = Math.clamp(-90f, 90f, Mth.wrapDegrees(entityData.get(YAW) - this.getYRot()));
|
diffX = diffX * 0.15f;
|
||||||
diffX = Mth.wrapDegrees(entityData.get(PITCH) - this.getXRot());
|
this.setYRot(this.getYRot() + Mth.clamp(0.5f * diffY, -1.75f, 1.75f));
|
||||||
this.setYRot(this.getYRot() + Mth.clamp(0.5f * diffY, -1.75f, 1.75f));
|
this.setXRot(Mth.clamp(this.getXRot() + Mth.clamp(diffX, -3f, 3f), -85, 16.3f));
|
||||||
this.setXRot(Mth.clamp(this.getXRot() + Mth.clamp(0.95f * diffX, -5, 5), -85, 15));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
diffY = Math.clamp(-90f, 90f, Mth.wrapDegrees(passenger.getYHeadRot() - this.getYRot()));
|
|
||||||
diffX = passenger.getXRot() - 1.3f - this.getXRot();
|
|
||||||
diffX = diffX * 0.15f;
|
|
||||||
this.setYRot(this.getYRot() + Mth.clamp(0.5f * diffY, -1.75f, 1.75f));
|
|
||||||
this.setXRot(Mth.clamp(this.getXRot() + Mth.clamp(diffX, -3f, 3f), -85, 16.3f));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean setTarget(ItemStack stack) {
|
|
||||||
int targetX = stack.getOrCreateTag().getInt("TargetX");
|
|
||||||
int targetY = stack.getOrCreateTag().getInt("TargetY");
|
|
||||||
int targetZ = stack.getOrCreateTag().getInt("TargetZ");
|
|
||||||
|
|
||||||
this.look(EntityAnchorArgument.Anchor.EYES, new Vec3(targetX, targetY, targetZ));
|
|
||||||
|
|
||||||
double[] angles = new double[2];
|
|
||||||
boolean flag = RangeHelper.canReachTarget(15, 0.05, 0.99,
|
|
||||||
new BlockPos((int) this.getX(), (int) this.getEyeY(), (int) this.getZ()),
|
|
||||||
new BlockPos(targetX, targetY, targetZ),
|
|
||||||
angles);
|
|
||||||
|
|
||||||
if (flag) {
|
|
||||||
this.entityData.set(PITCH, -(float) angles[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return flag;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void look(EntityAnchorArgument.Anchor pAnchor, Vec3 pTarget) {
|
|
||||||
Vec3 vec3 = pAnchor.apply(this);
|
|
||||||
double d0 = (pTarget.x - vec3.x) * 0.2;
|
|
||||||
double d2 = (pTarget.z - vec3.z) * 0.2;
|
|
||||||
this.entityData.set(YAW, Mth.wrapDegrees((float) (Mth.atan2(d2, d0) * 57.2957763671875) - 90.0F));
|
|
||||||
}
|
|
||||||
|
|
||||||
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, -85.0F, 16.3F);
|
||||||
|
|
|
@ -198,8 +198,30 @@ public class Mle1934Entity extends VehicleEntity implements GeoEntity, ICannonEn
|
||||||
}
|
}
|
||||||
|
|
||||||
lowHealthWarning();
|
lowHealthWarning();
|
||||||
|
}
|
||||||
|
|
||||||
this.refreshDimensions();
|
@Override
|
||||||
|
public void handleClientSync() {
|
||||||
|
if (isControlledByLocalInstance()) {
|
||||||
|
interpolationSteps = 0;
|
||||||
|
syncPacketPositionCodec(getX(), getY(), getZ());
|
||||||
|
}
|
||||||
|
if (interpolationSteps <= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
double interpolatedYaw = Mth.wrapDegrees(serverYRot - (double) getYRot());
|
||||||
|
setYRot(getYRot() + (float) interpolatedYaw / (float) interpolationSteps);
|
||||||
|
setXRot(getXRot() + (float) (serverXRot - (double) getXRot()) / (float) interpolationSteps);
|
||||||
|
setRot(getYRot(), getXRot());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void lerpTo(double x, double y, double z, float yaw, float pitch, int interpolationSteps, boolean interpolate) {
|
||||||
|
serverYRot = yaw;
|
||||||
|
serverXRot = pitch;
|
||||||
|
this.interpolationSteps = 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -378,7 +378,7 @@ public class VehicleEntity extends Entity {
|
||||||
return transform.transform(new Vector4f(x, y, z, 1));
|
return transform.transform(new Vector4f(x, y, z, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void handleClientSync() {
|
public void handleClientSync() {
|
||||||
if (isControlledByLocalInstance()) {
|
if (isControlledByLocalInstance()) {
|
||||||
interpolationSteps = 0;
|
interpolationSteps = 0;
|
||||||
syncPacketPositionCodec(getX(), getY(), getZ());
|
syncPacketPositionCodec(getX(), getY(), getZ());
|
||||||
|
|
|
@ -1,13 +1,10 @@
|
||||||
package com.atsuishio.superbwarfare.network.message;
|
package com.atsuishio.superbwarfare.network.message;
|
||||||
|
|
||||||
import com.atsuishio.superbwarfare.client.gui.RangeHelper;
|
|
||||||
import com.atsuishio.superbwarfare.entity.MortarEntity;
|
import com.atsuishio.superbwarfare.entity.MortarEntity;
|
||||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||||
import com.atsuishio.superbwarfare.tools.FormatTool;
|
|
||||||
import com.atsuishio.superbwarfare.tools.SoundTool;
|
import com.atsuishio.superbwarfare.tools.SoundTool;
|
||||||
import com.atsuishio.superbwarfare.tools.TraceTool;
|
import com.atsuishio.superbwarfare.tools.TraceTool;
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
import net.minecraft.network.chat.Component;
|
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.util.Mth;
|
import net.minecraft.util.Mth;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
|
@ -15,6 +12,8 @@ import net.minecraftforge.network.NetworkEvent;
|
||||||
|
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
import static com.atsuishio.superbwarfare.entity.MortarEntity.PITCH;
|
||||||
|
|
||||||
public class AdjustMortarAngleMessage {
|
public class AdjustMortarAngleMessage {
|
||||||
|
|
||||||
private final double scroll;
|
private final double scroll;
|
||||||
|
@ -41,16 +40,10 @@ public class AdjustMortarAngleMessage {
|
||||||
Entity looking = TraceTool.findLookingEntity(player, 6);
|
Entity looking = TraceTool.findLookingEntity(player, 6);
|
||||||
if (looking == null) return;
|
if (looking == null) return;
|
||||||
|
|
||||||
double angle = 0;
|
|
||||||
|
|
||||||
if (looking instanceof MortarEntity mortar) {
|
if (looking instanceof MortarEntity mortar) {
|
||||||
mortar.getEntityData().set(MortarEntity.PITCH, (float) Mth.clamp(mortar.getEntityData().get(MortarEntity.PITCH) + 0.5 * message.scroll, 20, 89));
|
mortar.getEntityData().set(PITCH, (float) Mth.clamp(mortar.getEntityData().get(PITCH) + 0.5 * message.scroll, -89, -20));
|
||||||
angle = mortar.getEntityData().get(MortarEntity.PITCH);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
player.displayClientMessage(Component.translatable("tips.superbwarfare.mortar.angle",
|
|
||||||
FormatTool.format2D(angle),
|
|
||||||
FormatTool.format1D((int) RangeHelper.getRange(angle)), "m"), true);
|
|
||||||
SoundTool.playLocalSound(player, ModSounds.ADJUST_FOV.get(), 1f, 0.7f);
|
SoundTool.playLocalSound(player, ModSounds.ADJUST_FOV.get(), 1f, 0.7f);
|
||||||
});
|
});
|
||||||
context.get().setPacketHandled(true);
|
context.get().setPacketHandled(true);
|
||||||
|
|
|
@ -464,7 +464,7 @@
|
||||||
"tips.superbwarfare.annihilator.energy_not_enough": "Energy is Not Enough",
|
"tips.superbwarfare.annihilator.energy_not_enough": "Energy is Not Enough",
|
||||||
"tips.superbwarfare.target.down": "Target Down %1$s",
|
"tips.superbwarfare.target.down": "Target Down %1$s",
|
||||||
"tips.superbwarfare.target.damage": "Damage: %1$s Distance: %2$s",
|
"tips.superbwarfare.target.damage": "Damage: %1$s Distance: %2$s",
|
||||||
"tips.superbwarfare.mortar.angle": "Angle: %1$s Range: %2$s",
|
"tips.superbwarfare.mortar.range": "Range: ",
|
||||||
"tips.superbwarfare.mortar.yaw": "Yaw:",
|
"tips.superbwarfare.mortar.yaw": "Yaw:",
|
||||||
"tips.superbwarfare.mortar.pitch": "Pitch:",
|
"tips.superbwarfare.mortar.pitch": "Pitch:",
|
||||||
"tips.superbwarfare.mortar.target_pos": "Target Position:",
|
"tips.superbwarfare.mortar.target_pos": "Target Position:",
|
||||||
|
|
|
@ -462,7 +462,7 @@
|
||||||
"tips.superbwarfare.annihilator.energy_not_enough": "能量不足",
|
"tips.superbwarfare.annihilator.energy_not_enough": "能量不足",
|
||||||
"tips.superbwarfare.target.down": "目标倒下 %1$s",
|
"tips.superbwarfare.target.down": "目标倒下 %1$s",
|
||||||
"tips.superbwarfare.target.damage": "伤害:%1$s 距离:%2$s",
|
"tips.superbwarfare.target.damage": "伤害:%1$s 距离:%2$s",
|
||||||
"tips.superbwarfare.mortar.angle": "角度:%1$s 射程:%2$s",
|
"tips.superbwarfare.mortar.range": "射程:",
|
||||||
"tips.superbwarfare.mortar.yaw": "水平朝向:",
|
"tips.superbwarfare.mortar.yaw": "水平朝向:",
|
||||||
"tips.superbwarfare.mortar.pitch": "俯仰角度:",
|
"tips.superbwarfare.mortar.pitch": "俯仰角度:",
|
||||||
"tips.superbwarfare.mortar.target_pos": "目标坐标:",
|
"tips.superbwarfare.mortar.target_pos": "目标坐标:",
|
||||||
|
|
Loading…
Add table
Reference in a new issue