添加盔甲插板的渲染
This commit is contained in:
parent
2d214977ad
commit
1d6a07787f
4 changed files with 80 additions and 6 deletions
|
@ -41,7 +41,7 @@ public class AmmoBarOverlay {
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent(priority = EventPriority.NORMAL)
|
@SubscribeEvent(priority = EventPriority.NORMAL)
|
||||||
public static void eventHandler(RenderGuiEvent.Pre event) {
|
public static void onRenderGui(RenderGuiEvent.Pre event) {
|
||||||
if (!DisplayConfig.AMMO_HUD.get()) return;
|
if (!DisplayConfig.AMMO_HUD.get()) return;
|
||||||
|
|
||||||
int w = event.getWindow().getGuiScaledWidth();
|
int w = event.getWindow().getGuiScaledWidth();
|
||||||
|
|
|
@ -0,0 +1,76 @@
|
||||||
|
package net.mcreator.superbwarfare.client.screens;
|
||||||
|
|
||||||
|
import net.mcreator.superbwarfare.ModUtils;
|
||||||
|
import net.mcreator.superbwarfare.init.ModTags;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.world.entity.EquipmentSlot;
|
||||||
|
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;
|
||||||
|
|
||||||
|
@Mod.EventBusSubscriber(value = Dist.CLIENT)
|
||||||
|
public class ArmorPlateOverlay {
|
||||||
|
|
||||||
|
private static final ResourceLocation ICON = ModUtils.loc("textures/screens/armor_plate_icon.png");
|
||||||
|
private static final ResourceLocation LEVEL1 = ModUtils.loc("textures/screens/armor_plate_level1.png");
|
||||||
|
private static final ResourceLocation LEVEL2 = ModUtils.loc("textures/screens/armor_plate_level2.png");
|
||||||
|
private static final ResourceLocation LEVEL3 = ModUtils.loc("textures/screens/armor_plate_level3.png");
|
||||||
|
private static final ResourceLocation LEVEL1_FRAME = ModUtils.loc("textures/screens/armor_plate_level1_frame.png");
|
||||||
|
private static final ResourceLocation LEVEL2_FRAME = ModUtils.loc("textures/screens/armor_plate_level2_frame.png");
|
||||||
|
private static final ResourceLocation LEVEL3_FRAME = ModUtils.loc("textures/screens/armor_plate_level3_frame.png");
|
||||||
|
|
||||||
|
@SubscribeEvent(priority = EventPriority.NORMAL)
|
||||||
|
public static void onRenderGui(RenderGuiEvent.Pre event) {
|
||||||
|
int h = event.getWindow().getGuiScaledHeight();
|
||||||
|
GuiGraphics guiGraphics = event.getGuiGraphics();
|
||||||
|
|
||||||
|
Player player = Minecraft.getInstance().player;
|
||||||
|
if (player == null) return;
|
||||||
|
if (player.isSpectator()) return;
|
||||||
|
|
||||||
|
ItemStack stack = player.getItemBySlot(EquipmentSlot.CHEST);
|
||||||
|
if (stack == ItemStack.EMPTY) return;
|
||||||
|
if (stack.getTag() == null || !stack.getTag().contains("ArmorPlate")) return;
|
||||||
|
|
||||||
|
double amount = stack.getTag().getDouble("ArmorPlate");
|
||||||
|
|
||||||
|
int armorLevel = 1;
|
||||||
|
if (stack.is(ModTags.Items.MILITARY_ARMOR)) {
|
||||||
|
armorLevel = 2;
|
||||||
|
} else if (stack.is(ModTags.Items.MILITARY_ARMOR_HEAVY)) {
|
||||||
|
armorLevel = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
ResourceLocation texture = switch (armorLevel) {
|
||||||
|
case 2 -> LEVEL2;
|
||||||
|
case 3 -> LEVEL3;
|
||||||
|
default -> LEVEL1;
|
||||||
|
};
|
||||||
|
ResourceLocation frame = switch (armorLevel) {
|
||||||
|
case 2 -> LEVEL2_FRAME;
|
||||||
|
case 3 -> LEVEL3_FRAME;
|
||||||
|
default -> LEVEL1_FRAME;
|
||||||
|
};
|
||||||
|
|
||||||
|
int length = armorLevel * 30;
|
||||||
|
|
||||||
|
guiGraphics.pose().pushPose();
|
||||||
|
// 渲染图标
|
||||||
|
guiGraphics.blit(ICON, 10, h - 16, 0, 0, 8, 8, 8, 8);
|
||||||
|
|
||||||
|
// 渲染框架
|
||||||
|
guiGraphics.blit(frame, 20, h - 15, 0, 0, length, 6, length, 6);
|
||||||
|
|
||||||
|
// 渲染盔甲值
|
||||||
|
guiGraphics.blit(texture, 20, h - 15, 0, 0, (int) amount, 6, length, 6);
|
||||||
|
|
||||||
|
guiGraphics.pose().popPose();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -107,7 +107,7 @@ public class LivingEventHandler {
|
||||||
|
|
||||||
double armorValue = 0;
|
double armorValue = 0;
|
||||||
|
|
||||||
if (armor.getItem() != ItemStack.EMPTY.getItem()) {
|
if (armor != ItemStack.EMPTY) {
|
||||||
armorValue = armor.getOrCreateTag().getDouble("ArmorPlate");
|
armorValue = armor.getOrCreateTag().getDouble("ArmorPlate");
|
||||||
armor.getOrCreateTag().putDouble("ArmorPlate", Math.max(armor.getOrCreateTag().getDouble("ArmorPlate") - damage, 0));
|
armor.getOrCreateTag().putDouble("ArmorPlate", Math.max(armor.getOrCreateTag().getDouble("ArmorPlate") - damage, 0));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package net.mcreator.superbwarfare.item;
|
package net.mcreator.superbwarfare.item;
|
||||||
|
|
||||||
|
|
||||||
import net.mcreator.superbwarfare.init.ModTags;
|
import net.mcreator.superbwarfare.init.ModTags;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.sounds.SoundEvents;
|
import net.minecraft.sounds.SoundEvents;
|
||||||
|
@ -27,7 +26,7 @@ public class ArmorPlate extends Item {
|
||||||
ItemStack stack = playerIn.getItemInHand(handIn);
|
ItemStack stack = playerIn.getItemInHand(handIn);
|
||||||
ItemStack armor = playerIn.getItemBySlot(EquipmentSlot.CHEST);
|
ItemStack armor = playerIn.getItemBySlot(EquipmentSlot.CHEST);
|
||||||
|
|
||||||
if (armor.getItem() == ItemStack.EMPTY.getItem()) return InteractionResultHolder.fail(stack);
|
if (armor == ItemStack.EMPTY) return InteractionResultHolder.fail(stack);
|
||||||
|
|
||||||
int armorLevel = 1;
|
int armorLevel = 1;
|
||||||
if (armor.is(ModTags.Items.MILITARY_ARMOR)) {
|
if (armor.is(ModTags.Items.MILITARY_ARMOR)) {
|
||||||
|
@ -51,7 +50,6 @@ public class ArmorPlate extends Item {
|
||||||
@Override
|
@Override
|
||||||
public ItemStack finishUsingItem(ItemStack pStack, Level pLevel, LivingEntity pLivingEntity) {
|
public ItemStack finishUsingItem(ItemStack pStack, Level pLevel, LivingEntity pLivingEntity) {
|
||||||
if (!pLevel.isClientSide) {
|
if (!pLevel.isClientSide) {
|
||||||
|
|
||||||
ItemStack armor = pLivingEntity.getItemBySlot(EquipmentSlot.CHEST);
|
ItemStack armor = pLivingEntity.getItemBySlot(EquipmentSlot.CHEST);
|
||||||
|
|
||||||
int armorLevel = 1;
|
int armorLevel = 1;
|
||||||
|
|
Loading…
Add table
Reference in a new issue