调整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.Mod;
|
||||||
import com.atsuishio.superbwarfare.component.ModDataComponents;
|
import com.atsuishio.superbwarfare.component.ModDataComponents;
|
||||||
import com.atsuishio.superbwarfare.entity.vehicle.Type63Entity;
|
import com.atsuishio.superbwarfare.entity.vehicle.Type63Entity;
|
||||||
|
import com.atsuishio.superbwarfare.init.ModItems;
|
||||||
import com.atsuishio.superbwarfare.item.FiringParameters;
|
import com.atsuishio.superbwarfare.item.FiringParameters;
|
||||||
import com.atsuishio.superbwarfare.tools.*;
|
import com.atsuishio.superbwarfare.tools.*;
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
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.entity.player.Player;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.phys.Vec3;
|
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 org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import static com.atsuishio.superbwarfare.entity.vehicle.Type63Entity.SHOOT_PITCH;
|
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.entity.vehicle.base.VehicleEntity.getXRotFromVector;
|
||||||
import static com.atsuishio.superbwarfare.tools.RangeTool.calculateLaunchVector;
|
import static com.atsuishio.superbwarfare.tools.RangeTool.calculateLaunchVector;
|
||||||
|
|
||||||
|
@OnlyIn(Dist.CLIENT)
|
||||||
public class Type63InfoOverlay implements LayeredDraw.Layer {
|
public class Type63InfoOverlay implements LayeredDraw.Layer {
|
||||||
|
|
||||||
public static final ResourceLocation ID = Mod.loc("type_63_info");
|
public static final ResourceLocation ID = Mod.loc("type_63_info");
|
||||||
|
@ -39,18 +42,17 @@ public class Type63InfoOverlay implements LayeredDraw.Layer {
|
||||||
Player player = mc.player;
|
Player player = mc.player;
|
||||||
Camera camera = mc.gameRenderer.getMainCamera();
|
Camera camera = mc.gameRenderer.getMainCamera();
|
||||||
Vec3 cameraPos = camera.getPosition();
|
Vec3 cameraPos = camera.getPosition();
|
||||||
Vec3 viewVec = new Vec3(camera.getLookVector());
|
|
||||||
PoseStack poseStack = guiGraphics.pose();
|
PoseStack poseStack = guiGraphics.pose();
|
||||||
|
|
||||||
|
if (player == null) return;
|
||||||
|
|
||||||
var screenWidth = guiGraphics.guiWidth();
|
var screenWidth = guiGraphics.guiWidth();
|
||||||
var screenHeight = guiGraphics.guiHeight();
|
var screenHeight = guiGraphics.guiHeight();
|
||||||
var partialTick = deltaTracker.getGameTimeDeltaPartialTick(true);
|
var partialTick = deltaTracker.getGameTimeDeltaPartialTick(true);
|
||||||
|
|
||||||
Entity lookingEntity;
|
Entity lookingEntity = TraceTool.findLookingEntity(player, player.entityInteractionRange());
|
||||||
if (player != null) {
|
|
||||||
lookingEntity = TraceTool.findLookingEntity(player, player.entityInteractionRange());
|
|
||||||
|
|
||||||
if (lookingEntity instanceof Type63Entity type63Entity) {
|
if (!(lookingEntity instanceof Type63Entity type63Entity)) return;
|
||||||
guiGraphics.drawString(Minecraft.getInstance().font, Component.translatable("tips.superbwarfare.mortar.pitch")
|
guiGraphics.drawString(Minecraft.getInstance().font, Component.translatable("tips.superbwarfare.mortar.pitch")
|
||||||
.append(Component.literal(FormatTool.format2D(type63Entity.getEntityData().get(SHOOT_PITCH), "°"))),
|
.append(Component.literal(FormatTool.format2D(type63Entity.getEntityData().get(SHOOT_PITCH), "°"))),
|
||||||
screenWidth / 2 - 130, screenHeight / 2 - 26, -1, false);
|
screenWidth / 2 - 130, screenHeight / 2 - 26, -1, false);
|
||||||
|
@ -61,13 +63,19 @@ public class Type63InfoOverlay implements LayeredDraw.Layer {
|
||||||
.append(Component.literal(FormatTool.format1D((int) RangeTool.getRange(type63Entity.getEntityData().get(SHOOT_PITCH), 10, 0.05), "m"))),
|
.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);
|
screenWidth / 2 - 130, screenHeight / 2 - 6, -1, false);
|
||||||
|
|
||||||
var itemHandler = type63Entity.getCapability(Capabilities.ItemHandler.ENTITY);
|
var items = type63Entity.getEntityData().get(Type63Entity.LOADED_AMMO);
|
||||||
|
|
||||||
// TODO 正确读取item
|
|
||||||
|
|
||||||
for (int i = 0; i < type63Entity.barrel.length; i++) {
|
for (int i = 0; i < type63Entity.barrel.length; i++) {
|
||||||
if (OBB.getLookingObb(player, player.entityInteractionRange()) == type63Entity.barrel[i]) {
|
if (OBB.getLookingObb(player, player.entityInteractionRange()) == type63Entity.barrel[i]) {
|
||||||
ItemStack stack = itemHandler.getStackInSlot(i);
|
int type = items.get(i);
|
||||||
|
if (type == -1) return;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
Vec3 pos = new Vec3(type63Entity.barrel[i].center());
|
Vec3 pos = new Vec3(type63Entity.barrel[i].center());
|
||||||
Vec3 point = VectorUtil.worldToScreen(pos, cameraPos);
|
Vec3 point = VectorUtil.worldToScreen(pos, cameraPos);
|
||||||
|
@ -78,11 +86,9 @@ public class Type63InfoOverlay implements LayeredDraw.Layer {
|
||||||
float y = (float) point.y;
|
float y = (float) point.y;
|
||||||
poseStack.translate(x, y, 0);
|
poseStack.translate(x, y, 0);
|
||||||
|
|
||||||
String info = stack.getDisplayName().getString();
|
var component = Component.literal("[").append(stack.getHoverName()).append("]");
|
||||||
int width = Minecraft.getInstance().font.width(info);
|
int width = Minecraft.getInstance().font.width(component);
|
||||||
|
guiGraphics.drawString(Minecraft.getInstance().font, component, -width / 2, -4, -1, false);
|
||||||
guiGraphics.drawString(Minecraft.getInstance().font, Component.literal(stack.getDisplayName().getString()),
|
|
||||||
-width / 2, -4, -1, false);
|
|
||||||
|
|
||||||
poseStack.popPose();
|
poseStack.popPose();
|
||||||
|
|
||||||
|
@ -131,7 +137,4 @@ public class Type63InfoOverlay implements LayeredDraw.Layer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,7 +76,7 @@ public class Type63Renderer extends GeoEntityRenderer<Type63Entity> {
|
||||||
for (int i = 0; i < 12; i++) {
|
for (int i = 0; i < 12; i++) {
|
||||||
var items = animatable.getEntityData().get(LOADED_AMMO);
|
var items = animatable.getEntityData().get(LOADED_AMMO);
|
||||||
if (name.equals("shell" + i)) {
|
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);
|
super.defineSynchedData(builder);
|
||||||
var list = new ArrayList<Integer>();
|
var list = new ArrayList<Integer>();
|
||||||
for (int i = 0; i < this.getContainerSize(); i++) {
|
for (int i = 0; i < this.getContainerSize(); i++) {
|
||||||
list.add(0);
|
list.add(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.define(PITCH, 0F)
|
builder.define(PITCH, 0F)
|
||||||
|
@ -533,6 +533,14 @@ public class Type63Entity extends ContainerMobileVehicleEntity implements GeoEnt
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setChanged() {
|
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 explosionDamage;
|
||||||
private final float fireProbability;
|
private final float fireProbability;
|
||||||
private final int fireTime;
|
private final int fireTime;
|
||||||
private final MediumRocketEntity.Type type;
|
public final MediumRocketEntity.Type type;
|
||||||
private final int sparedAmount;
|
private final int sparedAmount;
|
||||||
|
|
||||||
public MediumRocketItem(float damage, float radius, float explosionDamage, float fireProbability, int fireTime, MediumRocketEntity.Type type, 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