调整锁定框渲染
This commit is contained in:
parent
c392b62a97
commit
c906c587b0
2 changed files with 34 additions and 14 deletions
|
@ -27,6 +27,8 @@ import net.minecraftforge.eventbus.api.EventPriority;
|
|||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.atsuishio.superbwarfare.client.RenderHelper.preciseBlit;
|
||||
|
||||
@Mod.EventBusSubscriber(value = Dist.CLIENT)
|
||||
|
@ -87,26 +89,27 @@ public class JavelinHudOverlay {
|
|||
RenderSystem.setShaderColor(1, 1, 1, 1);
|
||||
|
||||
Entity targetEntity = EntityFindUtil.findEntity(player.level(), stack.getOrCreateTag().getString("TargetEntity"));
|
||||
Entity seekingEntity = SeekTool.seekEntity(player, player.level(), 512, 8);
|
||||
|
||||
if (seekingEntity == null) return;
|
||||
List<Entity> entities = SeekTool.seekLivingEntities(player, player.level(), 512, 10);
|
||||
|
||||
double zoom = 3.6;
|
||||
Vec3 pos = new Vec3(seekingEntity.getX(), seekingEntity.getEyeY(), seekingEntity.getZ());
|
||||
Vec3 lookAngle = player.getLookAngle().normalize().scale(pos.distanceTo(cameraPos) * (1 - 1.0 / zoom));
|
||||
|
||||
cameraPos = cameraPos.add(lookAngle);
|
||||
Vec3 p = RenderHelper.worldToScreen(pos, cameraPos);
|
||||
if (p == null) return;
|
||||
for (var e : entities) {
|
||||
Vec3 pos = new Vec3(e.getX(), e.getEyeY(), e.getZ());
|
||||
Vec3 lookAngle = player.getLookAngle().normalize().scale(pos.distanceTo(cameraPos) * (1 - 1.0 / zoom));
|
||||
|
||||
boolean lockOn = stack.getOrCreateTag().getInt("SeekTime") > 20 && seekingEntity == targetEntity;
|
||||
var cPos = cameraPos.add(lookAngle);
|
||||
Vec3 p = RenderHelper.worldToScreen(pos, cPos);
|
||||
if (p == null) return;
|
||||
|
||||
poseStack.pushPose();
|
||||
int x = (int) p.x;
|
||||
int y = (int) p.y;
|
||||
boolean lockOn = stack.getOrCreateTag().getInt("SeekTime") > 20 && e == targetEntity;
|
||||
|
||||
HudUtil.blit(poseStack, lockOn ? FRAME_LOCK : FRAME, x - 12, y - 12, 0, 0, 24, 24, 24, 24, 1f);
|
||||
poseStack.popPose();
|
||||
poseStack.pushPose();
|
||||
int x = (int) p.x;
|
||||
int y = (int) p.y;
|
||||
|
||||
HudUtil.blit(poseStack, lockOn ? FRAME_LOCK : FRAME, x - 12, y - 12, 0, 0, 24, 24, 24, 24, 1f);
|
||||
poseStack.popPose();
|
||||
}
|
||||
} else {
|
||||
scopeScale = 1;
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import net.minecraft.world.phys.HitResult;
|
|||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
public class SeekTool {
|
||||
|
@ -49,6 +50,22 @@ public class SeekTool {
|
|||
}).min(Comparator.comparingDouble(e -> calculateAngle(e, entity))).orElse(null);
|
||||
}
|
||||
|
||||
public static List<Entity> seekLivingEntities(Entity entity, Level level, double seekRange, double seekAngle) {
|
||||
return StreamSupport.stream(EntityFindUtil.getEntities(level).getAll().spliterator(), false)
|
||||
.filter(e -> {
|
||||
if (e.distanceTo(entity) <= seekRange && calculateAngle(e, entity) < seekAngle
|
||||
&& e != entity
|
||||
&& e.isAlive()
|
||||
&& (e instanceof LivingEntity || e instanceof IVehicleEntity)
|
||||
&& !(e instanceof Player player && (player.isCreative() || player.isSpectator()))
|
||||
&& (!e.isAlliedTo(entity) || e.getTeam() == null || e.getTeam().getName().equals("TDM"))) {
|
||||
return level.clip(new ClipContext(entity.getEyePosition(), e.getEyePosition(),
|
||||
ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, entity)).getType() != HitResult.Type.BLOCK;
|
||||
}
|
||||
return false;
|
||||
}).toList();
|
||||
}
|
||||
|
||||
private static double calculateAngle(Entity entityA, Entity entityB) {
|
||||
Vec3 start = new Vec3(entityA.getX() - entityB.getX(), entityA.getY() - entityB.getY(), entityA.getZ() - entityB.getZ());
|
||||
Vec3 end = entityB.getLookAngle();
|
||||
|
|
Loading…
Add table
Reference in a new issue