重置HUD名称显示

This commit is contained in:
17146 2025-01-11 00:39:24 +08:00
parent f9b8f9d055
commit 6eb1164f33
28 changed files with 62 additions and 63 deletions

View file

@ -179,20 +179,22 @@ public class AmmoBarOverlay {
poseStack.scale(0.9f, 0.9f, 1f); poseStack.scale(0.9f, 0.9f, 1f);
// 渲染物品名称 // 渲染物品名称
String gunName = gunItem.getGunDisplayName();
event.getGuiGraphics().drawString( event.getGuiGraphics().drawString(
Minecraft.getInstance().font, Minecraft.getInstance().font,
centerString(gunItem.getGunDisplayName(), 20), gunName,
w / 0.9f - 144 / 0.9f, w / 0.9f - (100 + Minecraft.getInstance().font.width(gunName) / 2f) / 0.9f,
h / 0.9f - 60 / 0.9f, h / 0.9f - 60 / 0.9f,
0xFFFFFF, 0xFFFFFF,
true true
); );
// 渲染弹药类型 // 渲染弹药类型
String ammoName = getGunAmmoType(stack);
event.getGuiGraphics().drawString( event.getGuiGraphics().drawString(
Minecraft.getInstance().font, Minecraft.getInstance().font,
centerString(getGunAmmoType(stack), 20), ammoName,
w / 0.9f - 144 / 0.9f, w / 0.9f - (100 + Minecraft.getInstance().font.width(ammoName) / 2f) / 0.9f,
h / 0.9f - 51 / 0.9f, h / 0.9f - 51 / 0.9f,
0xC8A679, 0xC8A679,
true true
@ -255,7 +257,7 @@ public class AmmoBarOverlay {
private static String getGunAmmoType(ItemStack stack) { private static String getGunAmmoType(ItemStack stack) {
if (stack.getItem() == ModItems.BOCEK.get()) { if (stack.getItem() == ModItems.BOCEK.get()) {
return " Arrow"; return "Arrow";
} }
if (stack.getItem() == ModItems.M_79.get()) { if (stack.getItem() == ModItems.M_79.get()) {
return "40mm Grenade"; return "40mm Grenade";
@ -273,7 +275,7 @@ public class AmmoBarOverlay {
return "Rifle Ammo"; return "Rifle Ammo";
} }
if (stack.is(ModTags.Items.USE_RIFLE_AMMO)) { if (stack.is(ModTags.Items.USE_RIFLE_AMMO)) {
return " Rifle Ammo"; return "Rifle Ammo";
} }
if (stack.is(ModTags.Items.USE_HANDGUN_AMMO)) { if (stack.is(ModTags.Items.USE_HANDGUN_AMMO)) {
return "Handgun Ammo"; return "Handgun Ammo";
@ -286,19 +288,4 @@ public class AmmoBarOverlay {
} }
return ""; return "";
} }
private static String centerString(String string, int length) {
int spaceBefore = (length - string.length()) / 2;
int spaceAfter = length - string.length() - spaceBefore;
return String.join("",
repeatChar(spaceBefore),
string,
repeatChar(spaceAfter));
}
private static String repeatChar(int count) {
return new String(new char[count]).replace('\0', ' ');
}
} }

View file

@ -136,12 +136,12 @@ public class Glock17Item extends GunItem implements GeoItem, AnimatedItem {
@Override @Override
public ResourceLocation getGunIcon() { public ResourceLocation getGunIcon() {
return new ResourceLocation(ModUtils.MODID, "textures/gun_icon/glock_icon.png"); return ModUtils.loc("textures/gun_icon/glock_icon.png");
} }
@Override @Override
public String getGunDisplayName() { public String getGunDisplayName() {
return " GLOCK-17"; return "GLOCK-17";
} }
@Override @Override

View file

@ -39,6 +39,7 @@ import java.util.Set;
import java.util.function.Consumer; import java.util.function.Consumer;
public class Glock18Item extends GunItem implements GeoItem, AnimatedItem { public class Glock18Item extends GunItem implements GeoItem, AnimatedItem {
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
public static ItemDisplayContext transformType; public static ItemDisplayContext transformType;
@ -138,12 +139,12 @@ public class Glock18Item extends GunItem implements GeoItem, AnimatedItem {
@Override @Override
public ResourceLocation getGunIcon() { public ResourceLocation getGunIcon() {
return new ResourceLocation(ModUtils.MODID, "textures/gun_icon/glock_icon.png"); return ModUtils.loc("textures/gun_icon/glock_icon.png");
} }
@Override @Override
public String getGunDisplayName() { public String getGunDisplayName() {
return " GLOCK-18"; return "GLOCK-18";
} }
@Override @Override

View file

@ -38,6 +38,7 @@ import java.util.Set;
import java.util.function.Consumer; import java.util.function.Consumer;
public class M1911Item extends GunItem implements GeoItem, AnimatedItem { public class M1911Item extends GunItem implements GeoItem, AnimatedItem {
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
public static ItemDisplayContext transformType; public static ItemDisplayContext transformType;
@ -138,12 +139,12 @@ public class M1911Item extends GunItem implements GeoItem, AnimatedItem {
@Override @Override
public ResourceLocation getGunIcon() { public ResourceLocation getGunIcon() {
return new ResourceLocation(ModUtils.MODID, "textures/gun_icon/m1911_icon.png"); return ModUtils.loc("textures/gun_icon/m1911_icon.png");
} }
@Override @Override
public String getGunDisplayName() { public String getGunDisplayName() {
return " M-1911"; return "M-1911";
} }
@Override @Override

View file

@ -136,12 +136,12 @@ public class Mp443Item extends GunItem implements GeoItem, AnimatedItem {
@Override @Override
public ResourceLocation getGunIcon() { public ResourceLocation getGunIcon() {
return new ResourceLocation(ModUtils.MODID, "textures/gun_icon/mp443_icon.png"); return ModUtils.loc("textures/gun_icon/mp443_icon.png");
} }
@Override @Override
public String getGunDisplayName() { public String getGunDisplayName() {
return " MP-443"; return "MP-443";
} }
@Override @Override

View file

@ -172,7 +172,7 @@ public class RpgItem extends GunItem implements GeoItem, AnimatedItem {
@Override @Override
public String getGunDisplayName() { public String getGunDisplayName() {
return " RPG-7"; return "RPG-7";
} }
@Override @Override

View file

@ -49,15 +49,15 @@ public class SecondaryCataclysm extends GunItem implements GeoItem, AnimatedItem
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
public static ItemDisplayContext transformType; public static ItemDisplayContext transformType;
public SecondaryCataclysm() {
super(new Properties().stacksTo(1).fireResistant().rarity(Rarity.EPIC));
}
@Override @Override
public Set<SoundEvent> getReloadSound() { public Set<SoundEvent> getReloadSound() {
return Set.of(ModSounds.M_79_RELOAD_EMPTY.get()); return Set.of(ModSounds.M_79_RELOAD_EMPTY.get());
} }
public SecondaryCataclysm() {
super(new Properties().stacksTo(1).fireResistant().rarity(Rarity.RARE));
}
@Override @Override
public void initializeClient(Consumer<IClientItemExtensions> consumer) { public void initializeClient(Consumer<IClientItemExtensions> consumer) {
super.initializeClient(consumer); super.initializeClient(consumer);

View file

@ -40,6 +40,7 @@ import java.util.Set;
import java.util.function.Consumer; import java.util.function.Consumer;
public class DevotionItem extends GunItem implements GeoItem, AnimatedItem { public class DevotionItem extends GunItem implements GeoItem, AnimatedItem {
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
public static ItemDisplayContext transformType; public static ItemDisplayContext transformType;
@ -122,12 +123,12 @@ public class DevotionItem extends GunItem implements GeoItem, AnimatedItem {
@Override @Override
public ResourceLocation getGunIcon() { public ResourceLocation getGunIcon() {
return new ResourceLocation(ModUtils.MODID, "textures/gun_icon/devotion_icon.png"); return ModUtils.loc("textures/gun_icon/devotion_icon.png");
} }
@Override @Override
public String getGunDisplayName() { public String getGunDisplayName() {
return " Devotion"; return "Devotion";
} }
@Override @Override

View file

@ -42,6 +42,7 @@ import java.util.Set;
import java.util.function.Consumer; import java.util.function.Consumer;
public class M60Item extends GunItem implements GeoItem, AnimatedItem { public class M60Item extends GunItem implements GeoItem, AnimatedItem {
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
public static ItemDisplayContext transformType; public static ItemDisplayContext transformType;
@ -156,7 +157,7 @@ public class M60Item extends GunItem implements GeoItem, AnimatedItem {
@Override @Override
public String getGunDisplayName() { public String getGunDisplayName() {
return " M60"; return "M60";
} }
@Override @Override

View file

@ -46,6 +46,7 @@ import software.bernie.geckolib.util.GeckoLibUtil;
import java.util.function.Consumer; import java.util.function.Consumer;
public class MinigunItem extends GunItem implements GeoItem, AnimatedItem { public class MinigunItem extends GunItem implements GeoItem, AnimatedItem {
private static final String TAG_HEAT = "heat"; private static final String TAG_HEAT = "heat";
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
public static ItemDisplayContext transformType; public static ItemDisplayContext transformType;
@ -196,7 +197,7 @@ public class MinigunItem extends GunItem implements GeoItem, AnimatedItem {
@Override @Override
public ResourceLocation getGunIcon() { public ResourceLocation getGunIcon() {
return new ResourceLocation(ModUtils.MODID, "textures/gun_icon/minigun_icon.png"); return ModUtils.loc("textures/gun_icon/minigun_icon.png");
} }
@Override @Override

View file

@ -40,8 +40,8 @@ import java.util.Set;
import java.util.function.Consumer; import java.util.function.Consumer;
public class RpkItem extends GunItem implements GeoItem, AnimatedItem { public class RpkItem extends GunItem implements GeoItem, AnimatedItem {
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
public String animationProcedure = "empty";
public static ItemDisplayContext transformType; public static ItemDisplayContext transformType;
public RpkItem() { public RpkItem() {
@ -96,7 +96,8 @@ public class RpkItem extends GunItem implements GeoItem, AnimatedItem {
} }
@Override @Override
public void registerControllers(AnimatableManager.ControllerRegistrar data) {; public void registerControllers(AnimatableManager.ControllerRegistrar data) {
;
var idleController = new AnimationController<>(this, "idleController", 4, this::idlePredicate); var idleController = new AnimationController<>(this, "idleController", 4, this::idlePredicate);
data.add(idleController); data.add(idleController);
} }
@ -123,12 +124,12 @@ public class RpkItem extends GunItem implements GeoItem, AnimatedItem {
@Override @Override
public ResourceLocation getGunIcon() { public ResourceLocation getGunIcon() {
return new ResourceLocation(ModUtils.MODID, "textures/gun_icon/rpk_icon.png"); return ModUtils.loc("textures/gun_icon/rpk_icon.png");
} }
@Override @Override
public String getGunDisplayName() { public String getGunDisplayName() {
return " RPK"; return "RPK";
} }
@Override @Override

View file

@ -197,7 +197,7 @@ public class AK12Item extends GunItem implements GeoItem, AnimatedItem {
@Override @Override
public String getGunDisplayName() { public String getGunDisplayName() {
return " AK-12"; return "AK-12";
} }
@Override @Override

View file

@ -206,7 +206,7 @@ public class AK47Item extends GunItem implements GeoItem, AnimatedItem {
@Override @Override
public String getGunDisplayName() { public String getGunDisplayName() {
return " AK-47"; return "AK-47";
} }
@Override @Override

View file

@ -208,7 +208,7 @@ public class Hk416Item extends GunItem implements GeoItem, AnimatedItem {
@Override @Override
public String getGunDisplayName() { public String getGunDisplayName() {
return " HK-416"; return "HK-416";
} }
@Override @Override

View file

@ -207,7 +207,7 @@ public class M4Item extends GunItem implements GeoItem, AnimatedItem {
@Override @Override
public String getGunDisplayName() { public String getGunDisplayName() {
return " M4A1"; return "M4A1";
} }
@Override @Override

View file

@ -163,7 +163,7 @@ public class MarlinItem extends GunItem implements GeoItem, AnimatedItem {
@Override @Override
public String getGunDisplayName() { public String getGunDisplayName() {
return " MARLIN-1894"; return "MARLIN-1894";
} }
@Override @Override

View file

@ -206,7 +206,7 @@ public class Mk14Item extends GunItem implements GeoItem, AnimatedItem {
@Override @Override
public String getGunDisplayName() { public String getGunDisplayName() {
return " MK-14"; return "MK-14";
} }
@Override @Override

View file

@ -141,7 +141,7 @@ public class SksItem extends GunItem implements GeoItem, AnimatedItem {
@Override @Override
public String getGunDisplayName() { public String getGunDisplayName() {
return " SKS"; return "SKS";
} }
@Override @Override

View file

@ -155,7 +155,7 @@ public class Aa12Item extends GunItem implements GeoItem, AnimatedItem {
@Override @Override
public String getGunDisplayName() { public String getGunDisplayName() {
return " AA-12"; return "AA-12";
} }
@Override @Override

View file

@ -131,7 +131,7 @@ public class AbekiriItem extends GunItem implements GeoItem, AnimatedItem {
@Override @Override
public String getGunDisplayName() { public String getGunDisplayName() {
return " Abekiri"; return "Abekiri";
} }
@Override @Override

View file

@ -165,7 +165,7 @@ public class M870Item extends GunItem implements GeoItem, AnimatedItem {
@Override @Override
public String getGunDisplayName() { public String getGunDisplayName() {
return " M870 MCS"; return "M870 MCS";
} }
@Override @Override

View file

@ -39,6 +39,7 @@ import java.util.Set;
import java.util.function.Consumer; import java.util.function.Consumer;
public class HuntingRifleItem extends GunItem implements GeoItem, AnimatedItem { public class HuntingRifleItem extends GunItem implements GeoItem, AnimatedItem {
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
public static ItemDisplayContext transformType; public static ItemDisplayContext transformType;
@ -117,12 +118,12 @@ public class HuntingRifleItem extends GunItem implements GeoItem, AnimatedItem {
@Override @Override
public ResourceLocation getGunIcon() { public ResourceLocation getGunIcon() {
return new ResourceLocation(ModUtils.MODID, "textures/gun_icon/hunting_rifle_icon.png"); return ModUtils.loc("textures/gun_icon/hunting_rifle_icon.png");
} }
@Override @Override
public String getGunDisplayName() { public String getGunDisplayName() {
return " Hunting Rifle"; return "Hunting Rifle";
} }
@Override @Override

View file

@ -38,6 +38,7 @@ import java.util.Set;
import java.util.function.Consumer; import java.util.function.Consumer;
public class K98Item extends GunItem implements GeoItem, AnimatedItem { public class K98Item extends GunItem implements GeoItem, AnimatedItem {
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
public static ItemDisplayContext transformType; public static ItemDisplayContext transformType;
@ -160,12 +161,12 @@ public class K98Item extends GunItem implements GeoItem, AnimatedItem {
@Override @Override
public ResourceLocation getGunIcon() { public ResourceLocation getGunIcon() {
return new ResourceLocation(ModUtils.MODID, "textures/gun_icon/k98_icon.png"); return ModUtils.loc("textures/gun_icon/k98_icon.png");
} }
@Override @Override
public String getGunDisplayName() { public String getGunDisplayName() {
return " KAR-98K"; return "KAR-98K";
} }
@Override @Override

View file

@ -39,6 +39,7 @@ import java.util.Set;
import java.util.function.Consumer; import java.util.function.Consumer;
public class M98bItem extends GunItem implements GeoItem, AnimatedItem { public class M98bItem extends GunItem implements GeoItem, AnimatedItem {
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
public static ItemDisplayContext transformType; public static ItemDisplayContext transformType;
@ -138,12 +139,12 @@ public class M98bItem extends GunItem implements GeoItem, AnimatedItem {
@Override @Override
public ResourceLocation getGunIcon() { public ResourceLocation getGunIcon() {
return new ResourceLocation(ModUtils.MODID, "textures/gun_icon/m98b_icon.png"); return ModUtils.loc("textures/gun_icon/m98b_icon.png");
} }
@Override @Override
public String getGunDisplayName() { public String getGunDisplayName() {
return " M98-B"; return "M98-B";
} }
@Override @Override

View file

@ -38,6 +38,7 @@ import java.util.Set;
import java.util.function.Consumer; import java.util.function.Consumer;
public class MosinNagantItem extends GunItem implements GeoItem, AnimatedItem { public class MosinNagantItem extends GunItem implements GeoItem, AnimatedItem {
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
public static ItemDisplayContext transformType; public static ItemDisplayContext transformType;
@ -160,7 +161,7 @@ public class MosinNagantItem extends GunItem implements GeoItem, AnimatedItem {
@Override @Override
public ResourceLocation getGunIcon() { public ResourceLocation getGunIcon() {
return new ResourceLocation(ModUtils.MODID, "textures/gun_icon/mosin_nagant_icon.png"); return ModUtils.loc("textures/gun_icon/mosin_nagant_icon.png");
} }
@Override @Override

View file

@ -39,6 +39,7 @@ import java.util.Set;
import java.util.function.Consumer; import java.util.function.Consumer;
public class Ntw20Item extends GunItem implements GeoItem, AnimatedItem { public class Ntw20Item extends GunItem implements GeoItem, AnimatedItem {
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
public static ItemDisplayContext transformType; public static ItemDisplayContext transformType;
@ -139,7 +140,7 @@ public class Ntw20Item extends GunItem implements GeoItem, AnimatedItem {
@Override @Override
public ResourceLocation getGunIcon() { public ResourceLocation getGunIcon() {
return new ResourceLocation(ModUtils.MODID, "textures/gun_icon/ntw_20_icon.png"); return ModUtils.loc("textures/gun_icon/ntw_20_icon.png");
} }
@Override @Override

View file

@ -39,6 +39,7 @@ import java.util.Set;
import java.util.function.Consumer; import java.util.function.Consumer;
public class SvdItem extends GunItem implements GeoItem, AnimatedItem { public class SvdItem extends GunItem implements GeoItem, AnimatedItem {
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
public static ItemDisplayContext transformType; public static ItemDisplayContext transformType;
@ -121,12 +122,12 @@ public class SvdItem extends GunItem implements GeoItem, AnimatedItem {
@Override @Override
public ResourceLocation getGunIcon() { public ResourceLocation getGunIcon() {
return new ResourceLocation(ModUtils.MODID, "textures/gun_icon/svd_icon.png"); return ModUtils.loc("textures/gun_icon/svd_icon.png");
} }
@Override @Override
public String getGunDisplayName() { public String getGunDisplayName() {
return " SVD"; return "SVD";
} }
@Override @Override

View file

@ -151,7 +151,7 @@ public class BocekItem extends GunItem implements GeoItem, AnimatedItem {
@Override @Override
public String getGunDisplayName() { public String getGunDisplayName() {
return " Bocek"; return "Bocek";
} }
@Override @Override