- 205
- 12
- 103
Привет. Такая ситуация: Я сделал 1 общий класс для зелек восстановления ХП, объем восстанавливаемого здоровья внес в конструктор и определяю при регистрации предмета, но теперь не знаю как его можно получить.
Класс предмета:
Регистрация:
Внешне вроде вопрос простой, но я чёт не могу допереть как это можно сделать.
Класс предмета:
Java:
public class HealingPotionItem extends Item {
public HealingPotionItem(float healAmount, Properties properties) {
super(properties);
}
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) {
ItemStack itemstack = playerIn.getHeldItem(handIn);
if (playerIn.getActivePotionEffect(ModEffects.Effects.potion_sickness) == null) {
playerIn.heal(healAmount); //Вот тут должно быть количество восстанавливаемого здоровья, которое я определяю при регистрации
if (!playerIn.abilities.isCreativeMode) {
itemstack.shrink(1);
}
playerIn.addStat(Stats.ITEM_USED.get(this));
playerIn.addPotionEffect(new EffectInstance(ModEffects.Effects.potion_sickness, 1200));
worldIn.playSound((PlayerEntity) null, playerIn.getPosX(), playerIn.getPosY(), playerIn.getPosZ(), ModSounds.POTION_USE, SoundCategory.NEUTRAL, 1.0F, 1.0F);
}
return ActionResult.resultPass(itemstack);
}
}
Регистрация:
Java:
@Mod.EventBusSubscriber(modid = Reference.MODID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class PotionItems {
public static class Items {
public static Item lesser_healing_potion;
public static Item healing_potion;
public static Item greater_healing_potion;
}
@SubscribeEvent
public static void onItemRegistry(RegistryEvent.Register<Item> event) {
Items.lesser_healing_potion = registerItem(new HealingPotionItem(50, new Item.Properties()
.group(items_item_group)
.maxStackSize(30))
.setRegistryName("lesser_healing_potion"));
Items.healing_potion = registerItem(new HealingPotionItem(100, new Item.Properties()
.group(items_item_group)
.maxStackSize(30))
.setRegistryName("healing_potion"));
Items.greater_healing_potion = registerItem(new HealingPotionItem(150, new Item.Properties()
.group(items_item_group)
.maxStackSize(30))
.setRegistryName("greater_healing_potion"));
}
}
Внешне вроде вопрос простой, но я чёт не могу допереть как это можно сделать.