添加玩家弹药总量显示
This commit is contained in:
parent
76a674313c
commit
535b1f5478
4 changed files with 92 additions and 26 deletions
|
@ -6,20 +6,25 @@ import com.atsuishio.superbwarfare.entity.vehicle.base.ArmedVehicleEntity;
|
|||
import com.atsuishio.superbwarfare.init.ModItems;
|
||||
import com.atsuishio.superbwarfare.init.ModKeyMappings;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.item.common.ammo.AmmoSupplierItem;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.network.ModVariables;
|
||||
import com.atsuishio.superbwarfare.tools.AmmoType;
|
||||
import com.atsuishio.superbwarfare.tools.GunsTool;
|
||||
import com.atsuishio.superbwarfare.tools.InventoryTool;
|
||||
import com.atsuishio.superbwarfare.tools.animation.AnimationCurves;
|
||||
import com.atsuishio.superbwarfare.tools.animation.AnimationTimer;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.event.RenderGuiEvent;
|
||||
import net.minecraftforge.eventbus.api.EventPriority;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
|
||||
|
@ -40,8 +45,8 @@ public class AmmoBarOverlay {
|
|||
return InventoryTool.hasCreativeAmmoBox(player);
|
||||
}
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.NORMAL)
|
||||
public static void onRenderGui(RenderGuiEvent.Pre event) {
|
||||
@SubscribeEvent
|
||||
public static void renderWeaponInfo(RenderGuiEvent.Pre event) {
|
||||
if (!DisplayConfig.AMMO_HUD.get()) return;
|
||||
|
||||
int w = event.getWindow().getGuiScaledWidth();
|
||||
|
@ -52,7 +57,7 @@ public class AmmoBarOverlay {
|
|||
if (player.isSpectator()) return;
|
||||
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (stack.getItem() instanceof GunItem gunItem &&!(player.getVehicle() instanceof ArmedVehicleEntity vehicle && vehicle.banHand(player))) {
|
||||
if (stack.getItem() instanceof GunItem gunItem && !(player.getVehicle() instanceof ArmedVehicleEntity vehicle && vehicle.banHand(player))) {
|
||||
PoseStack poseStack = event.getGuiGraphics().pose();
|
||||
|
||||
// 渲染图标
|
||||
|
@ -206,6 +211,67 @@ public class AmmoBarOverlay {
|
|||
}
|
||||
}
|
||||
|
||||
private static final AnimationTimer ammoInfoTimer = new AnimationTimer(500, AnimationCurves.EASE_OUT_CIRC);
|
||||
|
||||
/**
|
||||
* 在手持弹药或弹药盒时,渲染玩家弹药总量信息
|
||||
*/
|
||||
@SubscribeEvent
|
||||
public static void renderAmmoInfo(RenderGuiEvent.Pre event) {
|
||||
Player player = Minecraft.getInstance().player;
|
||||
if (player == null || player.isSpectator()) return;
|
||||
|
||||
// 动画计算
|
||||
var currentTime = System.currentTimeMillis();
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if ((stack.getItem() instanceof AmmoSupplierItem || stack.getItem() == ModItems.AMMO_BOX.get()) && !(player.getVehicle() instanceof ArmedVehicleEntity vehicle && vehicle.banHand(player))) {
|
||||
ammoInfoTimer.forward(currentTime);
|
||||
} else {
|
||||
ammoInfoTimer.backward(currentTime);
|
||||
}
|
||||
if (!ammoInfoTimer.isForward() && ammoInfoTimer.finished(currentTime)) return;
|
||||
|
||||
var poseStack = event.getGuiGraphics().pose();
|
||||
poseStack.pushPose();
|
||||
|
||||
var xOffset = -Mth.lerp(ammoInfoTimer.getProgress(currentTime), 0, 120);
|
||||
final int fontHeight = 15;
|
||||
var yOffset = -AmmoType.values().length * fontHeight;
|
||||
|
||||
// 渲染总弹药数量
|
||||
var cap = player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables());
|
||||
int w = event.getWindow().getGuiScaledWidth();
|
||||
int h = event.getWindow().getGuiScaledHeight();
|
||||
|
||||
RenderSystem.setShaderColor(1, 1, 1, Mth.lerp(ammoInfoTimer.getProgress(currentTime), 0, 1));
|
||||
var font = Minecraft.getInstance().font;
|
||||
for (var type : AmmoType.values()) {
|
||||
var ammoCountStr = Integer.toString(type.get(cap));
|
||||
event.getGuiGraphics().drawString(
|
||||
Minecraft.getInstance().font,
|
||||
ammoCountStr,
|
||||
w + xOffset + (30 - font.width(ammoCountStr)),
|
||||
h + yOffset,
|
||||
0xFFFFFF,
|
||||
true
|
||||
);
|
||||
|
||||
event.getGuiGraphics().drawString(
|
||||
Minecraft.getInstance().font,
|
||||
Component.translatable(type.translatableKey).getString(),
|
||||
w + xOffset + 35,
|
||||
h + yOffset,
|
||||
0xFFFFFF,
|
||||
true
|
||||
);
|
||||
|
||||
yOffset += fontHeight;
|
||||
}
|
||||
|
||||
RenderSystem.setShaderColor(1, 1, 1, 1);
|
||||
poseStack.popPose();
|
||||
}
|
||||
|
||||
private static ResourceLocation getFireMode(ItemStack stack) {
|
||||
return switch (GunsTool.getGunIntTag(stack, "FireMode")) {
|
||||
case 1 -> BURST;
|
||||
|
|
|
@ -62,6 +62,10 @@ public class AnimationTimer {
|
|||
return timers;
|
||||
}
|
||||
|
||||
public boolean isForward() {
|
||||
return !reversed;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取当前进度
|
||||
|
|
|
@ -4,12 +4,11 @@
|
|||
"item_group.superbwarfare.item": "Superb Warfare Items",
|
||||
"item_group.superbwarfare.block": "Superb Warfare Blocks",
|
||||
"item_group.superbwarfare.ammo": "Superb Warfare Ammo",
|
||||
|
||||
"item.superbwarfare.ammo.shotgun": "Shotgun",
|
||||
"item.superbwarfare.ammo.handgun": "Handgun",
|
||||
"item.superbwarfare.ammo.rifle": "Rifle",
|
||||
"item.superbwarfare.ammo.sniper": "Sniper",
|
||||
"item.superbwarfare.ammo.heavy": "Heavy Weapon",
|
||||
"item.superbwarfare.ammo.shotgun": "Shotgun Ammo",
|
||||
"item.superbwarfare.ammo.handgun": "Handgun Ammo",
|
||||
"item.superbwarfare.ammo.rifle": "Rifle Ammo",
|
||||
"item.superbwarfare.ammo.sniper": "Sniper Ammo",
|
||||
"item.superbwarfare.ammo.heavy": "Heavy Ammo",
|
||||
|
||||
"item.superbwarfare.sentinel": "SENTINEL",
|
||||
"item.superbwarfare.rpk": "RPK",
|
||||
|
@ -155,7 +154,7 @@
|
|||
"des.superbwarfare.ammo_supplier": "Right Click to Supply Ammo",
|
||||
"item.superbwarfare.creative_ammo_box": "Creative Ammo Box",
|
||||
"des.superbwarfare.creative_ammo_box": "Provide infinite ammo when placed in inventory",
|
||||
"item.superbwarfare.ammo_supplier.supply": "%1$s Ammo +%2$s",
|
||||
"item.superbwarfare.ammo_supplier.supply": "%1$s +%2$s",
|
||||
"item.superbwarfare.he_5_inches": "HE Shell",
|
||||
"item.superbwarfare.ap_5_inches": "AP Shell",
|
||||
"item.superbwarfare.javelin_missile": "Javelin Missile",
|
||||
|
@ -459,10 +458,9 @@
|
|||
"item.minecraft.tipped_arrow.effect.superbwarfare_shock": "Arrow of Shock",
|
||||
"item.minecraft.tipped_arrow.effect.superbwarfare_strong_shock": "Arrow of Shock",
|
||||
"item.minecraft.tipped_arrow.effect.superbwarfare_long_shock": "Arrow of Shock",
|
||||
|
||||
"commands.ammo.get": "Current %1$s ammo: %2$s",
|
||||
"commands.ammo.set": "Set %s ammo to %s for %s players",
|
||||
"commands.ammo.add": "Added %s ammo of amount %s for %s players",
|
||||
"commands.ammo.get": "Current %1$s: %2$s",
|
||||
"commands.ammo.set": "Set %s to %s for %s players",
|
||||
"commands.ammo.add": "Added %s of amount %s for %s players",
|
||||
"commands.ammo.no_permission": "Permission denied",
|
||||
|
||||
"tips.superbwarfare.sensitivity": "Current Sensitivity of This Gun: %1$s",
|
||||
|
|
|
@ -4,12 +4,11 @@
|
|||
"item_group.superbwarfare.item": "卓越前线:物品",
|
||||
"item_group.superbwarfare.block": "卓越前线:方块",
|
||||
"item_group.superbwarfare.ammo": "卓越前线:弹药",
|
||||
|
||||
"item.superbwarfare.ammo.shotgun": "霰弹枪",
|
||||
"item.superbwarfare.ammo.handgun": "手枪",
|
||||
"item.superbwarfare.ammo.rifle": "步枪",
|
||||
"item.superbwarfare.ammo.sniper": "狙击枪",
|
||||
"item.superbwarfare.ammo.heavy": "重型武器",
|
||||
"item.superbwarfare.ammo.shotgun": "霰弹枪弹药",
|
||||
"item.superbwarfare.ammo.handgun": "手枪弹药",
|
||||
"item.superbwarfare.ammo.rifle": "步枪弹药",
|
||||
"item.superbwarfare.ammo.sniper": "狙击枪弹药",
|
||||
"item.superbwarfare.ammo.heavy": "重型弹药",
|
||||
|
||||
"item.superbwarfare.sentinel": "哨兵狙击步枪",
|
||||
"item.superbwarfare.rpk": "RPK轻机枪",
|
||||
|
@ -155,7 +154,7 @@
|
|||
"des.superbwarfare.ammo_supplier": "右击使用以补充弹药",
|
||||
"item.superbwarfare.creative_ammo_box": "创造弹药盒",
|
||||
"des.superbwarfare.creative_ammo_box": "放置在背包中以提供无限的弹药",
|
||||
"item.superbwarfare.ammo_supplier.supply": "%1$s弹药 +%2$s",
|
||||
"item.superbwarfare.ammo_supplier.supply": "%1$s +%2$s",
|
||||
"item.superbwarfare.he_5_inches": "高爆弹",
|
||||
"item.superbwarfare.ap_5_inches": "穿甲弹",
|
||||
"item.superbwarfare.javelin_missile": "标枪导弹",
|
||||
|
@ -457,10 +456,9 @@
|
|||
"item.minecraft.tipped_arrow.effect.superbwarfare_shock": "电击之箭",
|
||||
"item.minecraft.tipped_arrow.effect.superbwarfare_strong_shock": "电击之箭",
|
||||
"item.minecraft.tipped_arrow.effect.superbwarfare_long_shock": "电击之箭",
|
||||
|
||||
"commands.ammo.get": "当前%1$s弹药数量: %2$s",
|
||||
"commands.ammo.set": "为%3$s位玩家的%1$s弹药数量设置为%2$s",
|
||||
"commands.ammo.add": "为%3$s位玩家添加了%2$s发%1$s弹药",
|
||||
"commands.ammo.get": "当前%1$s数量: %2$s",
|
||||
"commands.ammo.set": "为%3$s位玩家的%1$s数量设置为%2$s",
|
||||
"commands.ammo.add": "为%3$s位玩家添加了%2$s发%1$s",
|
||||
"commands.ammo.no_permission": "权限不足",
|
||||
|
||||
"tips.superbwarfare.sensitivity": "当前枪械的灵敏度为:%1$s",
|
||||
|
|
Loading…
Add table
Reference in a new issue