添加perk相关tool
This commit is contained in:
parent
c0ef2678f2
commit
6a715f7721
6 changed files with 95 additions and 8 deletions
|
@ -0,0 +1,28 @@
|
||||||
|
package net.mcreator.superbwarfare.event;
|
||||||
|
|
||||||
|
import net.mcreator.superbwarfare.item.PerkItem;
|
||||||
|
import net.mcreator.superbwarfare.perk.PerkHelper;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import net.minecraftforge.event.AnvilUpdateEvent;
|
||||||
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
|
import net.minecraftforge.fml.common.Mod;
|
||||||
|
|
||||||
|
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE)
|
||||||
|
public class TempEventHandler {
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onAnvilUpdate(AnvilUpdateEvent event) {
|
||||||
|
ItemStack left = event.getLeft();
|
||||||
|
ItemStack right = event.getRight();
|
||||||
|
|
||||||
|
if (right.getItem() instanceof PerkItem perkItem) {
|
||||||
|
ItemStack output = left.copy();
|
||||||
|
|
||||||
|
PerkHelper.setPerk(output, perkItem.getPerk());
|
||||||
|
|
||||||
|
event.setOutput(output);
|
||||||
|
event.setCost(10);
|
||||||
|
event.setMaterialCost(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -11,7 +11,7 @@ public class Perk {
|
||||||
|
|
||||||
public enum Type {
|
public enum Type {
|
||||||
AMMO("Ammo"),
|
AMMO("Ammo"),
|
||||||
FUNCTIONAL("Func"),
|
FUNCTIONAL("Functional"),
|
||||||
DAMAGE("Damage");
|
DAMAGE("Damage");
|
||||||
private final String type;
|
private final String type;
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,9 @@ public class PerkHelper {
|
||||||
private static final String TAG_PERK_LEVEL = "level";
|
private static final String TAG_PERK_LEVEL = "level";
|
||||||
private static final String TAG_PERK = "Perks";
|
private static final String TAG_PERK = "Perks";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 把一个Perk封装成nbt进行存储
|
||||||
|
*/
|
||||||
public static CompoundTag makePerk(@Nullable ResourceLocation pId, int pLevel) {
|
public static CompoundTag makePerk(@Nullable ResourceLocation pId, int pLevel) {
|
||||||
CompoundTag compoundtag = new CompoundTag();
|
CompoundTag compoundtag = new CompoundTag();
|
||||||
compoundtag.putString(TAG_PERK_ID, String.valueOf(pId));
|
compoundtag.putString(TAG_PERK_ID, String.valueOf(pId));
|
||||||
|
@ -38,7 +41,7 @@ public class PerkHelper {
|
||||||
@Nullable
|
@Nullable
|
||||||
public static ResourceLocation getPerkId(Perk perk) {
|
public static ResourceLocation getPerkId(Perk perk) {
|
||||||
return ModPerks.PERKS.getEntries().stream()
|
return ModPerks.PERKS.getEntries().stream()
|
||||||
.filter(p -> p.get().type == perk.type)
|
.filter(p -> p.get().descriptionId.equals(perk.descriptionId))
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.map(RegistryObject::getId)
|
.map(RegistryObject::getId)
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
|
@ -61,4 +64,15 @@ public class PerkHelper {
|
||||||
return tag.getCompound(type.getName());
|
return tag.getCompound(type.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setPerk(ItemStack stack, Perk perk, int level) {
|
||||||
|
CompoundTag perkTag = new CompoundTag();
|
||||||
|
perkTag.put(perk.type.getName(), makePerk(getPerkId(perk), level));
|
||||||
|
|
||||||
|
stack.addTagElement(TAG_PERK, perkTag);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setPerk(ItemStack stack, Perk perk) {
|
||||||
|
setPerk(stack, perk, 1);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
package net.mcreator.superbwarfare.tools;
|
package net.mcreator.superbwarfare.tools;
|
||||||
|
|
||||||
import net.mcreator.superbwarfare.entity.DroneEntity;
|
import net.mcreator.superbwarfare.entity.DroneEntity;
|
||||||
|
import net.mcreator.superbwarfare.perk.Perk;
|
||||||
|
import net.mcreator.superbwarfare.perk.PerkHelper;
|
||||||
import net.minecraft.ChatFormatting;
|
import net.minecraft.ChatFormatting;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gui.screens.Screen;
|
import net.minecraft.client.gui.screens.Screen;
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
@ -33,6 +36,7 @@ public class TooltipTool {
|
||||||
|
|
||||||
addLevelTips(tooltip, stack);
|
addLevelTips(tooltip, stack);
|
||||||
addBypassTips(tooltip, stack);
|
addBypassTips(tooltip, stack);
|
||||||
|
addPerkTips(tooltip, stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addShotgunTips(List<Component> tooltip, ItemStack stack, int count) {
|
public static void addShotgunTips(List<Component> tooltip, ItemStack stack, int count) {
|
||||||
|
@ -78,7 +82,46 @@ public class TooltipTool {
|
||||||
tooltip.add(Component.translatable("des.superbwarfare.tips.bypass").withStyle(ChatFormatting.GRAY)
|
tooltip.add(Component.translatable("des.superbwarfare.tips.bypass").withStyle(ChatFormatting.GRAY)
|
||||||
.append(Component.literal("").withStyle(ChatFormatting.RESET))
|
.append(Component.literal("").withStyle(ChatFormatting.RESET))
|
||||||
.append(Component.literal(new DecimalFormat("##.##").format(byPassRate * 100) + "%").withStyle(ChatFormatting.GOLD).withStyle(ChatFormatting.BOLD)));
|
.append(Component.literal(new DecimalFormat("##.##").format(byPassRate * 100) + "%").withStyle(ChatFormatting.GOLD).withStyle(ChatFormatting.BOLD)));
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO 实现正确的nbt获取
|
||||||
|
private static void addPerkTips(List<Component> tooltip, ItemStack stack) {
|
||||||
|
CompoundTag ammoTag = PerkHelper.getPerkTag(stack, Perk.Type.AMMO);
|
||||||
|
CompoundTag functionalTag = PerkHelper.getPerkTag(stack, Perk.Type.FUNCTIONAL);
|
||||||
|
CompoundTag damageTag = PerkHelper.getPerkTag(stack, Perk.Type.DAMAGE);
|
||||||
|
|
||||||
|
tooltip.add(Component.literal(damageTag.toString()));
|
||||||
|
|
||||||
|
if (!ammoTag.isEmpty() || !functionalTag.isEmpty() || !damageTag.isEmpty()) {
|
||||||
|
tooltip.add(Component.translatable("perk.superbwarfare.tips").withStyle(ChatFormatting.WHITE));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ammoTag.isEmpty()) {
|
||||||
|
tooltip.add(Component.translatable("perk.superbwarfare.slot_Ammo").withStyle(ChatFormatting.YELLOW)
|
||||||
|
.append(Component.literal(" >> "))
|
||||||
|
.append(Component.literal("").withStyle(ChatFormatting.RESET))
|
||||||
|
.append(Component.translatable("item.superbwarfare." + ammoTag.getString("id")).withStyle(ChatFormatting.GRAY))
|
||||||
|
.append(Component.literal("Lvl. " + ammoTag.getInt("level")).withStyle(ChatFormatting.GRAY)));
|
||||||
|
addHideText(tooltip, Component.translatable("perk.superbwarfare." + ammoTag.getString("id") + ".desc").withStyle(ChatFormatting.GRAY));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!functionalTag.isEmpty()) {
|
||||||
|
tooltip.add(Component.translatable("perk.superbwarfare.slot_Functional").withStyle(ChatFormatting.GREEN)
|
||||||
|
.append(Component.literal(" >> "))
|
||||||
|
.append(Component.literal("").withStyle(ChatFormatting.RESET))
|
||||||
|
.append(Component.translatable("item.superbwarfare." + functionalTag.getString("id")).withStyle(ChatFormatting.GRAY))
|
||||||
|
.append(Component.literal("Lvl. " + functionalTag.getInt("level")).withStyle(ChatFormatting.GRAY)));
|
||||||
|
addHideText(tooltip, Component.translatable("perk.superbwarfare." + functionalTag.getString("id") + ".desc").withStyle(ChatFormatting.GRAY));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!damageTag.isEmpty()) {
|
||||||
|
tooltip.add(Component.translatable("perk.superbwarfare.slot_Damage").withStyle(ChatFormatting.RED)
|
||||||
|
.append(Component.literal(" >> "))
|
||||||
|
.append(Component.literal("").withStyle(ChatFormatting.RESET))
|
||||||
|
.append(Component.translatable("item.superbwarfare." + damageTag.getString("id")).withStyle(ChatFormatting.GRAY))
|
||||||
|
.append(Component.literal("Lvl. " + damageTag.getInt("level")).withStyle(ChatFormatting.GRAY)));
|
||||||
|
addHideText(tooltip, Component.translatable("perk.superbwarfare." + damageTag.getString("id") + ".desc").withStyle(ChatFormatting.GRAY));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addBocekTips(List<Component> tooltip, ItemStack stack) {
|
public static void addBocekTips(List<Component> tooltip, ItemStack stack) {
|
||||||
|
|
|
@ -177,10 +177,11 @@
|
||||||
|
|
||||||
"item.superbwarfare.kill_clip": "Kill Clip",
|
"item.superbwarfare.kill_clip": "Kill Clip",
|
||||||
|
|
||||||
|
"perk.superbwarfare.tips": "[Perks]",
|
||||||
"perk.superbwarfare.slot": "Type: ",
|
"perk.superbwarfare.slot": "Type: ",
|
||||||
"perk.superbwarfare.slot_0": "Ammo Perk",
|
"perk.superbwarfare.slot_Ammo": "子弹模组",
|
||||||
"perk.superbwarfare.slot_1": "Functional Perk",
|
"perk.superbwarfare.slot_Functional": "功能模组",
|
||||||
"perk.superbwarfare.slot_2": "Damage Perk",
|
"perk.superbwarfare.slot_Damage": "伤害模组",
|
||||||
"perk.superbwarfare.kill_clip.desc": "Increases the damage of weapon after dealing a final blow",
|
"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",
|
||||||
|
|
|
@ -177,10 +177,11 @@
|
||||||
|
|
||||||
"item.superbwarfare.kill_clip": "杀戮弹匣",
|
"item.superbwarfare.kill_clip": "杀戮弹匣",
|
||||||
|
|
||||||
|
"perk.superbwarfare.tips": "[武器模组]",
|
||||||
"perk.superbwarfare.slot": "类型: ",
|
"perk.superbwarfare.slot": "类型: ",
|
||||||
"perk.superbwarfare.slot_0": "子弹模组",
|
"perk.superbwarfare.slot_Ammo": "子弹模组",
|
||||||
"perk.superbwarfare.slot_1": "功能模组",
|
"perk.superbwarfare.slot_Functional": "功能模组",
|
||||||
"perk.superbwarfare.slot_2": "伤害模组",
|
"perk.superbwarfare.slot_Damage": "伤害模组",
|
||||||
"perk.superbwarfare.kill_clip.desc": "完成击杀后填装可提升武器伤害",
|
"perk.superbwarfare.kill_clip.desc": "完成击杀后填装可提升武器伤害",
|
||||||
|
|
||||||
"death.attack.gunfire": "%1$s被%2$s射爆了",
|
"death.attack.gunfire": "%1$s被%2$s射爆了",
|
||||||
|
|
Loading…
Add table
Reference in a new issue