添加乘客图标

This commit is contained in:
Atsuihsio 2025-03-09 17:22:00 +08:00
parent 5245916bfc
commit 1857d94855
13 changed files with 221 additions and 104 deletions

View file

@ -1,6 +1,6 @@
package com.atsuishio.superbwarfare.client.gui;
import net.minecraft.core.BlockPos;
import net.minecraft.world.phys.Vec3;
public class RangeHelper {
@ -76,18 +76,18 @@ public class RangeHelper {
return range;
}
public static boolean canReachTarget(double initialVelocity, double gravity, double velocityDecay, BlockPos startPos, BlockPos targetPos, double[] angles) {
public static boolean canReachTarget(double initialVelocity, double gravity, double velocityDecay, Vec3 startPos, Vec3 targetPos, double[] angles) {
if (startPos.equals(targetPos)) {
return false;
}
int startX = startPos.getX();
int startY = startPos.getY();
int startZ = startPos.getZ();
double startX = startPos.x;
double startY = startPos.y;
double startZ = startPos.z;
int targetX = targetPos.getX();
int targetY = targetPos.getY();
int targetZ = targetPos.getZ();
double targetX = targetPos.x;
double targetY = targetPos.y;
double targetZ = targetPos.z;
double distanceXZ = Math.sqrt(Math.pow(targetX - startX, 2) + Math.pow(targetZ - startZ, 2));
if (distanceXZ > MAX_RANGE) {

View file

@ -18,6 +18,7 @@ import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.ClipContext;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.RenderGuiEvent;
@ -84,9 +85,12 @@ public class CannonHudOverlay {
if (ClientEventHandler.zoomVehicle) {
Entity lookingEntity = TraceTool.findLookingEntity(player, 512);
boolean lookAtEntity = false;
double blockRange = player.getEyePosition().distanceTo((Vec3.atLowerCornerOf(player.level().clip(
new ClipContext(player.getEyePosition(), player.getEyePosition().add(player.getLookAngle().scale(512)),
ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, player)).getBlockPos())));
BlockHitResult result = player.level().clip(new ClipContext(player.getEyePosition(), player.getEyePosition().add(player.getViewVector(1).scale(512)),
ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, player));
Vec3 hitPos = result.getLocation();
double blockRange = player.getEyePosition(1).distanceTo(hitPos);
double entityRange = 0;
if (lookingEntity instanceof LivingEntity living) {

View file

@ -21,6 +21,7 @@ import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.ClipContext;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.RenderGuiEvent;
@ -77,9 +78,12 @@ public class DroneUIOverlay {
if (entity != null) {
boolean lookAtEntity = false;
double distance = player.distanceTo(entity);
double blockRange = entity.position().distanceTo((Vec3.atLowerCornerOf(entity.level().clip(
new ClipContext(entity.getEyePosition(), entity.getEyePosition().add(entity.getViewVector(event.getPartialTick()).scale(520)),
ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, entity)).getBlockPos())));
BlockHitResult result = entity.level().clip(new ClipContext(entity.getEyePosition(), entity.getEyePosition().add(player.getViewVector(1).scale(512)),
ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, entity));
Vec3 hitPos = result.getLocation();
double blockRange = player.getEyePosition(1).distanceTo(hitPos);
double entityRange = 0;

View file

@ -98,25 +98,45 @@ public class JavelinHudOverlay {
double zoom = Minecraft.getInstance().options.fov().get() / ClientEventHandler.fov + 0.5 * fovAdjust2;
for (var e : entities) {
Vec3 playerVec = new Vec3(Mth.lerp(event.getPartialTick(), player.xo, player.getX()), Mth.lerp(event.getPartialTick(), player.yo + player.getEyeHeight(), player.getEyeY()), Mth.lerp(event.getPartialTick(), player.zo, player.getZ()));
Vec3 pos = new Vec3(Mth.lerp(event.getPartialTick(), e.xo, e.getX()), Mth.lerp(event.getPartialTick(), e.yo + e.getEyeHeight(), e.getEyeY()), Mth.lerp(event.getPartialTick(), e.zo, e.getZ()));
Vec3 playerVec = new Vec3(Mth.lerp(event.getPartialTick(), player.xo, player.getX()), Mth.lerp(event.getPartialTick(), player.yo + player.getEyeHeight(), player.getEyeY()), Mth.lerp(event.getPartialTick(), player.zo, player.getZ()));
if (stack.getOrCreateTag().getInt("GuideType") == 0) {
for (var e : entities) {
Vec3 pos = new Vec3(Mth.lerp(event.getPartialTick(), e.xo, e.getX()), Mth.lerp(event.getPartialTick(), e.yo + e.getEyeHeight(), e.getEyeY()), Mth.lerp(event.getPartialTick(), e.zo, e.getZ()));
Vec3 lookAngle = player.getLookAngle().normalize().scale(pos.distanceTo(playerVec) * (1 - 1.0 / zoom));
var cPos = playerVec.add(lookAngle);
Vec3 point = RenderHelper.worldToScreen(pos, cPos);
if (point == null) return;
boolean lockOn = stack.getOrCreateTag().getInt("SeekTime") > 20 && e == targetEntity;
boolean nearest = e == naerestEntity;
poseStack.pushPose();
float x = (float) point.x;
float y = (float) point.y;
RenderHelper.blit(poseStack, lockOn ? FRAME_LOCK : nearest ? FRAME_TARGET : FRAME, x - 12, y - 12, 0, 0, 24, 24, 24, 24, 1f);
poseStack.popPose();
}
} else {
Vec3 pos = new Vec3(stack.getOrCreateTag().getDouble("TargetPosX"), stack.getOrCreateTag().getDouble("TargetPosY"), stack.getOrCreateTag().getDouble("TargetPosZ"));
Vec3 lookAngle = player.getLookAngle().normalize().scale(pos.distanceTo(playerVec) * (1 - 1.0 / zoom));
boolean lockOn = stack.getOrCreateTag().getInt("SeekTime") > 20;
var cPos = playerVec.add(lookAngle);
Vec3 point = RenderHelper.worldToScreen(pos, cPos);
if (point == null) return;
boolean lockOn = stack.getOrCreateTag().getInt("SeekTime") > 20 && e == targetEntity;
boolean nearest = e == naerestEntity;
poseStack.pushPose();
float x = (float) point.x;
float y = (float) point.y;
RenderHelper.blit(poseStack, lockOn ? FRAME_LOCK : nearest ? FRAME_TARGET : FRAME, x - 12, y - 12, 0, 0, 24, 24, 24, 24, 1f);
RenderHelper.blit(poseStack, lockOn ? FRAME_LOCK : FRAME_TARGET, x - 12, y - 12, 0, 0, 24, 24, 24, 24, 1f);
poseStack.popPose();
}
} else {
scopeScale = 1;
}

View file

@ -8,6 +8,7 @@ import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.ClipContext;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.RenderGuiEvent;
@ -25,9 +26,12 @@ public class SpyglassRangeOverlay {
Player player = Minecraft.getInstance().player;
if (player != null && (player.getMainHandItem().getItem() == Items.SPYGLASS || player.getOffhandItem().getItem() == Items.SPYGLASS) && player.isUsingItem()) {
boolean lookAtEntity = false;
double blockRange = player.position().distanceTo((Vec3.atLowerCornerOf(player.level().clip(
new ClipContext(player.getEyePosition(), player.getEyePosition().add(player.getLookAngle().scale(520)),
ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, player)).getBlockPos())));
BlockHitResult result = player.level().clip(new ClipContext(player.getEyePosition(), player.getEyePosition().add(player.getViewVector(1).scale(512)),
ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, player));
Vec3 hitPos = result.getLocation();
double blockRange = player.getEyePosition(1).distanceTo(hitPos);
double entityRange = 0;
Entity lookingEntity = TraceTool.findLookingEntity(player, 520);

View file

@ -26,6 +26,7 @@ import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.ClipContext;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.RenderGuiEvent;
@ -268,9 +269,12 @@ public class VehicleHudOverlay {
// 测距
boolean lookAtEntity = false;
double blockRange = cameraPos.distanceTo((Vec3.atLowerCornerOf(player.level().clip(
new ClipContext(player.getEyePosition(), player.getEyePosition().add(iLand.getBarrelVec(event.getPartialTick()).scale(520)),
ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, player)).getBlockPos())));
BlockHitResult result = player.level().clip(new ClipContext(player.getEyePosition(), player.getEyePosition().add(player.getViewVector(1).scale(512)),
ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, player));
Vec3 hitPos = result.getLocation();
double blockRange = player.getEyePosition(1).distanceTo(hitPos);
double entityRange = 0;
@ -484,9 +488,9 @@ public class VehicleHudOverlay {
guiGraphics.drawString(Minecraft.getInstance().font, name.get(), 37, y, 0x66ff00, true);
String num = "[" + (i + 1) + "]";
guiGraphics.drawString(Minecraft.getInstance().font, num, 15 - Minecraft.getInstance().font.width(num), y, 0x66ff00, true);
guiGraphics.drawString(Minecraft.getInstance().font, num, 20 - Minecraft.getInstance().font.width(num), y, 0x66ff00, true);
preciseBlit(guiGraphics, index == passengers.size() - 1 ? DRIVER : PASSENGER, 25, y + 1, 100, 0, 0, 8, 8, 8, 8);
preciseBlit(guiGraphics, index == passengers.size() - 1 ? DRIVER : PASSENGER, 25, y, 100, 0, 0, 8, 8, 8, 8);
index++;
}
}

View file

@ -10,7 +10,6 @@ import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.item.common.ammo.MortarShell;
import net.minecraft.ChatFormatting;
import net.minecraft.commands.arguments.EntityAnchorArgument;
import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
@ -181,16 +180,16 @@ public class MortarEntity extends VehicleEntity implements GeoEntity {
}
public boolean setTarget(ItemStack stack) {
int targetX = stack.getOrCreateTag().getInt("TargetX");
int targetY = stack.getOrCreateTag().getInt("TargetY");
int targetZ = stack.getOrCreateTag().getInt("TargetZ");
double targetX = stack.getOrCreateTag().getDouble("TargetX");
double targetY = stack.getOrCreateTag().getDouble("TargetY");
double targetZ = stack.getOrCreateTag().getDouble("TargetZ");
this.look(EntityAnchorArgument.Anchor.EYES, new Vec3(targetX, targetY, targetZ));
double[] angles = new double[2];
boolean flag = RangeHelper.canReachTarget(11, 0.146, 0.99,
new BlockPos((int) this.getX(), (int) this.getEyeY(), (int) this.getZ()),
new BlockPos(targetX, targetY, targetZ),
boolean flag = RangeHelper.canReachTarget(11.4, 0.146, 0.99,
new Vec3(this.getX(), this.getEyeY(), this.getZ()),
new Vec3(targetX, targetY, targetZ),
angles);
if (flag) {

View file

@ -63,17 +63,22 @@ public class JavelinMissileEntity extends ThrowableItemProjectile implements Geo
private float explosion_damage = 140f;
private float explosion_radius = 6f;
private boolean distracted = false;
private int guide_type = 0;
public JavelinMissileEntity(EntityType<? extends JavelinMissileEntity> type, Level world) {
super(type, world);
this.noCulling = true;
}
public JavelinMissileEntity(LivingEntity entity, Level level, float damage, float explosion_damage, float explosion_radius) {
public JavelinMissileEntity(LivingEntity entity, Level level, float damage, float explosion_damage, float explosion_radius, int guide_type, Vec3 targetPos) {
super(ModEntities.JAVELIN_MISSILE.get(), entity, level);
this.damage = damage;
this.explosion_damage = explosion_damage;
this.explosion_radius = explosion_radius;
this.guide_type = guide_type;
this.entityData.set(TARGET_X, (float) targetPos.x);
this.entityData.set(TARGET_Y, (float) targetPos.y);
this.entityData.set(TARGET_Z, (float) targetPos.z);
}
public JavelinMissileEntity(PlayMessages.SpawnEntity spawnEntity, Level level) {
@ -98,12 +103,6 @@ public class JavelinMissileEntity extends ThrowableItemProjectile implements Geo
this.entityData.set(TARGET_UUID, uuid);
}
public void setTargetPosition(Float targetX, Float targetY, Float targetZ) {
this.entityData.set(TARGET_X, targetX);
this.entityData.set(TARGET_Y, targetY);
this.entityData.set(TARGET_Z, targetZ);
}
public void setAttackMode(boolean mode) {
this.entityData.set(TOP, mode);
}
@ -191,26 +190,57 @@ public class JavelinMissileEntity extends ThrowableItemProjectile implements Geo
}
}
if (entity != null) {
if (entity.level() instanceof ServerLevel) {
this.entityData.set(TARGET_X, (float) entity.getX());
this.entityData.set(TARGET_Y, (float) entity.getY() + 0.5f * entity.getBbHeight());
this.entityData.set(TARGET_Z, (float) entity.getZ());
if ((!entity.getPassengers().isEmpty() || entity instanceof VehicleEntity) && entity.tickCount %((int)Math.max(0.04 * this.distanceTo(entity),2)) == 0) {
entity.level().playSound(null, entity.getOnPos(), entity instanceof Pig ? SoundEvents.PIG_HURT : ModSounds.MISSILE_WARNING.get(), SoundSource.PLAYERS, 2, 1f);
if (guide_type == 0 || !entityData.get(TARGET_UUID).equals("none")) {
if (entity != null) {
if (entity.level() instanceof ServerLevel) {
this.entityData.set(TARGET_X, (float) entity.getX());
this.entityData.set(TARGET_Y, (float) entity.getY() + 0.5f * entity.getBbHeight());
this.entityData.set(TARGET_Z, (float) entity.getZ());
if ((!entity.getPassengers().isEmpty() || entity instanceof VehicleEntity) && entity.tickCount %((int)Math.max(0.04 * this.distanceTo(entity),2)) == 0) {
entity.level().playSound(null, entity.getOnPos(), entity instanceof Pig ? SoundEvents.PIG_HURT : ModSounds.MISSILE_WARNING.get(), SoundSource.PLAYERS, 2, 1f);
}
}
}
}
double px = this.getX();
double ex = this.entityData.get(TARGET_X);
double pz = this.getZ();
double ez = this.entityData.get(TARGET_Z);
boolean dir = Math.sqrt(Math.pow(px - ex, 2) + Math.pow(pz - ez, 2)) < 30;
Vec3 targetPos = new Vec3(this.entityData.get(TARGET_X), this.entityData.get(TARGET_Y) + (entity instanceof EnderDragon ? -3 : 0), this.entityData.get(TARGET_Z));
if (entity != null) {
Vec3 toVec = getEyePosition().vectorTo(targetPos.add(entity.getDeltaMovement().scale(0.5))).normalize();
double px = this.getX();
double ex = this.entityData.get(TARGET_X);
double pz = this.getZ();
double ez = this.entityData.get(TARGET_Z);
boolean dir = Math.sqrt(Math.pow(px - ex, 2) + Math.pow(pz - ez, 2)) < 30;
Vec3 targetPos = new Vec3(this.entityData.get(TARGET_X), this.entityData.get(TARGET_Y) + (entity instanceof EnderDragon ? -3 : 0), this.entityData.get(TARGET_Z));
if (entity != null) {
Vec3 toVec = getEyePosition().vectorTo(targetPos.add(entity.getDeltaMovement().scale(0.5))).normalize();
if (this.tickCount > 3) {
if (entityData.get(TOP)) {
if (!dir) {
Vec3 targetTopPos = new Vec3(this.entityData.get(TARGET_X), this.entityData.get(TARGET_Y) + Mth.clamp(5 * this.tickCount, 0, 90), this.entityData.get(TARGET_Z));
Vec3 toTopVec = getEyePosition().vectorTo(targetTopPos).normalize();
setDeltaMovement(getDeltaMovement().add(toTopVec.scale(0.5)));
} else {
boolean lostTarget = this.getY() < entity.getY();
if (!lostTarget) {
setDeltaMovement(getDeltaMovement().add(toVec.scale(1)).scale(0.87));
}
}
} else {
boolean lostTarget = (VectorTool.calculateAngle(getDeltaMovement(), toVec) > 80);
if (!lostTarget) {
setDeltaMovement(getDeltaMovement().add(toVec.scale(1)).scale(0.87));
}
}
}
}
} else if (guide_type == 1) {
double px = this.getX();
double ex = this.entityData.get(TARGET_X);
double pz = this.getZ();
double ez = this.entityData.get(TARGET_Z);
boolean dir = Math.sqrt(Math.pow(px - ex, 2) + Math.pow(pz - ez, 2)) < 30;
Vec3 targetPos = new Vec3(this.entityData.get(TARGET_X), this.entityData.get(TARGET_Y), this.entityData.get(TARGET_Z));
Vec3 toVec = getEyePosition().vectorTo(targetPos).normalize();
if (this.tickCount > 3) {
if (entityData.get(TOP)) {
if (!dir) {
@ -218,7 +248,7 @@ public class JavelinMissileEntity extends ThrowableItemProjectile implements Geo
Vec3 toTopVec = getEyePosition().vectorTo(targetTopPos).normalize();
setDeltaMovement(getDeltaMovement().add(toTopVec.scale(0.5)));
} else {
boolean lostTarget = this.getY() < entity.getY();
boolean lostTarget = this.getY() < this.entityData.get(TARGET_Y);
if (!lostTarget) {
setDeltaMovement(getDeltaMovement().add(toVec.scale(1)).scale(0.87));
}
@ -230,8 +260,8 @@ public class JavelinMissileEntity extends ThrowableItemProjectile implements Geo
}
}
}
}
}
if (this.tickCount == 4) {
if (!this.level().isClientSide() && this.level() instanceof ServerLevel serverLevel) {

View file

@ -29,9 +29,9 @@ public class FiringParameters extends Item {
if (player == null) return InteractionResult.PASS;
if (player.isShiftKeyDown()) {
stack.getOrCreateTag().putInt("TargetX", pos.getX());
stack.getOrCreateTag().putInt("TargetY", pos.getY());
stack.getOrCreateTag().putInt("TargetZ", pos.getZ());
stack.getOrCreateTag().putDouble("TargetX", pos.getX());
stack.getOrCreateTag().putDouble("TargetY", pos.getY());
stack.getOrCreateTag().putDouble("TargetZ", pos.getZ());
}
return InteractionResult.SUCCESS;

View file

@ -33,6 +33,7 @@ import net.minecraft.world.inventory.tooltip.TooltipComponent;
import net.minecraft.world.item.ItemDisplayContext;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.client.extensions.common.IClientItemExtensions;
import org.jetbrains.annotations.NotNull;
import software.bernie.geckolib.animatable.GeoItem;
@ -146,34 +147,61 @@ public class JavelinItem extends GunItem implements GeoItem {
GunsTool.setGunIntTag(stack, "MaxAmmo", getAmmoCount(player));
if (tag.getBoolean("Seeking")) {
List<Entity> decoy = SeekTool.seekLivingEntities(player, player.level(), 512, 8);
Entity targetEntity = EntityFindUtil.findEntity(player.level(), tag.getString("TargetEntity"));
Entity seekingEntity = SeekTool.seekEntity(player, player.level(), 512, 8);
for (var e : decoy) {
if (e instanceof FlareDecoyEntity flareDecoy) {
tag.putString("TargetEntity", flareDecoy.getStringUUID());
tag.putDouble("TargetPosX", flareDecoy.getX());
tag.putDouble("TargetPosY", flareDecoy.getEyeY());
tag.putDouble("TargetPosZ", flareDecoy.getZ());
}
}
if (seekingEntity != null && seekingEntity == targetEntity) {
tag.putInt("SeekTime", tag.getInt("SeekTime") + 1);
if (tag.getInt("SeekTime") > 0 && (!seekingEntity.getPassengers().isEmpty() || seekingEntity instanceof VehicleEntity) && seekingEntity.tickCount %3 == 0) {
seekingEntity.level().playSound(null, seekingEntity.getOnPos(), seekingEntity instanceof Pig ? SoundEvents.PIG_HURT : ModSounds.LOCKING_WARNING.get(), SoundSource.PLAYERS, 1, 1f);
}
} else {
tag.putInt("SeekTime", 0);
}
Entity targetEntity = EntityFindUtil.findEntity(player.level(), tag.getString("TargetEntity"));
Entity seekingEntity = SeekTool.seekEntity(player, player.level(), 512, 8);
if (tag.getInt("SeekTime") == 1 && player instanceof ServerPlayer serverPlayer) {
SoundTool.playLocalSound(serverPlayer, ModSounds.JAVELIN_LOCK.get(), 1, 1);
}
if (seekingEntity != null && tag.getInt("SeekTime") > 20) {
if (player instanceof ServerPlayer serverPlayer) {
SoundTool.playLocalSound(serverPlayer, ModSounds.JAVELIN_LOCKON.get(), 1, 1);
if (tag.getInt("GuideType") == 0) {
if (seekingEntity != null && seekingEntity == targetEntity) {
tag.putInt("SeekTime", tag.getInt("SeekTime") + 1);
if (tag.getInt("SeekTime") > 0 && (!seekingEntity.getPassengers().isEmpty() || seekingEntity instanceof VehicleEntity) && seekingEntity.tickCount %3 == 0) {
seekingEntity.level().playSound(null, seekingEntity.getOnPos(), seekingEntity instanceof Pig ? SoundEvents.PIG_HURT : ModSounds.LOCKING_WARNING.get(), SoundSource.PLAYERS, 1, 1f);
}
} else {
tag.putInt("SeekTime", 0);
}
if ((!seekingEntity.getPassengers().isEmpty() || seekingEntity instanceof VehicleEntity) && seekingEntity.tickCount %2 == 0) {
seekingEntity.level().playSound(null, seekingEntity.getOnPos(), seekingEntity instanceof Pig ? SoundEvents.PIG_HURT : ModSounds.LOCKED_WARNING.get(), SoundSource.PLAYERS, 1, 0.95f);
if (tag.getInt("SeekTime") == 1 && player instanceof ServerPlayer serverPlayer) {
SoundTool.playLocalSound(serverPlayer, ModSounds.JAVELIN_LOCK.get(), 1, 1);
}
if (seekingEntity != null && tag.getInt("SeekTime") > 20) {
if (player instanceof ServerPlayer serverPlayer) {
SoundTool.playLocalSound(serverPlayer, ModSounds.JAVELIN_LOCKON.get(), 1, 1);
}
if ((!seekingEntity.getPassengers().isEmpty() || seekingEntity instanceof VehicleEntity) && seekingEntity.tickCount %2 == 0) {
seekingEntity.level().playSound(null, seekingEntity.getOnPos(), seekingEntity instanceof Pig ? SoundEvents.PIG_HURT : ModSounds.LOCKED_WARNING.get(), SoundSource.PLAYERS, 1, 0.95f);
}
}
} else if (tag.getInt("GuideType") == 1) {
Vec3 toVec = player.getEyePosition().vectorTo(new Vec3(tag.getDouble("TargetPosX"), tag.getDouble("TargetPosY"), tag.getDouble("TargetPosZ"))).normalize();
if (VectorTool.calculateAngle(player.getViewVector(1), toVec) < 8) {
tag.putInt("SeekTime", tag.getInt("SeekTime") + 1);
} else {
tag.putInt("SeekTime", 0);
}
if (tag.getInt("SeekTime") == 1 && player instanceof ServerPlayer serverPlayer) {
SoundTool.playLocalSound(serverPlayer, ModSounds.JAVELIN_LOCK.get(), 1, 1);
}
if (tag.getInt("SeekTime") > 20) {
if (player instanceof ServerPlayer serverPlayer) {
SoundTool.playLocalSound(serverPlayer, ModSounds.JAVELIN_LOCKON.get(), 1, 1);
}
}
}
}

View file

@ -11,6 +11,7 @@ import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.ClipContext;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.network.NetworkEvent;
@ -50,20 +51,23 @@ public class DroneFireMessage {
boolean lookAtEntity = false;
Entity lookingEntity = SeekTool.seekLivingEntity(drone, drone.level(), 512, 2);
Vec3 looking = Vec3.atLowerCornerOf(player.level().clip(new ClipContext(drone.getEyePosition(), drone.getEyePosition().add(drone.getLookAngle().scale(512)), ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, player)).getBlockPos());
BlockHitResult result = drone.level().clip(new ClipContext(drone.getEyePosition(), drone.getEyePosition().add(drone.getViewVector(1).scale(512)),
ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, drone));
Vec3 hitPos = result.getLocation();
if (lookingEntity != null) {
lookAtEntity = true;
}
if (lookAtEntity) {
offStack.getOrCreateTag().putInt("TargetX", (int) lookingEntity.getX());
offStack.getOrCreateTag().putInt("TargetY", (int) lookingEntity.getY());
offStack.getOrCreateTag().putInt("TargetZ", (int) lookingEntity.getZ());
offStack.getOrCreateTag().putDouble("TargetX", lookingEntity.getX());
offStack.getOrCreateTag().putDouble("TargetY", lookingEntity.getY());
offStack.getOrCreateTag().putDouble("TargetZ", lookingEntity.getZ());
} else {
offStack.getOrCreateTag().putInt("TargetX", (int) looking.x());
offStack.getOrCreateTag().putInt("TargetY", (int) looking.y());
offStack.getOrCreateTag().putInt("TargetZ", (int) looking.z());
offStack.getOrCreateTag().putDouble("TargetX", hitPos.x());
offStack.getOrCreateTag().putDouble("TargetY", hitPos.y());
offStack.getOrCreateTag().putDouble("TargetZ", hitPos.z());
}
player.displayClientMessage(Component.translatable("tips.superbwarfare.mortar.target_pos").withStyle(ChatFormatting.GRAY)

View file

@ -11,7 +11,10 @@ import com.atsuishio.superbwarfare.network.ModVariables;
import com.atsuishio.superbwarfare.perk.AmmoPerk;
import com.atsuishio.superbwarfare.perk.Perk;
import com.atsuishio.superbwarfare.perk.PerkHelper;
import com.atsuishio.superbwarfare.tools.*;
import com.atsuishio.superbwarfare.tools.GunsTool;
import com.atsuishio.superbwarfare.tools.ParticleTool;
import com.atsuishio.superbwarfare.tools.SeekTool;
import com.atsuishio.superbwarfare.tools.SoundTool;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.FriendlyByteBuf;
@ -27,7 +30,10 @@ import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.ClipContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.common.capabilities.ForgeCapabilities;
import net.minecraftforge.network.NetworkEvent;
import net.minecraftforge.network.PacketDistributor;
@ -127,10 +133,23 @@ public class FireMessage {
if (stack.getItem() == ModItems.JAVELIN.get() && player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null)
.orElse(new ModVariables.PlayerVariables()).zoom && GunsTool.getGunIntTag(stack, "Ammo", 0) > 0) {
Entity seekingEntity = SeekTool.seekEntity(player, player.level(), 512, 8);
if (seekingEntity != null) {
if (seekingEntity != null && !player.isCrouching()) {
tag.putInt("GuideType", 0);
tag.putString("TargetEntity", seekingEntity.getStringUUID());
tag.putBoolean("Seeking", true);
tag.putInt("SeekTime", 0);
} else {
BlockHitResult result = player.level().clip(new ClipContext(player.getEyePosition(), player.getEyePosition().add(player.getViewVector(1).scale(512)),
ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, player));
Vec3 hitPos = result.getLocation();
tag.putInt("GuideType", 1);
tag.putDouble("TargetPosX", hitPos.x);
tag.putDouble("TargetPosY", hitPos.y);
tag.putDouble("TargetPosZ", hitPos.z);
tag.putBoolean("Seeking", true);
tag.putInt("SeekTime", 0);
}
}
@ -506,7 +525,9 @@ public class FireMessage {
JavelinMissileEntity missileEntity = new JavelinMissileEntity(player, level,
(float) GunsTool.getGunDoubleTag(stack, "Damage", 0),
(float) GunsTool.getGunDoubleTag(stack, "ExplosionDamage", 0),
(float) GunsTool.getGunDoubleTag(stack, "ExplosionRadius", 0));
(float) GunsTool.getGunDoubleTag(stack, "ExplosionRadius", 0),
stack.getOrCreateTag().getInt("GuideType"),
new Vec3(stack.getOrCreateTag().getDouble("TargetPosX"), stack.getOrCreateTag().getDouble("TargetPosY"), stack.getOrCreateTag().getDouble("TargetPosZ")));
var dmgPerk = PerkHelper.getPerkByType(stack, Perk.Type.DAMAGE);
if (dmgPerk == ModPerks.MONSTER_HUNTER.get()) {
@ -514,15 +535,11 @@ public class FireMessage {
missileEntity.setMonsterMultiplier(0.1f + 0.1f * perkLevel);
}
Entity targetEntity = EntityFindUtil.findEntity(player.level(), tag.getString("TargetEntity"));
missileEntity.setPos(player.getX() + firePos.x, player.getEyeY() + firePos.y, player.getZ() + firePos.z);
missileEntity.shoot(player.getLookAngle().x, player.getLookAngle().y + 0.3, player.getLookAngle().z, 3f, 1);
missileEntity.setTargetUuid(tag.getString("TargetEntity"));
missileEntity.setAttackMode(tag.getBoolean("TopMode"));
if (targetEntity != null) {
missileEntity.setTargetPosition((float) targetEntity.getX(), (float) targetEntity.getEyeY(), (float) targetEntity.getZ());
}
level.addFreshEntity(missileEntity);
}

View file

@ -8,6 +8,7 @@ import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.ClipContext;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.network.NetworkEvent;
@ -39,20 +40,22 @@ public class SetFiringParametersMessage {
boolean lookAtEntity = false;
Entity lookingEntity = TraceTool.findLookingEntity(player, 520);
Vec3 looking = Vec3.atLowerCornerOf(player.level().clip(new ClipContext(player.getEyePosition(), player.getEyePosition().add(player.getLookAngle().scale(512)), ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, player)).getBlockPos());
BlockHitResult result = player.level().clip(new ClipContext(player.getEyePosition(), player.getEyePosition().add(player.getViewVector(1).scale(512)),
ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, player));
Vec3 hitPos = result.getLocation();
if (lookingEntity != null) {
lookAtEntity = true;
}
if (lookAtEntity) {
stack.getOrCreateTag().putInt("TargetX", (int) lookingEntity.getX());
stack.getOrCreateTag().putInt("TargetY", (int) lookingEntity.getY());
stack.getOrCreateTag().putInt("TargetZ", (int) lookingEntity.getZ());
stack.getOrCreateTag().putDouble("TargetX", lookingEntity.getX());
stack.getOrCreateTag().putDouble("TargetY", lookingEntity.getY());
stack.getOrCreateTag().putDouble("TargetZ", lookingEntity.getZ());
} else {
stack.getOrCreateTag().putInt("TargetX", (int) looking.x());
stack.getOrCreateTag().putInt("TargetY", (int) looking.y());
stack.getOrCreateTag().putInt("TargetZ", (int) looking.z());
stack.getOrCreateTag().putDouble("TargetX", hitPos.x());
stack.getOrCreateTag().putDouble("TargetY", hitPos.y());
stack.getOrCreateTag().putDouble("TargetZ", hitPos.z());
}
player.displayClientMessage(Component.translatable("tips.superbwarfare.mortar.target_pos").withStyle(ChatFormatting.GRAY)