添加通用枪械描述工具类
This commit is contained in:
parent
9a829dee63
commit
b2af030470
7 changed files with 72 additions and 32 deletions
|
@ -6,6 +6,7 @@ import net.mcreator.target.TargetMod;
|
||||||
import net.mcreator.target.client.renderer.item.TracheliumItemRenderer;
|
import net.mcreator.target.client.renderer.item.TracheliumItemRenderer;
|
||||||
import net.mcreator.target.procedures.ReloadingProcedure;
|
import net.mcreator.target.procedures.ReloadingProcedure;
|
||||||
import net.mcreator.target.tools.RarityTool;
|
import net.mcreator.target.tools.RarityTool;
|
||||||
|
import net.mcreator.target.tools.TooltipTool;
|
||||||
import net.minecraft.ChatFormatting;
|
import net.minecraft.ChatFormatting;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.model.HumanoidModel;
|
import net.minecraft.client.model.HumanoidModel;
|
||||||
|
@ -154,5 +155,7 @@ public class Trachelium extends GunItem implements GeoItem {
|
||||||
public void appendHoverText(ItemStack stack, @Nullable Level level, List<Component> list, TooltipFlag flag) {
|
public void appendHoverText(ItemStack stack, @Nullable Level level, List<Component> list, TooltipFlag flag) {
|
||||||
list.add(Component.translatable("des.target.trachelium_1").withStyle(ChatFormatting.GRAY).withStyle(ChatFormatting.ITALIC));
|
list.add(Component.translatable("des.target.trachelium_1").withStyle(ChatFormatting.GRAY).withStyle(ChatFormatting.ITALIC));
|
||||||
list.add(Component.translatable("des.target.trachelium_2").withStyle(ChatFormatting.GRAY));
|
list.add(Component.translatable("des.target.trachelium_2").withStyle(ChatFormatting.GRAY));
|
||||||
|
|
||||||
|
TooltipTool.addGunTips(list, stack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,33 +30,6 @@ public class GunsTipsProcedure {
|
||||||
private static void execute(@Nullable Event event, ItemStack itemstack, List<Component> tooltip) {
|
private static void execute(@Nullable Event event, ItemStack itemstack, List<Component> tooltip) {
|
||||||
if (tooltip == null)
|
if (tooltip == null)
|
||||||
return;
|
return;
|
||||||
String firemode = "";
|
|
||||||
ItemStack usehand = ItemStack.EMPTY;
|
|
||||||
if (itemstack.is(ItemTags.create(new ResourceLocation("target:gun")))) {
|
|
||||||
if (itemstack.getItem() == TargetModItems.BOCEK.get()) {
|
|
||||||
tooltip.add(Component.literal(("\u00A7l\u00A77Damage:(" + new java.text.DecimalFormat("##.##").format(2.4 * itemstack.getOrCreateTag().getDouble("damageadd")) + ")*10/"
|
|
||||||
+ new java.text.DecimalFormat("##.##").format(24 * itemstack.getOrCreateTag().getDouble("damageadd")))));
|
|
||||||
} else {
|
|
||||||
tooltip.add(Component.literal(("\u00A7l\u00A77Damage:"
|
|
||||||
+ new java.text.DecimalFormat("##.##").format((itemstack.getOrCreateTag().getDouble("damage") + itemstack.getOrCreateTag().getDouble("adddamage")) * itemstack.getOrCreateTag().getDouble("damageadd")))));
|
|
||||||
}
|
|
||||||
if (itemstack.getOrCreateTag().getDouble("level") < 4) {
|
|
||||||
tooltip.add(Component.literal(("\u00A7f\u00A7lLevel:" + new java.text.DecimalFormat("##").format(itemstack.getOrCreateTag().getDouble("level")) + " "
|
|
||||||
+ new java.text.DecimalFormat("##.##").format(100 * (itemstack.getOrCreateTag().getDouble("damagenow") / itemstack.getOrCreateTag().getDouble("damageneed"))) + "%")));
|
|
||||||
} else if (4 <= itemstack.getOrCreateTag().getDouble("level") && itemstack.getOrCreateTag().getDouble("level") < 6) {
|
|
||||||
tooltip.add(Component.literal(("\u00A7b\u00A7lLevel:" + new java.text.DecimalFormat("##").format(itemstack.getOrCreateTag().getDouble("level")) + " "
|
|
||||||
+ new java.text.DecimalFormat("##.##").format(100 * (itemstack.getOrCreateTag().getDouble("damagenow") / itemstack.getOrCreateTag().getDouble("damageneed"))) + "%")));
|
|
||||||
} else if (6 <= itemstack.getOrCreateTag().getDouble("level") && itemstack.getOrCreateTag().getDouble("level") < 8) {
|
|
||||||
tooltip.add(Component.literal(("\u00A7d\u00A7lLevel:" + new java.text.DecimalFormat("##").format(itemstack.getOrCreateTag().getDouble("level")) + " "
|
|
||||||
+ new java.text.DecimalFormat("##.##").format(100 * (itemstack.getOrCreateTag().getDouble("damagenow") / itemstack.getOrCreateTag().getDouble("damageneed"))) + "%")));
|
|
||||||
} else if (8 <= itemstack.getOrCreateTag().getDouble("level") && itemstack.getOrCreateTag().getDouble("level") < 10) {
|
|
||||||
tooltip.add(Component.literal(("\u00A76\u00A7lLevel:" + new java.text.DecimalFormat("##").format(itemstack.getOrCreateTag().getDouble("level")) + " "
|
|
||||||
+ new java.text.DecimalFormat("##.##").format(100 * (itemstack.getOrCreateTag().getDouble("damagenow") / itemstack.getOrCreateTag().getDouble("damageneed"))) + "%")));
|
|
||||||
} else if (10 <= itemstack.getOrCreateTag().getDouble("level")) {
|
|
||||||
tooltip.add(Component.literal(("\u00A7c\u00A7lLevel:" + new java.text.DecimalFormat("##").format(itemstack.getOrCreateTag().getDouble("level")) + " "
|
|
||||||
+ new java.text.DecimalFormat("##.##").format(100 * (itemstack.getOrCreateTag().getDouble("damagenow") / itemstack.getOrCreateTag().getDouble("damageneed"))) + "%")));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (itemstack.getItem() == TargetModItems.CREATIVE_AMMO_BOX.get()) {
|
if (itemstack.getItem() == TargetModItems.CREATIVE_AMMO_BOX.get()) {
|
||||||
tooltip.add(Component.literal("Creative Ammo * 2147483647"));
|
tooltip.add(Component.literal("Creative Ammo * 2147483647"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ public class WeaponLevelProcedure {
|
||||||
private static void execute(@Nullable Event event, Entity entity) {
|
private static void execute(@Nullable Event event, Entity entity) {
|
||||||
if (entity == null)
|
if (entity == null)
|
||||||
return;
|
return;
|
||||||
ItemStack stack = ItemStack.EMPTY;
|
ItemStack stack;
|
||||||
stack = (entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY);
|
stack = (entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY);
|
||||||
if (stack.is(ItemTags.create(new ResourceLocation("target:gun")))) {
|
if (stack.is(ItemTags.create(new ResourceLocation("target:gun")))) {
|
||||||
if (stack.getOrCreateTag().getDouble("level") == 0) {
|
if (stack.getOrCreateTag().getDouble("level") == 0) {
|
||||||
|
|
|
@ -4,14 +4,14 @@ import net.minecraft.world.item.ItemStack;
|
||||||
|
|
||||||
//from Botania
|
//from Botania
|
||||||
public final class ItemNBTTool {
|
public final class ItemNBTTool {
|
||||||
public static void setBoolean(ItemStack stack, String tag, boolean b) {
|
|
||||||
stack.getOrCreateTag().putBoolean(tag, b);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean verifyExistence(ItemStack stack, String tag) {
|
public static boolean verifyExistence(ItemStack stack, String tag) {
|
||||||
return !stack.isEmpty() && stack.getOrCreateTag().contains(tag);
|
return !stack.isEmpty() && stack.getOrCreateTag().contains(tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setBoolean(ItemStack stack, String tag, boolean b) {
|
||||||
|
stack.getOrCreateTag().putBoolean(tag, b);
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean getBoolean(ItemStack stack, String tag, boolean defaultExpected) {
|
public static boolean getBoolean(ItemStack stack, String tag, boolean defaultExpected) {
|
||||||
return verifyExistence(stack, tag) ? stack.getOrCreateTag().getBoolean(tag) : defaultExpected;
|
return verifyExistence(stack, tag) ? stack.getOrCreateTag().getBoolean(tag) : defaultExpected;
|
||||||
}
|
}
|
||||||
|
@ -39,4 +39,12 @@ public final class ItemNBTTool {
|
||||||
public static long getLong(ItemStack stack, String tag, long num) {
|
public static long getLong(ItemStack stack, String tag, long num) {
|
||||||
return verifyExistence(stack, tag) ? stack.getOrCreateTag().getLong(tag) : num;
|
return verifyExistence(stack, tag) ? stack.getOrCreateTag().getLong(tag) : num;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setDouble(ItemStack stack, String tag, double num) {
|
||||||
|
stack.getOrCreateTag().putDouble(tag, num);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double getDouble(ItemStack stack, String tag, double num) {
|
||||||
|
return verifyExistence(stack, tag) ? stack.getOrCreateTag().getDouble(tag) : num;
|
||||||
|
}
|
||||||
}
|
}
|
50
src/main/java/net/mcreator/target/tools/TooltipTool.java
Normal file
50
src/main/java/net/mcreator/target/tools/TooltipTool.java
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
package net.mcreator.target.tools;
|
||||||
|
|
||||||
|
import net.minecraft.ChatFormatting;
|
||||||
|
import net.minecraft.client.gui.screens.Screen;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
|
||||||
|
import java.text.DecimalFormat;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class TooltipTool {
|
||||||
|
|
||||||
|
public static void addHideText(List<Component> tooltip, Component text) {
|
||||||
|
if (Screen.hasShiftDown()) {
|
||||||
|
tooltip.add(text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void addGunTips(List<Component> tooltip, ItemStack stack) {
|
||||||
|
tooltip.add(Component.literal(""));
|
||||||
|
|
||||||
|
double damage = (ItemNBTTool.getDouble(stack, "damage", 0) +
|
||||||
|
ItemNBTTool.getDouble(stack, "adddamage", 0))
|
||||||
|
* ItemNBTTool.getDouble(stack, "damageadd", 1);
|
||||||
|
|
||||||
|
tooltip.add(Component.translatable("des.target.tips.damage").withStyle(ChatFormatting.WHITE)
|
||||||
|
.append(Component.literal("").withStyle(ChatFormatting.RESET))
|
||||||
|
.append(Component.literal(new DecimalFormat("##.#").format(damage)).withStyle(ChatFormatting.GREEN)));
|
||||||
|
|
||||||
|
int level = (int) ItemNBTTool.getDouble(stack, "level", 0);
|
||||||
|
double rate = ItemNBTTool.getDouble(stack, "damagenow", 0) / ItemNBTTool.getDouble(stack, "damageneed", 1);
|
||||||
|
|
||||||
|
ChatFormatting formatting;
|
||||||
|
if (level < 4) {
|
||||||
|
formatting = ChatFormatting.GRAY;
|
||||||
|
} else if (level < 6) {
|
||||||
|
formatting = ChatFormatting.AQUA;
|
||||||
|
} else if (level < 8) {
|
||||||
|
formatting = ChatFormatting.LIGHT_PURPLE;
|
||||||
|
} else if (level < 10) {
|
||||||
|
formatting = ChatFormatting.GOLD;
|
||||||
|
} else {
|
||||||
|
formatting = ChatFormatting.RED;
|
||||||
|
}
|
||||||
|
|
||||||
|
tooltip.add(Component.translatable("des.target.tips.level").withStyle(ChatFormatting.WHITE)
|
||||||
|
.append(Component.literal("").withStyle(ChatFormatting.RESET))
|
||||||
|
.append(Component.literal(level + " " + new DecimalFormat("##.##").format(rate) + "%")).withStyle(formatting).withStyle(ChatFormatting.BOLD));
|
||||||
|
}
|
||||||
|
}
|
|
@ -30,6 +30,9 @@
|
||||||
"item.target.svd": "SVD",
|
"item.target.svd": "SVD",
|
||||||
"item.target.kraber": "KRABER",
|
"item.target.kraber": "KRABER",
|
||||||
|
|
||||||
|
"des.target.tips.damage": "Damage: ",
|
||||||
|
"des.target.tips.level": "Level: ",
|
||||||
|
|
||||||
"item.target.vector_blueprint": "VECTOR Blueprint",
|
"item.target.vector_blueprint": "VECTOR Blueprint",
|
||||||
"item.target.m_60_blueprint": "M60 Blueprint",
|
"item.target.m_60_blueprint": "M60 Blueprint",
|
||||||
"item.target.hk_416_blueprint": "Hk-416 Blueprint",
|
"item.target.hk_416_blueprint": "Hk-416 Blueprint",
|
||||||
|
|
|
@ -30,6 +30,9 @@
|
||||||
"item.target.svd": "SVD狙击步枪",
|
"item.target.svd": "SVD狙击步枪",
|
||||||
"item.target.kraber": "克莱贝尔狙击步枪",
|
"item.target.kraber": "克莱贝尔狙击步枪",
|
||||||
|
|
||||||
|
"des.target.tips.damage": "伤害: ",
|
||||||
|
"des.target.tips.level": "等级: ",
|
||||||
|
|
||||||
"item.target.vector_blueprint": "短剑冲锋枪蓝图",
|
"item.target.vector_blueprint": "短剑冲锋枪蓝图",
|
||||||
"item.target.m_60_blueprint": "M60通用机枪蓝图",
|
"item.target.m_60_blueprint": "M60通用机枪蓝图",
|
||||||
"item.target.hk_416_blueprint": "Hk-416突击步枪蓝图",
|
"item.target.hk_416_blueprint": "Hk-416突击步枪蓝图",
|
||||||
|
|
Loading…
Add table
Reference in a new issue