Неправильное наложение эффектов.

34
0
При использовании ItemFood на игрока накладываются не все эффекты которые я добавил а ItemFodd.java. Что делать?[Главный класс]
Код:
package net.test.mod;

Import...

@Mod(modid = TestMod.modid, version = TestMod.version)
public class TesMod {

public static final String modid = "TestMod";
public static final String version = "v1.0";

public static Item itemFood;

@EventHandler
public void PreInit(FMLPreInitializationEvent preEvent) {
itemFood = new ItemFood(10, 1.0F, true).setUnlocalizedName("Food");
GameRegistry.registerItem(itemFood, "Food");
}
}


[Класс ItemFood]
Код:
package net.test.mod.items;

Import...

public class ItemFood extends ItemFood {
    
    public ItemFood(int heal, float saturation, boolean wolfmeat) {
        super(heal, saturation, wolfmeat);

        this.setPotionEffect(4, 10, 1, 1F);
        this.setPotionEffect(2, 10, 2, 1F);
        this.setPotionEffect(6, 10, 1, 1F);
        this.setPotionEffect(8, 10, 1, 1F);
        this.setTextureName(TestMod.modid + ":textures/items/ItemFood.png");
        this.setCreativeTab(CreativeTabs.tabFood);
    
    }
}
В данном случае наложится эффект(8) "Мощный прыжок 2".
 
Для 1.7
Код:
    @Override
    public ItemStack onEaten(ItemStack p_77654_1_, World p_77654_2_, EntityPlayer player) {
        player.addPotionEffect(new PotionEffect(Potion.moveSpeed.id, 200));
        player.addPotionEffect(new PotionEffect(Potion.weakness.id, 200));
        player.addPotionEffect(new PotionEffect(Potion.hunger.id, 200));
        return super.onEaten(p_77654_1_, p_77654_2_, player);
    }
 
Asd73 написал(а):
Для 1.7
Код:
    @Override
    public ItemStack onEaten(ItemStack p_77654_1_, World p_77654_2_, EntityPlayer player) {
        player.addPotionEffect(new PotionEffect(Potion.moveSpeed.id, 200));
        player.addPotionEffect(new PotionEffect(Potion.weakness.id, 200));
        player.addPotionEffect(new PotionEffect(Potion.hunger.id, 200));
        return super.onEaten(p_77654_1_, p_77654_2_, player);
    }

[merge_posts_bbcode]Добавлено: 18.10.2014 12:03:15[/merge_posts_bbcode]

Asd73 написал(а):
А немного неправильно я написал, нужно так:
Код:
    @Override
    public ItemStack onFoodEaten(ItemStack p_77654_1_, World p_77654_2_, EntityPlayer player) {
        player.addPotionEffect(new PotionEffect(Potion.moveSpeed.id, 200));
        player.addPotionEffect(new PotionEffect(Potion.weakness.id, 200));
        player.addPotionEffect(new PotionEffect(Potion.hunger.id, 200));
    }
Ничего ничего...
 
Нет, не так. Немного напутал. Нужно выполнять только на серверной стороне.

Код:
    @Override
    public ItemStack onEaten(ItemStack p_77654_1_, World p_77654_2_, EntityPlayer player) {
        if (!p_77654_2_.isRemote) {
           player.addPotionEffect(new PotionEffect(Potion.moveSpeed.id, 200));
           player.addPotionEffect(new PotionEffect(Potion.weakness.id, 200));
           player.addPotionEffect(new PotionEffect(Potion.hunger.id, 200));
        }
        return super.onEaten(p_77654_1_, p_77654_2_, player);
    }
[merge_posts_bbcode]Добавлено: 18.10.2014 12:08:39[/merge_posts_bbcode]

Хотя можно и в onFoodEaten засунуть - без разницы.
 
Назад
Сверху