[1.7.10] Ивенты не хотят "ловится"

Статус
В этой теме нельзя размещать новые ответы.
13
0
Ткните носом в ошибку 
Код:
     @EventHandler
     public void GiveHealthToBag(AttackEntityEvent attackevent,ItemStack stack){
         if(attackevent.entityPlayer.inventory.hasItem(BaseMyMod.bagofhealth)){
             stack.stackTagCompound.setInteger("HealthInBag",1 + stack.stackTagCompound.getInteger("HealthInBag"));
 
код предмета
Код:
package com.blabla.mymod;

import java.util.List;

import cpw.mods.fml.common.Mod.EventHandler;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.world.World;
import net.minecraftforge.event.entity.player.AttackEntityEvent;
import net.minecraftforge.common.MinecraftForge;

public class BagOfHealth extends Item {
     public BagOfHealth() {
            this.setTextureName("mymod:BagOfHealth");
            this.setCreativeTab(CreativeTabs.tabMisc);
            this.setMaxStackSize(1);
        }
     public void onUpdate(ItemStack stack, World world, Entity entity,int per, boolean bool) {
         if (stack.stackTagCompound == null) {
         stack.stackTagCompound = new NBTTagCompound();
        stack.stackTagCompound.setInteger("HealthInBag",0);}}
     @EventHandler
     public void GiveHealthToBag(AttackEntityEvent attackevent,ItemStack stack){
         if(attackevent.entityPlayer.inventory.hasItem(BaseMyMod.bagofhealth)){
             stack.stackTagCompound.setInteger("HealthInBag",1 + stack.stackTagCompound.getInteger("HealthInBag"));
         }}
         public void addInformation(ItemStack stack, EntityPlayer player,List list, boolean bool) {
                if (stack.stackTagCompound != null) { 
                int HealthInBag = stack.stackTagCompound.getInteger("HealthInBag");
                list.add(EnumChatFormatting.RED + "Stored health: " + HealthInBag);
                }}
}
 
1. Какая версия Minecraft?
2. С чего ты взял что нужно использовать "@EventHandler"?
3. С чего ты взял что у тебя эвант заработает?
3.1. Ты эвант зарегистрировал?
 
У меня такая-же версия Minecraft и работаю на Eclipse. "@EventHandler" у меня не работает, а на "@SubscribeEvent" не нравиться "ItemStack stack" в:
Код:
public void GiveHealthToBag(AttackEntityEvent attackevent,ItemStack stack){

Зато заработало так:
Код:
MinecraftForge.EVENT_BUS.register(new EventTest());
EventTest
Код:
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.event.entity.player.AttackEntityEvent;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class EventTest {

    @SubscribeEvent
    public void giveHealthToBag(AttackEntityEvent attackevent) {
        EntityPlayer player = attackevent.entityPlayer;

        for (ItemStack slot : player.inventory.mainInventory) {
            if (slot != null) {
                if (slot.getItem() == Items.diamond) {
                    NBTTagCompound nbt = slot.getTagCompound();
                    if (nbt == null) nbt = new NBTTagCompound();
                    if (!nbt.hasKey("HealthInBag")) nbt.setInteger("HealthInBag", 0);

                    if (nbt.hasKey("HealthInBag") && nbt.getInteger("HealthInBag") < 1000000) {
                        nbt.setInteger("HealthInBag", nbt.getInteger("HealthInBag") + 1);
                        slot.setTagCompound(nbt);
                        break;
                    }

                }
            }
        }

    }

    @SideOnly(Side.CLIENT) 
    @SubscribeEvent
    public void tipHealthToBag(ItemTooltipEvent e) {
        NBTTagCompound nbt = e.itemStack.getTagCompound();
        if (nbt != null && nbt.hasKey("HealthInBag"))
            e.toolTip.add("Health In Bag: " + nbt.getInteger("HealthInBag"));
    }

}
[merge_posts_bbcode]Добавлено: 23.03.2015 10:56:18[/merge_posts_bbcode]

Где "Items.diamond" должен быть твой "BaseMyMod.bagofhealth".
 
Статус
В этой теме нельзя размещать новые ответы.
Назад
Сверху