diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mk42Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mk42Entity.java index 13c55c872..4bbc6bb13 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mk42Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mk42Entity.java @@ -18,10 +18,7 @@ import com.atsuishio.superbwarfare.init.ModTags; import com.atsuishio.superbwarfare.item.ArtilleryIndicator; import com.atsuishio.superbwarfare.item.common.ammo.CannonShellItem; import com.atsuishio.superbwarfare.network.message.receive.ShakeClientMessage; -import com.atsuishio.superbwarfare.tools.CustomExplosion; -import com.atsuishio.superbwarfare.tools.InventoryTool; -import com.atsuishio.superbwarfare.tools.ParticleTool; -import com.atsuishio.superbwarfare.tools.SoundTool; +import com.atsuishio.superbwarfare.tools.*; import net.minecraft.ChatFormatting; import net.minecraft.core.particles.ParticleTypes; import net.minecraft.nbt.CompoundTag; @@ -54,6 +51,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.joml.Math; import org.joml.Matrix4f; +import org.joml.Vector3f; import org.joml.Vector4f; import software.bernie.geckolib.animatable.GeoEntity; import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache; @@ -69,6 +67,10 @@ public class Mk42Entity extends VehicleEntity implements GeoEntity, CannonEntity public static final EntityDataAccessor PITCH = SynchedEntityData.defineId(Mk42Entity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor YAW = SynchedEntityData.defineId(Mk42Entity.class, EntityDataSerializers.FLOAT); + public static final EntityDataAccessor DEPRESSED = SynchedEntityData.defineId(Mk42Entity.class, EntityDataSerializers.BOOLEAN); + public static final EntityDataAccessor TARGET_POS = SynchedEntityData.defineId(Mk42Entity.class, EntityDataSerializers.VECTOR3); + public static final EntityDataAccessor RADIUS = SynchedEntityData.defineId(Mk42Entity.class, EntityDataSerializers.INT); + private final float shellGravity = 0.1f; public Mk42Entity(EntityType type, Level world) { @@ -83,7 +85,11 @@ public class Mk42Entity extends VehicleEntity implements GeoEntity, CannonEntity super.defineSynchedData(builder); builder.define(COOL_DOWN, 0) .define(PITCH, 0F) - .define(YAW, 0F); + .define(YAW, 0F) + + .define(DEPRESSED, false) + .define(TARGET_POS, new Vector3f()) + .define(RADIUS, 0); } @Override @@ -123,6 +129,12 @@ public class Mk42Entity extends VehicleEntity implements GeoEntity, CannonEntity compound.putInt("CoolDown", this.entityData.get(COOL_DOWN)); compound.putFloat("Pitch", this.entityData.get(PITCH)); compound.putFloat("Yaw", this.entityData.get(YAW)); + + compound.putBoolean("Depressed", this.entityData.get(DEPRESSED)); + compound.putInt("Radius", this.entityData.get(RADIUS)); + compound.putFloat("TargetX", this.entityData.get(TARGET_POS).x); + compound.putFloat("TargetY", this.entityData.get(TARGET_POS).y); + compound.putFloat("TargetZ", this.entityData.get(TARGET_POS).z); } @Override @@ -131,6 +143,16 @@ public class Mk42Entity extends VehicleEntity implements GeoEntity, CannonEntity this.entityData.set(COOL_DOWN, compound.getInt("CoolDown")); this.entityData.set(PITCH, compound.getFloat("Pitch")); this.entityData.set(YAW, compound.getFloat("Yaw")); + + if (compound.contains("Depressed")) { + this.entityData.set(DEPRESSED, compound.getBoolean("Depressed")); + } + if (compound.contains("Radius")) { + this.entityData.set(RADIUS, compound.getInt("Radius")); + } + if (compound.contains("TargetX") && compound.contains("TargetY") && compound.contains("TargetZ")) { + this.entityData.set(TARGET_POS, new Vector3f(compound.getFloat("TargetX"), compound.getFloat("TargetX"), compound.getFloat("TargetZ"))); + } } @Override @@ -211,11 +233,16 @@ public class Mk42Entity extends VehicleEntity implements GeoEntity, CannonEntity Matrix4f transform = getVehicleFlatTransform(1); Vector4f worldPosition = transformPosition(transform, 0f, 2.16f, 0.5175f); Vec3 shootPos = new Vec3(worldPosition.x, worldPosition.y, worldPosition.z); + double adjust = -1 + 0.004 * new Vec3(targetX, targetY, targetZ).distanceTo(shootPos); + + entityData.set(TARGET_POS, new Vector3f((float) targetX, (float) (targetY - adjust), (float) targetZ)); + entityData.set(DEPRESSED, isDepressed); + entityData.set(RADIUS, parameters.radius()); + Vec3 randomPos = VectorTool.randomPos(new Vec3(entityData.get(TARGET_POS)), entityData.get(RADIUS)); try { - double adjust = -1 + 0.004 * new Vec3(targetX, targetY, targetZ).distanceTo(shootPos); - Vec3 launchVector = calculateLaunchVector(shootPos, new Vec3(targetX, targetY - adjust, targetZ), 15, -shellGravity, isDepressed); - this.look(new Vec3(targetX, targetY, targetZ)); + Vec3 launchVector = calculateLaunchVector(getEyePosition(), randomPos, 15, -shellGravity, entityData.get(DEPRESSED)); + this.look(randomPos); float angle = (float) -getXRotFromVector(launchVector); if (angle < -85 || angle > 14.9) { return false; @@ -227,34 +254,14 @@ public class Mk42Entity extends VehicleEntity implements GeoEntity, CannonEntity return true; } - //TODO 指示器能选择弹道后删掉这个 - - public boolean setTarget(ItemStack stack, boolean isDepressed) { - var parameters = stack.get(ModDataComponents.FIRING_PARAMETERS); - if (parameters == null) return false; - - var pos = parameters.pos(); - double targetX = pos.getX(); - double targetY = pos.getY(); - double targetZ = pos.getZ(); - - Matrix4f transform = getVehicleFlatTransform(1); - Vector4f worldPosition = transformPosition(transform, 0f, 2.16f, 0.5175f); - Vec3 shootPos = new Vec3(worldPosition.x, worldPosition.y, worldPosition.z); - - try { - double adjust = -1 + 0.004 * new Vec3(targetX, targetY, targetZ).distanceTo(shootPos); - Vec3 launchVector = calculateLaunchVector(shootPos, new Vec3(targetX, targetY - adjust, targetZ), 15, -shellGravity, isDepressed); - this.look(new Vec3(targetX, targetY, targetZ)); - float angle = (float) -getXRotFromVector(launchVector); - if (angle < -85 || angle > 14.9) { - return false; - } + public void resetTarget() { + Vec3 randomPos = VectorTool.randomPos(new Vec3(entityData.get(TARGET_POS)), entityData.get(RADIUS)); + Vec3 launchVector = calculateLaunchVector(getEyePosition(), randomPos, 15, -shellGravity, entityData.get(DEPRESSED)); + this.look(randomPos); + float angle = (float) -getXRotFromVector(launchVector); + if (angle < -85 || angle > 14.9) { entityData.set(PITCH, angle); - } catch (Exception e) { - return false; } - return true; } private void look(Vec3 pTarget) { @@ -425,6 +432,8 @@ public class Mk42Entity extends VehicleEntity implements GeoEntity, CannonEntity } ShakeClientMessage.sendToNearbyPlayers(this, 20, 15, 15, 45); + + resetTarget(); } } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mle1934Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mle1934Entity.java index 3b977b18e..712694528 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mle1934Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mle1934Entity.java @@ -18,10 +18,7 @@ import com.atsuishio.superbwarfare.init.ModTags; import com.atsuishio.superbwarfare.item.ArtilleryIndicator; import com.atsuishio.superbwarfare.item.common.ammo.CannonShellItem; import com.atsuishio.superbwarfare.network.message.receive.ShakeClientMessage; -import com.atsuishio.superbwarfare.tools.CustomExplosion; -import com.atsuishio.superbwarfare.tools.InventoryTool; -import com.atsuishio.superbwarfare.tools.ParticleTool; -import com.atsuishio.superbwarfare.tools.SoundTool; +import com.atsuishio.superbwarfare.tools.*; import net.minecraft.ChatFormatting; import net.minecraft.core.particles.ParticleTypes; import net.minecraft.nbt.CompoundTag; @@ -55,6 +52,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.joml.Math; import org.joml.Matrix4f; +import org.joml.Vector3f; import org.joml.Vector4f; import software.bernie.geckolib.animatable.GeoEntity; import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache; @@ -69,6 +67,11 @@ public class Mle1934Entity extends VehicleEntity implements GeoEntity, CannonEnt public static final EntityDataAccessor TYPE = SynchedEntityData.defineId(Mle1934Entity.class, EntityDataSerializers.INT); public static final EntityDataAccessor PITCH = SynchedEntityData.defineId(Mle1934Entity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor YAW = SynchedEntityData.defineId(Mle1934Entity.class, EntityDataSerializers.FLOAT); + + public static final EntityDataAccessor DEPRESSED = SynchedEntityData.defineId(Mle1934Entity.class, EntityDataSerializers.BOOLEAN); + public static final EntityDataAccessor TARGET_POS = SynchedEntityData.defineId(Mle1934Entity.class, EntityDataSerializers.VECTOR3); + public static final EntityDataAccessor RADIUS = SynchedEntityData.defineId(Mle1934Entity.class, EntityDataSerializers.INT); + private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); private final float shellGravity = 0.1f; @@ -117,7 +120,11 @@ public class Mle1934Entity extends VehicleEntity implements GeoEntity, CannonEnt builder.define(COOL_DOWN, 0) .define(TYPE, 0) .define(PITCH, 0f) - .define(YAW, 0f); + .define(YAW, 0f) + + .define(DEPRESSED, false) + .define(TARGET_POS, new Vector3f()) + .define(RADIUS, 0); } @Override @@ -127,6 +134,12 @@ public class Mle1934Entity extends VehicleEntity implements GeoEntity, CannonEnt compound.putInt("Type", this.entityData.get(TYPE)); compound.putFloat("Pitch", this.entityData.get(PITCH)); compound.putFloat("Yaw", this.entityData.get(YAW)); + + compound.putBoolean("Depressed", this.entityData.get(DEPRESSED)); + compound.putInt("Radius", this.entityData.get(RADIUS)); + compound.putFloat("TargetX", this.entityData.get(TARGET_POS).x); + compound.putFloat("TargetY", this.entityData.get(TARGET_POS).y); + compound.putFloat("TargetZ", this.entityData.get(TARGET_POS).z); } @Override @@ -136,6 +149,16 @@ public class Mle1934Entity extends VehicleEntity implements GeoEntity, CannonEnt this.entityData.set(TYPE, compound.getInt("Type")); this.entityData.set(PITCH, compound.getFloat("Pitch")); this.entityData.set(YAW, compound.getFloat("Yaw")); + + if (compound.contains("Depressed")) { + this.entityData.set(DEPRESSED, compound.getBoolean("Depressed")); + } + if (compound.contains("Radius")) { + this.entityData.set(RADIUS, compound.getInt("Radius")); + } + if (compound.contains("TargetX") && compound.contains("TargetY") && compound.contains("TargetZ")) { + this.entityData.set(TARGET_POS, new Vector3f(compound.getFloat("TargetX"), compound.getFloat("TargetX"), compound.getFloat("TargetZ"))); + } } @Override @@ -204,6 +227,7 @@ public class Mle1934Entity extends VehicleEntity implements GeoEntity, CannonEnt return super.interact(player, hand); } + //这个炮仰角太低只能用低伸弹道 public boolean setTarget(ItemStack stack) { var parameters = stack.get(ModDataComponents.FIRING_PARAMETERS); if (parameters == null) return false; @@ -214,15 +238,19 @@ public class Mle1934Entity extends VehicleEntity implements GeoEntity, CannonEnt int targetZ = pos.getZ(); var isDepressed = parameters.isDepressed(); - this.look(new Vec3(targetX, targetY, targetZ)); Matrix4f transform = getVehicleFlatTransform(1); Vector4f worldPosition = transformPosition(transform, 0, 1.4992625f, 1.52065f); Vec3 shootPos = new Vec3(worldPosition.x, worldPosition.y, worldPosition.z); + double adjust = -1 + 0.004 * new Vec3(targetX, targetY, targetZ).distanceTo(shootPos); + + entityData.set(TARGET_POS, new Vector3f((float) targetX, (float) (targetY - adjust), (float) targetZ)); + entityData.set(DEPRESSED, true); + entityData.set(RADIUS, parameters.radius()); + Vec3 randomPos = VectorTool.randomPos(new Vec3(entityData.get(TARGET_POS)), entityData.get(RADIUS)); try { - double adjust = -1 + 0.004 * new Vec3(targetX, targetY, targetZ).distanceTo(shootPos); - Vec3 launchVector = calculateLaunchVector(shootPos, new Vec3(targetX, targetY - adjust, targetZ), 15, -shellGravity, isDepressed); - this.look(new Vec3(targetX, targetY, targetZ)); + Vec3 launchVector = calculateLaunchVector(getEyePosition(), randomPos, 15, -shellGravity, entityData.get(DEPRESSED)); + this.look(randomPos); float angle = (float) -getXRotFromVector(launchVector); if (angle < -30 || angle > 2.7) { return false; @@ -231,37 +259,17 @@ public class Mle1934Entity extends VehicleEntity implements GeoEntity, CannonEnt } catch (Exception e) { return false; } - return true; } - //这个炮仰角太低只能用低伸弹道 - public boolean setTarget(ItemStack stack, boolean isDepressed) { - var parameters = stack.get(ModDataComponents.FIRING_PARAMETERS); - if (parameters == null) return false; - - var pos = parameters.pos(); - double targetX = pos.getX(); - double targetY = pos.getY(); - double targetZ = pos.getZ(); - - Matrix4f transform = getVehicleFlatTransform(1); - Vector4f worldPosition = transformPosition(transform, 0f, 2.16f, 0.5175f); - Vec3 shootPos = new Vec3(worldPosition.x, worldPosition.y, worldPosition.z); - - try { - double adjust = -1 + 0.004 * new Vec3(targetX, targetY, targetZ).distanceTo(shootPos); - Vec3 launchVector = calculateLaunchVector(shootPos, new Vec3(targetX, targetY - adjust, targetZ), 15, -shellGravity, isDepressed); - this.look(new Vec3(targetX, targetY, targetZ)); - float angle = (float) -getXRotFromVector(launchVector); - if (angle < -85 || angle > 14.9) { - return false; - } + public void resetTarget() { + Vec3 randomPos = VectorTool.randomPos(new Vec3(entityData.get(TARGET_POS)), entityData.get(RADIUS)); + Vec3 launchVector = calculateLaunchVector(getEyePosition(), randomPos, 15, -shellGravity, entityData.get(DEPRESSED)); + this.look(randomPos); + float angle = (float) -getXRotFromVector(launchVector); + if (angle < -30 || angle > 2.7) { entityData.set(PITCH, angle); - } catch (Exception e) { - return false; } - return true; } private void look(Vec3 pTarget) { @@ -492,6 +500,8 @@ public class Mle1934Entity extends VehicleEntity implements GeoEntity, CannonEnt 100, 7, 0.02, 7, 0.005); ShakeClientMessage.sendToNearbyPlayers(this, 20, 15, 15, 45); + + resetTarget(); } } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/MortarEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/MortarEntity.java index 605128e4e..94bdc6d69 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/MortarEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/MortarEntity.java @@ -10,6 +10,7 @@ import com.atsuishio.superbwarfare.init.ModTags; import com.atsuishio.superbwarfare.item.ArtilleryIndicator; import com.atsuishio.superbwarfare.item.Monitor; import com.atsuishio.superbwarfare.item.common.ammo.MortarShell; +import com.atsuishio.superbwarfare.tools.VectorTool; import net.minecraft.ChatFormatting; import net.minecraft.commands.arguments.EntityAnchorArgument; import net.minecraft.core.particles.ParticleTypes; @@ -38,6 +39,7 @@ import net.neoforged.neoforge.items.ItemHandlerHelper; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.joml.Math; +import org.joml.Vector3f; import software.bernie.geckolib.animatable.GeoEntity; import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache; import software.bernie.geckolib.animation.*; @@ -46,12 +48,15 @@ import software.bernie.geckolib.util.GeckoLibUtil; import static com.atsuishio.superbwarfare.tools.RangeTool.calculateLaunchVector; public class MortarEntity extends VehicleEntity implements GeoEntity, Container { - public static final EntityDataAccessor FIRE_TIME = SynchedEntityData.defineId(MortarEntity.class, EntityDataSerializers.INT); public static final EntityDataAccessor PITCH = SynchedEntityData.defineId(MortarEntity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor YAW = SynchedEntityData.defineId(MortarEntity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor INTELLIGENT = SynchedEntityData.defineId(MortarEntity.class, EntityDataSerializers.BOOLEAN); + public static final EntityDataAccessor DEPRESSED = SynchedEntityData.defineId(MortarEntity.class, EntityDataSerializers.BOOLEAN); + public static final EntityDataAccessor TARGET_POS = SynchedEntityData.defineId(MortarEntity.class, EntityDataSerializers.VECTOR3); + public static final EntityDataAccessor RADIUS = SynchedEntityData.defineId(MortarEntity.class, EntityDataSerializers.INT); + private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); private LivingEntity shooter = null; @@ -78,7 +83,13 @@ public class MortarEntity extends VehicleEntity implements GeoEntity, Container builder.define(FIRE_TIME, 0) .define(PITCH, -70f) .define(YAW, this.getYRot()) - .define(INTELLIGENT, false); + + .define(DEPRESSED, false) + .define(INTELLIGENT, false) + .define(TARGET_POS, new Vector3f()) + .define(RADIUS, 0); + + } @Override @@ -92,6 +103,12 @@ public class MortarEntity extends VehicleEntity implements GeoEntity, Container compound.putFloat("Pitch", this.entityData.get(PITCH)); compound.putFloat("Yaw", this.entityData.get(YAW)); compound.putBoolean("Intelligent", this.entityData.get(INTELLIGENT)); + + compound.putBoolean("Depressed", this.entityData.get(DEPRESSED)); + compound.putInt("Radius", this.entityData.get(RADIUS)); + compound.putFloat("TargetX", this.entityData.get(TARGET_POS).x); + compound.putFloat("TargetY", this.entityData.get(TARGET_POS).y); + compound.putFloat("TargetZ", this.entityData.get(TARGET_POS).z); } @Override @@ -106,10 +123,21 @@ public class MortarEntity extends VehicleEntity implements GeoEntity, Container if (compound.contains("Intelligent")) { this.entityData.set(INTELLIGENT, compound.getBoolean("Intelligent")); } + + if (compound.contains("Depressed")) { + this.entityData.set(DEPRESSED, compound.getBoolean("Depressed")); + } + if (compound.contains("Radius")) { + this.entityData.set(RADIUS, compound.getInt("Radius")); + } + if (compound.contains("TargetX") && compound.contains("TargetY") && compound.contains("TargetZ")) { + this.entityData.set(TARGET_POS, new Vector3f(compound.getFloat("TargetX"), compound.getFloat("TargetX"), compound.getFloat("TargetZ"))); + } } public void fire(@Nullable LivingEntity shooter) { if (!(this.stack.getItem() instanceof MortarShell)) return; + if (entityData.get(FIRE_TIME) != 0) return; this.shooter = shooter; this.entityData.set(FIRE_TIME, 25); @@ -154,7 +182,7 @@ public class MortarEntity extends VehicleEntity implements GeoEntity, Container } if (mainHandItem.is(ModTags.Items.CROWBAR) && !player.isShiftKeyDown()) { - if (this.stack.getItem() instanceof MortarShell) { + if (this.stack.getItem() instanceof MortarShell && this.entityData.get(FIRE_TIME) == 0) { fire(player); } return InteractionResult.SUCCESS; @@ -212,9 +240,14 @@ public class MortarEntity extends VehicleEntity implements GeoEntity, Container double targetZ = pos.getZ(); var isDepressed = parameters.isDepressed(); + entityData.set(TARGET_POS, new Vector3f((float) targetX, (float) targetY, (float) targetZ)); + entityData.set(DEPRESSED, isDepressed); + entityData.set(RADIUS, parameters.radius()); + Vec3 randomPos = VectorTool.randomPos(new Vec3(entityData.get(TARGET_POS)), entityData.get(RADIUS)); + try { - Vec3 launchVector = calculateLaunchVector(getEyePosition(), new Vec3(targetX, targetY - 1, targetZ), 13, -0.11, isDepressed); - this.look(new Vec3(targetX, targetY, targetZ)); + Vec3 launchVector = calculateLaunchVector(getEyePosition(), randomPos, 13, -0.11, entityData.get(DEPRESSED)); + this.look(randomPos); float angle = (float) -getXRotFromVector(launchVector); if (angle < -89 || angle > -20) { return false; @@ -223,10 +256,20 @@ public class MortarEntity extends VehicleEntity implements GeoEntity, Container } catch (Exception e) { return false; } - return true; } + public void resetTarget() { + Vec3 randomPos = VectorTool.randomPos(new Vec3(entityData.get(TARGET_POS)), entityData.get(RADIUS)); + Vec3 launchVector = calculateLaunchVector(getEyePosition(), randomPos, 13, -0.11, entityData.get(DEPRESSED)); + this.look(randomPos); + float angle = (float) -getXRotFromVector(launchVector); + if (angle > -89 && angle < -20) { + entityData.set(PITCH, angle); + } + } + + private void look(Vec3 pTarget) { Vec3 vec3 = EntityAnchorArgument.Anchor.EYES.apply(this); double d0 = (pTarget.x - vec3.x) * 0.2; @@ -252,13 +295,14 @@ public class MortarEntity extends VehicleEntity implements GeoEntity, Container if (level instanceof ServerLevel server) { MortarShellEntity entityToSpawn = MortarShell.createShell(shooter, level, this.stack); entityToSpawn.setPos(this.getX(), this.getEyeY(), this.getZ()); - entityToSpawn.shoot(this.getLookAngle().x, this.getLookAngle().y, this.getLookAngle().z, 13f, (float) 0.4); + entityToSpawn.shoot(this.getLookAngle().x, this.getLookAngle().y, this.getLookAngle().z, 13f, (float) 0.1); level.addFreshEntity(entityToSpawn); server.sendParticles(ParticleTypes.CAMPFIRE_COSY_SMOKE, (this.getX() + 3 * this.getLookAngle().x), (this.getY() + 0.1 + 3 * this.getLookAngle().y), (this.getZ() + 3 * this.getLookAngle().z), 8, 0.4, 0.4, 0.4, 0.007); server.sendParticles(ParticleTypes.CAMPFIRE_COSY_SMOKE, this.getX(), this.getY(), this.getZ(), 50, 2, 0.02, 2, 0.0005); this.stack = ItemStack.EMPTY; + resetTarget(); } } diff --git a/src/main/java/com/atsuishio/superbwarfare/network/message/send/DroneFireMessage.java b/src/main/java/com/atsuishio/superbwarfare/network/message/send/DroneFireMessage.java index 50461e012..b7a88c451 100644 --- a/src/main/java/com/atsuishio/superbwarfare/network/message/send/DroneFireMessage.java +++ b/src/main/java/com/atsuishio/superbwarfare/network/message/send/DroneFireMessage.java @@ -67,6 +67,7 @@ public record DroneFireMessage(Vector3f pos) implements CustomPacketPayload { SoundTool.playLocalSound(player, ModSounds.CANNON_ZOOM_IN.get(), 2, 1); if (offStack.is(ModItems.ARTILLERY_INDICATOR.get())) { + ListTag tags = NBTTool.getTag(offStack).getList(TAG_CANNON, Tag.TAG_COMPOUND); for (int i = 0; i < tags.size(); i++) { var tag = tags.getCompound(i); @@ -77,12 +78,12 @@ public record DroneFireMessage(Vector3f pos) implements CustomPacketPayload { } } if (entity instanceof Mk42Entity mk42Entity) { - if (!mk42Entity.setTarget(offStack, true)) { + if (!mk42Entity.setTarget(offStack)) { player.displayClientMessage(Component.translatable("tips.superbwarfare.mk_42.warn").withStyle(ChatFormatting.RED), true); } } if (entity instanceof Mle1934Entity mle1934Entity) { - if (!mle1934Entity.setTarget(offStack, true)) { + if (!mle1934Entity.setTarget(offStack)) { player.displayClientMessage(Component.translatable("tips.superbwarfare.mle_1934.warn").withStyle(ChatFormatting.RED), true); } } diff --git a/src/main/java/com/atsuishio/superbwarfare/network/message/send/SetFiringParametersMessage.java b/src/main/java/com/atsuishio/superbwarfare/network/message/send/SetFiringParametersMessage.java index f36c09fdb..65d3f56b1 100644 --- a/src/main/java/com/atsuishio/superbwarfare/network/message/send/SetFiringParametersMessage.java +++ b/src/main/java/com/atsuishio/superbwarfare/network/message/send/SetFiringParametersMessage.java @@ -101,12 +101,12 @@ public enum SetFiringParametersMessage implements CustomPacketPayload { } } if (entity instanceof Mk42Entity mk42Entity) { - if (!mk42Entity.setTarget(mainStack, true)) { + if (!mk42Entity.setTarget(mainStack)) { player.displayClientMessage(Component.translatable("tips.superbwarfare.mk_42.warn").withStyle(ChatFormatting.RED), true); } } if (entity instanceof Mle1934Entity mle1934Entity) { - if (!mle1934Entity.setTarget(mainStack, true)) { + if (!mle1934Entity.setTarget(mainStack)) { player.displayClientMessage(Component.translatable("tips.superbwarfare.mle_1934.warn").withStyle(ChatFormatting.RED), true); } } diff --git a/src/main/java/com/atsuishio/superbwarfare/tools/ParticleTool.java b/src/main/java/com/atsuishio/superbwarfare/tools/ParticleTool.java index 31c612766..d32847499 100644 --- a/src/main/java/com/atsuishio/superbwarfare/tools/ParticleTool.java +++ b/src/main/java/com/atsuishio/superbwarfare/tools/ParticleTool.java @@ -37,11 +37,6 @@ public class ParticleTool { level.playSound(null, BlockPos.containing(x, y + 1, z), ModSounds.EXPLOSION_WATER.get(), SoundSource.BLOCKS, 2, 1); } level.playSound(null, BlockPos.containing(x, y + 1, z), SoundEvents.FIREWORK_ROCKET_BLAST, SoundSource.BLOCKS, 4, 1); - } else { - if ((level.getBlockState(BlockPos.containing(x, y, z))).getBlock() == Blocks.WATER) { - level.playLocalSound(x, (y + 1), z, ModSounds.EXPLOSION_WATER.get(), SoundSource.BLOCKS, 1, 1, false); - } - level.playLocalSound(x, (y + 1), z, SoundEvents.FIREWORK_ROCKET_BLAST, SoundSource.BLOCKS, 2, 1, false); } if (level instanceof ServerLevel serverLevel) { @@ -64,14 +59,6 @@ public class ParticleTool { level.playSound(null, BlockPos.containing(x, y + 1, z), ModSounds.EXPLOSION_CLOSE.get(), SoundSource.BLOCKS, 3, 1); level.playSound(null, BlockPos.containing(x, y + 1, z), ModSounds.EXPLOSION_FAR.get(), SoundSource.BLOCKS, 6, 1); level.playSound(null, BlockPos.containing(x, y + 1, z), ModSounds.EXPLOSION_VERY_FAR.get(), SoundSource.BLOCKS, 12, 1); - } else { - if ((level.getBlockState(BlockPos.containing(x, y, z))).getBlock() == Blocks.WATER) { - level.playLocalSound(x, (y + 1), z, ModSounds.EXPLOSION_WATER.get(), SoundSource.BLOCKS, 1, 1, false); - } - level.playLocalSound(x, (y + 1), z, SoundEvents.FIREWORK_ROCKET_BLAST, SoundSource.BLOCKS, 2, 1, false); - level.playLocalSound(x, (y + 1), z, ModSounds.EXPLOSION_CLOSE.get(), SoundSource.BLOCKS, 1, 1, false); - level.playLocalSound(x, (y + 1), z, ModSounds.EXPLOSION_FAR.get(), SoundSource.BLOCKS, 1, 1, false); - level.playLocalSound(x, (y + 1), z, ModSounds.EXPLOSION_VERY_FAR.get(), SoundSource.BLOCKS, 1, 1, false); } if (level instanceof ServerLevel serverLevel) { @@ -92,16 +79,9 @@ public class ParticleTool { if ((level.getBlockState(BlockPos.containing(x, y, z))).getBlock() == Blocks.WATER) { level.playSound(null, BlockPos.containing(x, y + 1, z), ModSounds.EXPLOSION_WATER.get(), SoundSource.BLOCKS, 3, 1); } - level.playSound(null, BlockPos.containing(x, y + 1, z), ModSounds.EXPLOSION_CLOSE.get(), SoundSource.BLOCKS, 6, 1); - level.playSound(null, BlockPos.containing(x, y + 1, z), ModSounds.EXPLOSION_FAR.get(), SoundSource.BLOCKS, 12, 1); - level.playSound(null, BlockPos.containing(x, y + 1, z), ModSounds.EXPLOSION_VERY_FAR.get(), SoundSource.BLOCKS, 32, 1); - } else { - if ((level.getBlockState(BlockPos.containing(x, y, z))).getBlock() == Blocks.WATER) { - level.playLocalSound(x, (y + 1), z, ModSounds.EXPLOSION_WATER.get(), SoundSource.BLOCKS, 1, 1, false); - } - level.playLocalSound(x, (y + 1), z, ModSounds.EXPLOSION_CLOSE.get(), SoundSource.BLOCKS, 1, 1, false); - level.playLocalSound(x, (y + 1), z, ModSounds.EXPLOSION_FAR.get(), SoundSource.BLOCKS, 1, 1, false); - level.playLocalSound(x, (y + 1), z, ModSounds.EXPLOSION_VERY_FAR.get(), SoundSource.BLOCKS, 1, 1, false); + level.playSound(null, BlockPos.containing(x, y + 1, z), ModSounds.EXPLOSION_CLOSE.get(), SoundSource.BLOCKS, 16, 1); + level.playSound(null, BlockPos.containing(x, y + 1, z), ModSounds.EXPLOSION_FAR.get(), SoundSource.BLOCKS, 48, 1); + level.playSound(null, BlockPos.containing(x, y + 1, z), ModSounds.EXPLOSION_VERY_FAR.get(), SoundSource.BLOCKS, 128, 1); } if (level instanceof ServerLevel serverLevel) { @@ -129,16 +109,9 @@ public class ParticleTool { if ((level.getBlockState(BlockPos.containing(x, y, z))).getBlock() == Blocks.WATER) { level.playSound(null, BlockPos.containing(x, y + 1, z), ModSounds.EXPLOSION_WATER.get(), SoundSource.BLOCKS, 3, 1); } - level.playSound(null, BlockPos.containing(x, y + 1, z), ModSounds.HUGE_EXPLOSION_CLOSE.get(), SoundSource.BLOCKS, 8, 1); - level.playSound(null, BlockPos.containing(x, y + 1, z), ModSounds.HUGE_EXPLOSION_FAR.get(), SoundSource.BLOCKS, 16, 1); - level.playSound(null, BlockPos.containing(x, y + 1, z), ModSounds.HUGE_EXPLOSION_VERY_FAR.get(), SoundSource.BLOCKS, 32, 1); - } else { - if ((level.getBlockState(BlockPos.containing(x, y, z))).getBlock() == Blocks.WATER) { - level.playLocalSound(x, (y + 1), z, ModSounds.EXPLOSION_WATER.get(), SoundSource.BLOCKS, 1, 1, false); - } - level.playLocalSound(x, (y + 1), z, ModSounds.HUGE_EXPLOSION_CLOSE.get(), SoundSource.BLOCKS, 1, 1, false); - level.playLocalSound(x, (y + 1), z, ModSounds.HUGE_EXPLOSION_FAR.get(), SoundSource.BLOCKS, 1, 1, false); - level.playLocalSound(x, (y + 1), z, ModSounds.HUGE_EXPLOSION_VERY_FAR.get(), SoundSource.BLOCKS, 1, 1, false); + level.playSound(null, BlockPos.containing(x, y + 1, z), ModSounds.HUGE_EXPLOSION_CLOSE.get(), SoundSource.BLOCKS, 24, 1); + level.playSound(null, BlockPos.containing(x, y + 1, z), ModSounds.HUGE_EXPLOSION_FAR.get(), SoundSource.BLOCKS, 64, 1); + level.playSound(null, BlockPos.containing(x, y + 1, z), ModSounds.HUGE_EXPLOSION_VERY_FAR.get(), SoundSource.BLOCKS, 160, 1); } if (level instanceof ServerLevel serverLevel) { diff --git a/src/main/java/com/atsuishio/superbwarfare/tools/VectorTool.java b/src/main/java/com/atsuishio/superbwarfare/tools/VectorTool.java index 1f1d338a8..46e694d0e 100644 --- a/src/main/java/com/atsuishio/superbwarfare/tools/VectorTool.java +++ b/src/main/java/com/atsuishio/superbwarfare/tools/VectorTool.java @@ -55,4 +55,8 @@ public class VectorTool { return combined; } + + public static Vec3 randomPos(Vec3 originPos, int radius) { + return originPos.add(new Vec3(Math.random() * radius, 0, 0).yRot((float) (360 * Math.random()))); + } }