调整63式弹药显示方式
This commit is contained in:
parent
3411cb80be
commit
9d7353dd85
4 changed files with 87 additions and 76 deletions
|
@ -3,6 +3,7 @@ package com.atsuishio.superbwarfare.client.overlay;
|
|||
import com.atsuishio.superbwarfare.Mod;
|
||||
import com.atsuishio.superbwarfare.component.ModDataComponents;
|
||||
import com.atsuishio.superbwarfare.entity.vehicle.Type63Entity;
|
||||
import com.atsuishio.superbwarfare.init.ModItems;
|
||||
import com.atsuishio.superbwarfare.item.FiringParameters;
|
||||
import com.atsuishio.superbwarfare.tools.*;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
|
@ -21,7 +22,8 @@ import net.minecraft.world.entity.Entity;
|
|||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.neoforged.neoforge.capabilities.Capabilities;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.api.distmarker.OnlyIn;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static com.atsuishio.superbwarfare.entity.vehicle.Type63Entity.SHOOT_PITCH;
|
||||
|
@ -29,6 +31,7 @@ import static com.atsuishio.superbwarfare.entity.vehicle.Type63Entity.SHOOT_YAW;
|
|||
import static com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity.getXRotFromVector;
|
||||
import static com.atsuishio.superbwarfare.tools.RangeTool.calculateLaunchVector;
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public class Type63InfoOverlay implements LayeredDraw.Layer {
|
||||
|
||||
public static final ResourceLocation ID = Mod.loc("type_63_info");
|
||||
|
@ -39,99 +42,99 @@ public class Type63InfoOverlay implements LayeredDraw.Layer {
|
|||
Player player = mc.player;
|
||||
Camera camera = mc.gameRenderer.getMainCamera();
|
||||
Vec3 cameraPos = camera.getPosition();
|
||||
Vec3 viewVec = new Vec3(camera.getLookVector());
|
||||
PoseStack poseStack = guiGraphics.pose();
|
||||
|
||||
if (player == null) return;
|
||||
|
||||
var screenWidth = guiGraphics.guiWidth();
|
||||
var screenHeight = guiGraphics.guiHeight();
|
||||
var partialTick = deltaTracker.getGameTimeDeltaPartialTick(true);
|
||||
|
||||
Entity lookingEntity;
|
||||
if (player != null) {
|
||||
lookingEntity = TraceTool.findLookingEntity(player, player.entityInteractionRange());
|
||||
Entity lookingEntity = TraceTool.findLookingEntity(player, player.entityInteractionRange());
|
||||
|
||||
if (lookingEntity instanceof Type63Entity type63Entity) {
|
||||
guiGraphics.drawString(Minecraft.getInstance().font, Component.translatable("tips.superbwarfare.mortar.pitch")
|
||||
.append(Component.literal(FormatTool.format2D(type63Entity.getEntityData().get(SHOOT_PITCH), "°"))),
|
||||
screenWidth / 2 - 130, screenHeight / 2 - 26, -1, false);
|
||||
guiGraphics.drawString(Minecraft.getInstance().font, Component.translatable("tips.superbwarfare.mortar.yaw")
|
||||
.append(Component.literal(FormatTool.format2D(type63Entity.getEntityData().get(SHOOT_YAW), "°"))),
|
||||
screenWidth / 2 - 130, screenHeight / 2 - 16, -1, false);
|
||||
guiGraphics.drawString(Minecraft.getInstance().font, Component.translatable("tips.superbwarfare.mortar.range")
|
||||
.append(Component.literal(FormatTool.format1D((int) RangeTool.getRange(type63Entity.getEntityData().get(SHOOT_PITCH), 10, 0.05), "m"))),
|
||||
screenWidth / 2 - 130, screenHeight / 2 - 6, -1, false);
|
||||
if (!(lookingEntity instanceof Type63Entity type63Entity)) return;
|
||||
guiGraphics.drawString(Minecraft.getInstance().font, Component.translatable("tips.superbwarfare.mortar.pitch")
|
||||
.append(Component.literal(FormatTool.format2D(type63Entity.getEntityData().get(SHOOT_PITCH), "°"))),
|
||||
screenWidth / 2 - 130, screenHeight / 2 - 26, -1, false);
|
||||
guiGraphics.drawString(Minecraft.getInstance().font, Component.translatable("tips.superbwarfare.mortar.yaw")
|
||||
.append(Component.literal(FormatTool.format2D(type63Entity.getEntityData().get(SHOOT_YAW), "°"))),
|
||||
screenWidth / 2 - 130, screenHeight / 2 - 16, -1, false);
|
||||
guiGraphics.drawString(Minecraft.getInstance().font, Component.translatable("tips.superbwarfare.mortar.range")
|
||||
.append(Component.literal(FormatTool.format1D((int) RangeTool.getRange(type63Entity.getEntityData().get(SHOOT_PITCH), 10, 0.05), "m"))),
|
||||
screenWidth / 2 - 130, screenHeight / 2 - 6, -1, false);
|
||||
|
||||
var itemHandler = type63Entity.getCapability(Capabilities.ItemHandler.ENTITY);
|
||||
var items = type63Entity.getEntityData().get(Type63Entity.LOADED_AMMO);
|
||||
for (int i = 0; i < type63Entity.barrel.length; i++) {
|
||||
if (OBB.getLookingObb(player, player.entityInteractionRange()) == type63Entity.barrel[i]) {
|
||||
int type = items.get(i);
|
||||
if (type == -1) return;
|
||||
|
||||
// TODO 正确读取item
|
||||
ItemStack stack = switch (type) {
|
||||
case 0 -> new ItemStack(ModItems.MEDIUM_ROCKET_AP.get());
|
||||
case 1 -> new ItemStack(ModItems.MEDIUM_ROCKET_HE.get());
|
||||
case 2 -> new ItemStack(ModItems.MEDIUM_ROCKET_CM.get());
|
||||
default -> ItemStack.EMPTY;
|
||||
};
|
||||
if (stack.isEmpty()) return;
|
||||
|
||||
for (int i = 0; i < type63Entity.barrel.length; i++) {
|
||||
if (OBB.getLookingObb(player, player.entityInteractionRange()) == type63Entity.barrel[i]) {
|
||||
ItemStack stack = itemHandler.getStackInSlot(i);
|
||||
Vec3 pos = new Vec3(type63Entity.barrel[i].center());
|
||||
Vec3 point = VectorUtil.worldToScreen(pos, cameraPos);
|
||||
if (point == null) return;
|
||||
|
||||
Vec3 pos = new Vec3(type63Entity.barrel[i].center());
|
||||
Vec3 point = VectorUtil.worldToScreen(pos, cameraPos);
|
||||
if (point == null) return;
|
||||
poseStack.pushPose();
|
||||
float x = (float) point.x;
|
||||
float y = (float) point.y;
|
||||
poseStack.translate(x, y, 0);
|
||||
|
||||
poseStack.pushPose();
|
||||
float x = (float) point.x;
|
||||
float y = (float) point.y;
|
||||
poseStack.translate(x, y, 0);
|
||||
var component = Component.literal("[").append(stack.getHoverName()).append("]");
|
||||
int width = Minecraft.getInstance().font.width(component);
|
||||
guiGraphics.drawString(Minecraft.getInstance().font, component, -width / 2, -4, -1, false);
|
||||
|
||||
String info = stack.getDisplayName().getString();
|
||||
int width = Minecraft.getInstance().font.width(info);
|
||||
|
||||
guiGraphics.drawString(Minecraft.getInstance().font, Component.literal(stack.getDisplayName().getString()),
|
||||
-width / 2, -4, -1, false);
|
||||
|
||||
poseStack.popPose();
|
||||
poseStack.popPose();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ItemStack stack = player.getOffhandItem();
|
||||
if (stack.getItem() instanceof FiringParameters) {
|
||||
var parameters = stack.get(ModDataComponents.FIRING_PARAMETERS);
|
||||
if (parameters == null) {
|
||||
parameters = new FiringParameters.Parameters(new BlockPos(0, 0, 0));
|
||||
}
|
||||
double targetX = parameters.pos().getX();
|
||||
double targetY = parameters.pos().getY() - 1;
|
||||
double targetZ = parameters.pos().getZ();
|
||||
boolean isDepressed = parameters.isDepressed();
|
||||
ItemStack stack = player.getOffhandItem();
|
||||
if (stack.getItem() instanceof FiringParameters) {
|
||||
var parameters = stack.get(ModDataComponents.FIRING_PARAMETERS);
|
||||
if (parameters == null) {
|
||||
parameters = new FiringParameters.Parameters(new BlockPos(0, 0, 0));
|
||||
}
|
||||
double targetX = parameters.pos().getX();
|
||||
double targetY = parameters.pos().getY() - 1;
|
||||
double targetZ = parameters.pos().getZ();
|
||||
boolean isDepressed = parameters.isDepressed();
|
||||
|
||||
Vec3 targetPos = new Vec3(targetX, targetY, targetZ);
|
||||
Vec3 launchVector = calculateLaunchVector(type63Entity.getShootPos(partialTick), targetPos, 10, -0.05, isDepressed);
|
||||
Vec3 targetPos = new Vec3(targetX, targetY, targetZ);
|
||||
Vec3 launchVector = calculateLaunchVector(type63Entity.getShootPos(partialTick), targetPos, 10, -0.05, isDepressed);
|
||||
|
||||
Vec3 vec3 = EntityAnchorArgument.Anchor.EYES.apply(lookingEntity);
|
||||
double d0 = (targetPos.x - vec3.x) * 0.2;
|
||||
double d2 = (targetPos.z - vec3.z) * 0.2;
|
||||
double targetYaw = Mth.wrapDegrees((float) (Mth.atan2(d2, d0) * 57.2957763671875) - 90.0F);
|
||||
Vec3 vec3 = EntityAnchorArgument.Anchor.EYES.apply(lookingEntity);
|
||||
double d0 = (targetPos.x - vec3.x) * 0.2;
|
||||
double d2 = (targetPos.z - vec3.z) * 0.2;
|
||||
double targetYaw = Mth.wrapDegrees((float) (Mth.atan2(d2, d0) * 57.2957763671875) - 90.0F);
|
||||
|
||||
float angle = 0;
|
||||
float angle = 0;
|
||||
|
||||
if (launchVector != null) {
|
||||
angle = (float) getXRotFromVector(launchVector);
|
||||
}
|
||||
|
||||
if (angle > -5 && angle < 60) {
|
||||
guiGraphics.drawString(Minecraft.getInstance().font, Component.translatable("tips.superbwarfare.target.pitch")
|
||||
.append(Component.literal(FormatTool.format2D(angle, "°"))),
|
||||
screenWidth / 2 + 90, screenHeight / 2 - 26, -1, false);
|
||||
guiGraphics.drawString(Minecraft.getInstance().font, Component.translatable("tips.superbwarfare.target.yaw")
|
||||
.append(Component.literal(FormatTool.format2D(targetYaw, "°"))),
|
||||
screenWidth / 2 + 90, screenHeight / 2 - 16, -1, false);
|
||||
guiGraphics.drawString(Minecraft.getInstance().font, Component.translatable("tips.superbwarfare.mortar.target_pos")
|
||||
.append(Component.literal(FormatTool.format0D(targetX) + " " + FormatTool.format0D(targetY) + " " + FormatTool.format0D(targetZ))),
|
||||
screenWidth / 2 + 90, screenHeight / 2 - 6, -1, false);
|
||||
} else {
|
||||
guiGraphics.drawString(Minecraft.getInstance().font, Component.translatable("tips.superbwarfare.mortar.warn", lookingEntity.getDisplayName()).withStyle(ChatFormatting.RED),
|
||||
screenWidth / 2 + 90, screenHeight / 2 - 26, -1, false);
|
||||
}
|
||||
}
|
||||
if (launchVector != null) {
|
||||
angle = (float) getXRotFromVector(launchVector);
|
||||
}
|
||||
|
||||
if (angle > -5 && angle < 60) {
|
||||
guiGraphics.drawString(Minecraft.getInstance().font, Component.translatable("tips.superbwarfare.target.pitch")
|
||||
.append(Component.literal(FormatTool.format2D(angle, "°"))),
|
||||
screenWidth / 2 + 90, screenHeight / 2 - 26, -1, false);
|
||||
guiGraphics.drawString(Minecraft.getInstance().font, Component.translatable("tips.superbwarfare.target.yaw")
|
||||
.append(Component.literal(FormatTool.format2D(targetYaw, "°"))),
|
||||
screenWidth / 2 + 90, screenHeight / 2 - 16, -1, false);
|
||||
guiGraphics.drawString(Minecraft.getInstance().font, Component.translatable("tips.superbwarfare.mortar.target_pos")
|
||||
.append(Component.literal(FormatTool.format0D(targetX) + " " + FormatTool.format0D(targetY) + " " + FormatTool.format0D(targetZ))),
|
||||
screenWidth / 2 + 90, screenHeight / 2 - 6, -1, false);
|
||||
} else {
|
||||
guiGraphics.drawString(Minecraft.getInstance().font, Component.translatable("tips.superbwarfare.mortar.warn", lookingEntity.getDisplayName()).withStyle(ChatFormatting.RED),
|
||||
screenWidth / 2 + 90, screenHeight / 2 - 26, -1, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -76,7 +76,7 @@ public class Type63Renderer extends GeoEntityRenderer<Type63Entity> {
|
|||
for (int i = 0; i < 12; i++) {
|
||||
var items = animatable.getEntityData().get(LOADED_AMMO);
|
||||
if (name.equals("shell" + i)) {
|
||||
bone.setHidden(items.get(i) == 0);
|
||||
bone.setHidden(items.get(i) == -1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -111,7 +111,7 @@ public class Type63Entity extends ContainerMobileVehicleEntity implements GeoEnt
|
|||
super.defineSynchedData(builder);
|
||||
var list = new ArrayList<Integer>();
|
||||
for (int i = 0; i < this.getContainerSize(); i++) {
|
||||
list.add(0);
|
||||
list.add(-1);
|
||||
}
|
||||
|
||||
builder.define(PITCH, 0F)
|
||||
|
@ -533,6 +533,14 @@ public class Type63Entity extends ContainerMobileVehicleEntity implements GeoEnt
|
|||
|
||||
@Override
|
||||
public void setChanged() {
|
||||
this.entityData.set(LOADED_AMMO, this.items.stream().map(i -> i.isEmpty() ? 0 : 1).toList());
|
||||
var list = new ArrayList<Integer>();
|
||||
for (var item : this.items) {
|
||||
if (item.getItem() instanceof MediumRocketItem mediumRocketItem) {
|
||||
list.add(mediumRocketItem.type.ordinal());
|
||||
} else {
|
||||
list.add(-1);
|
||||
}
|
||||
}
|
||||
this.entityData.set(LOADED_AMMO, list);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ public class MediumRocketItem extends Item implements ProjectileItem {
|
|||
private final float explosionDamage;
|
||||
private final float fireProbability;
|
||||
private final int fireTime;
|
||||
private final MediumRocketEntity.Type type;
|
||||
public final MediumRocketEntity.Type type;
|
||||
private final int sparedAmount;
|
||||
|
||||
public MediumRocketItem(float damage, float radius, float explosionDamage, float fireProbability, int fireTime, MediumRocketEntity.Type type, int sparedAmount) {
|
||||
|
|
Loading…
Add table
Reference in a new issue