修改基本的弹药显示
This commit is contained in:
parent
f896b904cf
commit
c82e034688
3 changed files with 92 additions and 33 deletions
|
@ -1,9 +1,13 @@
|
|||
package net.mcreator.target.client.screens;
|
||||
|
||||
import net.mcreator.target.event.PlayerEventHandler;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.mcreator.target.init.TargetModItems;
|
||||
import net.mcreator.target.init.TargetModTags;
|
||||
import net.mcreator.target.network.TargetModVariables;
|
||||
import net.mcreator.target.tools.FireMode;
|
||||
import net.minecraft.client.Minecraft;
|
||||
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;
|
||||
|
@ -17,16 +21,86 @@ public class AmmoBarOverlay {
|
|||
public static void eventHandler(RenderGuiEvent.Pre event) {
|
||||
int w = event.getWindow().getGuiScaledWidth();
|
||||
int h = event.getWindow().getGuiScaledHeight();
|
||||
Player entity = Minecraft.getInstance().player;
|
||||
if (entity != null && entity.getMainHandItem().is(TargetModTags.Items.GUN)) {
|
||||
Player player = Minecraft.getInstance().player;
|
||||
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (stack.is(TargetModTags.Items.GUN)) {
|
||||
PoseStack poseStack = event.getGuiGraphics().pose();
|
||||
|
||||
FireMode mode = getFireMode(stack);
|
||||
|
||||
poseStack.pushPose();
|
||||
poseStack.scale(1.5f, 1.5f, 1f);
|
||||
|
||||
event.getGuiGraphics().drawString(
|
||||
Minecraft.getInstance().font,
|
||||
PlayerEventHandler.handleAmmoCount(entity),
|
||||
w / 2 + 92,
|
||||
h - 11,
|
||||
-16711936,
|
||||
false
|
||||
getGunAmmoCount(player) + "",
|
||||
w / 3f + 117,
|
||||
h / 1.5f - 28,
|
||||
0xFFFFFF,
|
||||
true
|
||||
);
|
||||
poseStack.popPose();
|
||||
|
||||
event.getGuiGraphics().drawString(
|
||||
Minecraft.getInstance().font,
|
||||
getPlayerAmmoCount(player),
|
||||
w / 2 + 180,
|
||||
h - 30,
|
||||
0xCCCCCC,
|
||||
true
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public static FireMode getFireMode(ItemStack stack) {
|
||||
return switch (stack.getOrCreateTag().getInt("fire_mode")) {
|
||||
case 0 -> FireMode.SEMI;
|
||||
case 1 -> FireMode.BURST;
|
||||
case 2 -> FireMode.AUTO;
|
||||
default -> FireMode.OTHER;
|
||||
};
|
||||
}
|
||||
|
||||
public static int getGunAmmoCount(Player player) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
|
||||
if (stack.getItem() == TargetModItems.BOCEK.get() || stack.getItem() == TargetModItems.M_79.get()
|
||||
|| stack.getItem() == TargetModItems.RPG.get() || stack.getItem() == TargetModItems.TASER.get()) {
|
||||
return stack.getOrCreateTag().getInt("maxammo");
|
||||
}
|
||||
if (stack.getItem() == TargetModItems.MINIGUN.get()) {
|
||||
return (player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).rifleAmmo;
|
||||
}
|
||||
|
||||
return stack.getOrCreateTag().getInt("ammo");
|
||||
}
|
||||
|
||||
public static String getPlayerAmmoCount(Player player) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
|
||||
if (stack.getItem() == TargetModItems.BOCEK.get()) {
|
||||
return "";
|
||||
}
|
||||
if (stack.getItem() == TargetModItems.MINIGUN.get()) {
|
||||
return "";
|
||||
}
|
||||
if (stack.is(TargetModTags.Items.RIFLE)) {
|
||||
return "" + (player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).rifleAmmo;
|
||||
}
|
||||
if (stack.is(TargetModTags.Items.HANDGUN) || stack.is(TargetModTags.Items.SMG)) {
|
||||
return "" + (player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).handgunAmmo;
|
||||
}
|
||||
if (stack.is(TargetModTags.Items.SHOTGUN)) {
|
||||
return "" + (player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).shotgunAmmo;
|
||||
}
|
||||
if (stack.is(TargetModTags.Items.SNIPER_RIFLE)) {
|
||||
return "" + (player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).sniperAmmo;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -179,48 +179,25 @@ public class PlayerEventHandler {
|
|||
recoilThread.start();
|
||||
}
|
||||
|
||||
public static String handleAmmoCount(Player player) {
|
||||
public static void handleAmmoCount(Player player) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
|
||||
String firemode = switch (stack.getOrCreateTag().getInt("fire_mode")) {
|
||||
case 0 -> "Semi";
|
||||
case 1 -> "Burst";
|
||||
case 2 -> "Auto";
|
||||
default -> "";
|
||||
};
|
||||
if (stack.getItem() == TargetModItems.BOCEK.get()) {
|
||||
return (new java.text.DecimalFormat("##").format(stack.getOrCreateTag().getInt("maxammo"))) + " " + firemode;
|
||||
}
|
||||
if (stack.getItem() == TargetModItems.MINIGUN.get()) {
|
||||
return new java.text.DecimalFormat("##").format((player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).rifleAmmo) + " " + firemode;
|
||||
}
|
||||
if (stack.is(TargetModTags.Items.RIFLE)) {
|
||||
stack.getOrCreateTag().putInt("maxammo",
|
||||
((player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).rifleAmmo));
|
||||
return (new java.text.DecimalFormat("##").format(stack.getOrCreateTag().getInt("ammo"))) + "/"
|
||||
+ new java.text.DecimalFormat("##").format((player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).rifleAmmo) + " " + firemode;
|
||||
}
|
||||
if (stack.is(TargetModTags.Items.HANDGUN)
|
||||
|| stack.is(TargetModTags.Items.SMG)) {
|
||||
if (stack.is(TargetModTags.Items.HANDGUN) || stack.is(TargetModTags.Items.SMG)) {
|
||||
stack.getOrCreateTag().putInt("maxammo",
|
||||
((player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).handgunAmmo));
|
||||
return (new java.text.DecimalFormat("##").format(stack.getOrCreateTag().getInt("ammo"))) + "/"
|
||||
+ new java.text.DecimalFormat("##").format((player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).handgunAmmo) + " " + firemode;
|
||||
}
|
||||
if (stack.is(TargetModTags.Items.SHOTGUN)) {
|
||||
stack.getOrCreateTag().putInt("maxammo",
|
||||
((player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).shotgunAmmo));
|
||||
return (new java.text.DecimalFormat("##").format(stack.getOrCreateTag().getInt("ammo"))) + "/"
|
||||
+ new java.text.DecimalFormat("##").format((player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).shotgunAmmo) + " " + firemode;
|
||||
}
|
||||
if (stack.is(TargetModTags.Items.SNIPER_RIFLE)) {
|
||||
stack.getOrCreateTag().putInt("maxammo",
|
||||
((player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).sniperAmmo));
|
||||
return (new java.text.DecimalFormat("##").format(stack.getOrCreateTag().getInt("ammo"))) + "/"
|
||||
+ new java.text.DecimalFormat("##").format((player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).sniperAmmo) + " " + firemode;
|
||||
}
|
||||
return (new java.text.DecimalFormat("##").format(stack.getOrCreateTag().getInt("ammo"))) + "/"
|
||||
+ (new java.text.DecimalFormat("##").format(stack.getOrCreateTag().getInt("maxammo"))) + " " + firemode;
|
||||
}
|
||||
|
||||
private static void handleFireTime(Player player) {
|
||||
|
|
8
src/main/java/net/mcreator/target/tools/FireMode.java
Normal file
8
src/main/java/net/mcreator/target/tools/FireMode.java
Normal file
|
@ -0,0 +1,8 @@
|
|||
package net.mcreator.target.tools;
|
||||
|
||||
public enum FireMode {
|
||||
SEMI,
|
||||
BURST,
|
||||
AUTO,
|
||||
OTHER
|
||||
}
|
Loading…
Add table
Reference in a new issue