调整锁定框渲染
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.eventbus.api.SubscribeEvent;
|
||||||
import net.minecraftforge.fml.common.Mod;
|
import net.minecraftforge.fml.common.Mod;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import static com.atsuishio.superbwarfare.client.RenderHelper.preciseBlit;
|
import static com.atsuishio.superbwarfare.client.RenderHelper.preciseBlit;
|
||||||
|
|
||||||
@Mod.EventBusSubscriber(value = Dist.CLIENT)
|
@Mod.EventBusSubscriber(value = Dist.CLIENT)
|
||||||
|
@ -87,26 +89,27 @@ public class JavelinHudOverlay {
|
||||||
RenderSystem.setShaderColor(1, 1, 1, 1);
|
RenderSystem.setShaderColor(1, 1, 1, 1);
|
||||||
|
|
||||||
Entity targetEntity = EntityFindUtil.findEntity(player.level(), stack.getOrCreateTag().getString("TargetEntity"));
|
Entity targetEntity = EntityFindUtil.findEntity(player.level(), stack.getOrCreateTag().getString("TargetEntity"));
|
||||||
Entity seekingEntity = SeekTool.seekEntity(player, player.level(), 512, 8);
|
List<Entity> entities = SeekTool.seekLivingEntities(player, player.level(), 512, 10);
|
||||||
|
|
||||||
if (seekingEntity == null) return;
|
|
||||||
|
|
||||||
double zoom = 3.6;
|
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);
|
for (var e : entities) {
|
||||||
Vec3 p = RenderHelper.worldToScreen(pos, cameraPos);
|
Vec3 pos = new Vec3(e.getX(), e.getEyeY(), e.getZ());
|
||||||
if (p == null) return;
|
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();
|
boolean lockOn = stack.getOrCreateTag().getInt("SeekTime") > 20 && e == targetEntity;
|
||||||
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.pushPose();
|
||||||
poseStack.popPose();
|
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 {
|
} else {
|
||||||
scopeScale = 1;
|
scopeScale = 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ import net.minecraft.world.phys.HitResult;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
import java.util.stream.StreamSupport;
|
import java.util.stream.StreamSupport;
|
||||||
|
|
||||||
public class SeekTool {
|
public class SeekTool {
|
||||||
|
@ -49,6 +50,22 @@ public class SeekTool {
|
||||||
}).min(Comparator.comparingDouble(e -> calculateAngle(e, entity))).orElse(null);
|
}).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) {
|
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 start = new Vec3(entityA.getX() - entityB.getX(), entityA.getY() - entityB.getY(), entityA.getZ() - entityB.getZ());
|
||||||
Vec3 end = entityB.getLookAngle();
|
Vec3 end = entityB.getLookAngle();
|
||||||
|
|
Loading…
Add table
Reference in a new issue