修改perk设置方法,添加自动注册perkItem
This commit is contained in:
parent
e8d6c6fd38
commit
561fe80f57
6 changed files with 24 additions and 10 deletions
|
@ -191,14 +191,16 @@ public class ModItems {
|
||||||
*/
|
*/
|
||||||
public static final DeferredRegister<Item> PERKS = DeferredRegister.create(ForgeRegistries.ITEMS, ModUtils.MODID);
|
public static final DeferredRegister<Item> PERKS = DeferredRegister.create(ForgeRegistries.ITEMS, ModUtils.MODID);
|
||||||
|
|
||||||
public static final RegistryObject<Item> KILL_CLIP = PERKS.register("kill_clip", () -> new PerkItem(ModPerks.KILL_CLIP));
|
public static void registerPerkItems() {
|
||||||
|
ModPerks.PERKS.getEntries().forEach(registryObject -> PERKS.register(registryObject.getId().getPath(), () -> new PerkItem(registryObject)));
|
||||||
|
}
|
||||||
|
|
||||||
public static void register(IEventBus bus) {
|
public static void register(IEventBus bus) {
|
||||||
ITEMS.register(bus);
|
ITEMS.register(bus);
|
||||||
GUNS.register(bus);
|
GUNS.register(bus);
|
||||||
AMMO.register(bus);
|
AMMO.register(bus);
|
||||||
BLOCKS.register(bus);
|
BLOCKS.register(bus);
|
||||||
|
registerPerkItems();
|
||||||
PERKS.register(bus);
|
PERKS.register(bus);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ public class PerkItem extends Item {
|
||||||
case DAMAGE -> ChatFormatting.RED;
|
case DAMAGE -> ChatFormatting.RED;
|
||||||
};
|
};
|
||||||
|
|
||||||
tooltips.add(Component.translatable("perk.superbwarfare." + this.getPerk().descriptionId + ".desc").withStyle(ChatFormatting.GRAY));
|
tooltips.add(Component.translatable("des.superbwarfare." + this.getPerk().descriptionId).withStyle(ChatFormatting.GRAY));
|
||||||
tooltips.add(Component.literal(""));
|
tooltips.add(Component.literal(""));
|
||||||
tooltips.add(Component.translatable("perk.superbwarfare.slot").withStyle(ChatFormatting.GOLD)
|
tooltips.add(Component.translatable("perk.superbwarfare.slot").withStyle(ChatFormatting.GOLD)
|
||||||
.append(Component.translatable("perk.superbwarfare.slot_" + this.getPerk().type.getName()).withStyle(chatFormatting)));
|
.append(Component.translatable("perk.superbwarfare.slot_" + this.getPerk().type.getName()).withStyle(chatFormatting)));
|
||||||
|
|
|
@ -65,9 +65,17 @@ public class PerkHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setPerk(ItemStack stack, Perk perk, int level) {
|
public static void setPerk(ItemStack stack, Perk perk, int level) {
|
||||||
CompoundTag perkTag = new CompoundTag();
|
var tag = stack.getTag();
|
||||||
perkTag.put(perk.type.getName(), makePerk(getPerkId(perk), level));
|
if (tag == null) {
|
||||||
|
tag = new CompoundTag();
|
||||||
|
}
|
||||||
|
|
||||||
|
var perkTag = tag.getCompound(TAG_PERK);
|
||||||
|
if (perkTag.isEmpty()) {
|
||||||
|
perkTag = new CompoundTag();
|
||||||
|
}
|
||||||
|
|
||||||
|
perkTag.put(perk.type.getName(), makePerk(getPerkId(perk), level));
|
||||||
stack.addTagElement(TAG_PERK, perkTag);
|
stack.addTagElement(TAG_PERK, perkTag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -101,7 +101,7 @@ public class TooltipTool {
|
||||||
.append(Component.literal("").withStyle(ChatFormatting.RESET))
|
.append(Component.literal("").withStyle(ChatFormatting.RESET))
|
||||||
.append(Component.translatable("item.superbwarfare." + id).withStyle(ChatFormatting.WHITE))
|
.append(Component.translatable("item.superbwarfare." + id).withStyle(ChatFormatting.WHITE))
|
||||||
.append(Component.literal(" Lvl. " + ammoTag.getInt("level")).withStyle(ChatFormatting.WHITE)));
|
.append(Component.literal(" Lvl. " + ammoTag.getInt("level")).withStyle(ChatFormatting.WHITE)));
|
||||||
addHideText(tooltip, Component.translatable("perk.superbwarfare." + id + ".desc").withStyle(ChatFormatting.GRAY));
|
addHideText(tooltip, Component.translatable("des.superbwarfare." + id).withStyle(ChatFormatting.GRAY));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!functionalTag.isEmpty()) {
|
if (!functionalTag.isEmpty()) {
|
||||||
|
@ -111,7 +111,7 @@ public class TooltipTool {
|
||||||
.append(Component.literal("").withStyle(ChatFormatting.RESET))
|
.append(Component.literal("").withStyle(ChatFormatting.RESET))
|
||||||
.append(Component.translatable("item.superbwarfare." + id).withStyle(ChatFormatting.WHITE))
|
.append(Component.translatable("item.superbwarfare." + id).withStyle(ChatFormatting.WHITE))
|
||||||
.append(Component.literal(" Lvl. " + functionalTag.getInt("level")).withStyle(ChatFormatting.WHITE)));
|
.append(Component.literal(" Lvl. " + functionalTag.getInt("level")).withStyle(ChatFormatting.WHITE)));
|
||||||
addHideText(tooltip, Component.translatable("perk.superbwarfare." + id + ".desc").withStyle(ChatFormatting.GRAY));
|
addHideText(tooltip, Component.translatable("des.superbwarfare." + id).withStyle(ChatFormatting.GRAY));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!damageTag.isEmpty()) {
|
if (!damageTag.isEmpty()) {
|
||||||
|
@ -121,7 +121,7 @@ public class TooltipTool {
|
||||||
.append(Component.literal("").withStyle(ChatFormatting.RESET))
|
.append(Component.literal("").withStyle(ChatFormatting.RESET))
|
||||||
.append(Component.translatable("item.superbwarfare." + id).withStyle(ChatFormatting.WHITE))
|
.append(Component.translatable("item.superbwarfare." + id).withStyle(ChatFormatting.WHITE))
|
||||||
.append(Component.literal(" Lvl. " + damageTag.getInt("level")).withStyle(ChatFormatting.WHITE)));
|
.append(Component.literal(" Lvl. " + damageTag.getInt("level")).withStyle(ChatFormatting.WHITE)));
|
||||||
addHideText(tooltip, Component.translatable("perk.superbwarfare." + id + ".desc").withStyle(ChatFormatting.GRAY));
|
addHideText(tooltip, Component.translatable("des.superbwarfare." + id).withStyle(ChatFormatting.GRAY));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -176,13 +176,15 @@
|
||||||
"item.superbwarfare.scheelite": "Raw Galena",
|
"item.superbwarfare.scheelite": "Raw Galena",
|
||||||
|
|
||||||
"item.superbwarfare.kill_clip": "Kill Clip",
|
"item.superbwarfare.kill_clip": "Kill Clip",
|
||||||
|
"des.superbwarfare.kill_clip": "Increases the damage of weapon after dealing a final blow",
|
||||||
|
"item.superbwarfare.heal_clip": "Heal Clip",
|
||||||
|
"des.superbwarfare.heal_clip": "Reloading after dealing a final blow will heal you and your nearby allies",
|
||||||
|
|
||||||
"perk.superbwarfare.tips": "[Perks]",
|
"perk.superbwarfare.tips": "[Perks]",
|
||||||
"perk.superbwarfare.slot": "Type: ",
|
"perk.superbwarfare.slot": "Type: ",
|
||||||
"perk.superbwarfare.slot_Ammo": "子弹模组",
|
"perk.superbwarfare.slot_Ammo": "子弹模组",
|
||||||
"perk.superbwarfare.slot_Functional": "功能模组",
|
"perk.superbwarfare.slot_Functional": "功能模组",
|
||||||
"perk.superbwarfare.slot_Damage": "伤害模组",
|
"perk.superbwarfare.slot_Damage": "伤害模组",
|
||||||
"perk.superbwarfare.kill_clip.desc": "Increases the damage of weapon after dealing a final blow",
|
|
||||||
|
|
||||||
"death.attack.gunfire": "%1$s was shoot by %2$s",
|
"death.attack.gunfire": "%1$s was shoot by %2$s",
|
||||||
"death.attack.gunfire.entity": "%1$s was shoot by %2$s",
|
"death.attack.gunfire.entity": "%1$s was shoot by %2$s",
|
||||||
|
|
|
@ -176,13 +176,15 @@
|
||||||
"item.superbwarfare.scheelite": "白钨矿",
|
"item.superbwarfare.scheelite": "白钨矿",
|
||||||
|
|
||||||
"item.superbwarfare.kill_clip": "杀戮弹匣",
|
"item.superbwarfare.kill_clip": "杀戮弹匣",
|
||||||
|
"des.superbwarfare.kill_clip": "完成击杀后填装可提升武器伤害",
|
||||||
|
"item.superbwarfare.heal_clip": "治疗弹匣",
|
||||||
|
"des.superbwarfare.heal_clip": "最后一击后短时间内填装,可治疗自身和附近队友",
|
||||||
|
|
||||||
"perk.superbwarfare.tips": "[武器模组]",
|
"perk.superbwarfare.tips": "[武器模组]",
|
||||||
"perk.superbwarfare.slot": "类型: ",
|
"perk.superbwarfare.slot": "类型: ",
|
||||||
"perk.superbwarfare.slot_Ammo": "子弹模组",
|
"perk.superbwarfare.slot_Ammo": "子弹模组",
|
||||||
"perk.superbwarfare.slot_Functional": "功能模组",
|
"perk.superbwarfare.slot_Functional": "功能模组",
|
||||||
"perk.superbwarfare.slot_Damage": "伤害模组",
|
"perk.superbwarfare.slot_Damage": "伤害模组",
|
||||||
"perk.superbwarfare.kill_clip.desc": "完成击杀后填装可提升武器伤害",
|
|
||||||
|
|
||||||
"death.attack.gunfire": "%1$s被%2$s射爆了",
|
"death.attack.gunfire": "%1$s被%2$s射爆了",
|
||||||
"death.attack.gunfire.entity": "%1$s被%2$s射爆了",
|
"death.attack.gunfire.entity": "%1$s被%2$s射爆了",
|
||||||
|
|
Loading…
Add table
Reference in a new issue