添加PerkItem示例

This commit is contained in:
17146 2024-08-08 01:02:34 +08:00
parent 755ee4fe3a
commit 1a570d1c08
7 changed files with 77 additions and 9 deletions

View file

@ -186,10 +186,19 @@ public class ModItems {
return BLOCKS.register(block.getId().getPath(), () -> new BlockItem(block.get(), new Item.Properties())); return BLOCKS.register(block.getId().getPath(), () -> new BlockItem(block.get(), new Item.Properties()));
} }
/**
* Perk Items
*/
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 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);
PERKS.register(bus);
} }
} }

View file

@ -20,10 +20,10 @@ public class ModPerks {
public static final DeferredRegister<Perk> PERKS = DeferredRegister.create(new ResourceLocation(ModUtils.MODID, "perk"), ModUtils.MODID); public static final DeferredRegister<Perk> PERKS = DeferredRegister.create(new ResourceLocation(ModUtils.MODID, "perk"), ModUtils.MODID);
public static final RegistryObject<Perk> FOURTH_TIMES_CHARM = PERKS.register("fourth_times_charm", () -> new Perk(Perk.Type.FUNCTIONAL)); public static final RegistryObject<Perk> FOURTH_TIMES_CHARM = PERKS.register("fourth_times_charm", () -> new Perk("fourth_times_charm", Perk.Type.FUNCTIONAL));
public static final RegistryObject<Perk> GUTSHOT_STRAIGHT = PERKS.register("gutshot_straight", () -> new Perk(Perk.Type.DAMAGE)); public static final RegistryObject<Perk> GUTSHOT_STRAIGHT = PERKS.register("gutshot_straight", () -> new Perk("gutshot_straight", Perk.Type.DAMAGE));
public static final RegistryObject<Perk> HEAL_CLIP = PERKS.register("heal_clip", () -> new Perk(Perk.Type.FUNCTIONAL)); public static final RegistryObject<Perk> HEAL_CLIP = PERKS.register("heal_clip", () -> new Perk("heal_clip", Perk.Type.FUNCTIONAL));
public static final RegistryObject<Perk> KILL_CLIP = PERKS.register("kill_clip", () -> new Perk(Perk.Type.DAMAGE)); public static final RegistryObject<Perk> KILL_CLIP = PERKS.register("kill_clip", () -> new Perk("kill_clip", Perk.Type.DAMAGE));
public static final RegistryObject<Perk> KILLING_TALLY = PERKS.register("killing_tally", () -> new Perk(Perk.Type.DAMAGE)); public static final RegistryObject<Perk> KILLING_TALLY = PERKS.register("killing_tally", () -> new Perk("killing_tally", Perk.Type.DAMAGE));
public static final RegistryObject<Perk> MONSTER_HUNTER = PERKS.register("monster_hunter", () -> new Perk(Perk.Type.DAMAGE)); public static final RegistryObject<Perk> MONSTER_HUNTER = PERKS.register("monster_hunter", () -> new Perk("monster_hunter", Perk.Type.DAMAGE));
} }

View file

@ -1,10 +1,46 @@
package net.mcreator.superbwarfare.item; package net.mcreator.superbwarfare.item;
import net.mcreator.superbwarfare.perk.Perk;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.Item; import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Rarity;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.function.Supplier;
public class PerkItem extends Item { public class PerkItem extends Item {
private final Supplier<Perk> perk;
public PerkItem(Properties pProperties) { public PerkItem(Supplier<Perk> perk) {
super(pProperties); super(new Properties());
this.perk = perk;
}
public PerkItem(Supplier<Perk> perk, Rarity rarity) {
super(new Properties().rarity(rarity));
this.perk = perk;
}
public Perk getPerk() {
return this.perk.get();
}
@Override
public void appendHoverText(ItemStack stack, @Nullable Level level, List<Component> tooltips, TooltipFlag isAdvanced) {
ChatFormatting chatFormatting = switch (this.getPerk().type.getSlot()) {
case 0 -> ChatFormatting.YELLOW;
case 1 -> ChatFormatting.GREEN;
default -> ChatFormatting.RED;
};
tooltips.add(Component.translatable("perk.superbwarfare." + this.getPerk().descriptionId + ".desc").withStyle(ChatFormatting.GRAY));
tooltips.add(Component.literal(""));
tooltips.add(Component.translatable("perk.superbwarfare.slot").withStyle(ChatFormatting.GOLD)
.append(Component.translatable("perk.superbwarfare.slot_" + this.getPerk().type.getSlot()).withStyle(chatFormatting)));
} }
} }

View file

@ -5,6 +5,7 @@ import net.mcreator.superbwarfare.init.ModEnchantments;
import net.mcreator.superbwarfare.init.ModItems; import net.mcreator.superbwarfare.init.ModItems;
import net.mcreator.superbwarfare.init.ModTags; import net.mcreator.superbwarfare.init.ModTags;
import net.mcreator.superbwarfare.network.ModVariables; import net.mcreator.superbwarfare.network.ModVariables;
import net.mcreator.superbwarfare.perk.Perk;
import net.mcreator.superbwarfare.tools.EnchantmentCategoryTool; import net.mcreator.superbwarfare.tools.EnchantmentCategoryTool;
import net.mcreator.superbwarfare.tools.GunsTool; import net.mcreator.superbwarfare.tools.GunsTool;
import net.mcreator.superbwarfare.tools.ItemNBTTool; import net.mcreator.superbwarfare.tools.ItemNBTTool;
@ -176,4 +177,8 @@ public abstract class GunItem extends Item {
} }
} }
} }
public boolean canApplyPerk(ItemStack stack, Perk perk, int slot) {
return perk.type.getSlot() == slot;
}
} }

View file

@ -1,9 +1,11 @@
package net.mcreator.superbwarfare.perk; package net.mcreator.superbwarfare.perk;
public class Perk { public class Perk {
public String descriptionId;
public Type type; public Type type;
public Perk(Type type) { public Perk(String descriptionId, Type type) {
this.descriptionId = descriptionId;
this.type = type; this.type = type;
} }

View file

@ -175,6 +175,14 @@
"item.superbwarfare.galena": "Raw Galena", "item.superbwarfare.galena": "Raw Galena",
"item.superbwarfare.scheelite": "Raw Galena", "item.superbwarfare.scheelite": "Raw Galena",
"item.superbwarfare.kill_clip": "Kill Clip",
"perk.superbwarfare.slot": "Type: ",
"perk.superbwarfare.slot_0": "Ammo Perk",
"perk.superbwarfare.slot_1": "Functional Perk",
"perk.superbwarfare.slot_2": "Damage Perk",
"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",
"death.attack.gunfire.item": "%1$s was shoot by %2$s using %3$s", "death.attack.gunfire.item": "%1$s was shoot by %2$s using %3$s",

View file

@ -175,6 +175,14 @@
"item.superbwarfare.galena": "粗方铅矿", "item.superbwarfare.galena": "粗方铅矿",
"item.superbwarfare.scheelite": "白钨矿", "item.superbwarfare.scheelite": "白钨矿",
"item.superbwarfare.kill_clip": "杀戮弹匣",
"perk.superbwarfare.slot": "类型: ",
"perk.superbwarfare.slot_0": "子弹模组",
"perk.superbwarfare.slot_1": "功能模组",
"perk.superbwarfare.slot_2": "伤害模组",
"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射爆了",
"death.attack.gunfire.item": "%1$s被%2$s用%3$s射爆了", "death.attack.gunfire.item": "%1$s被%2$s用%3$s射爆了",