让苹果给你体验? | Minecraft Forge Modding 1.7.10

时间:2016-02-17 03:41:17

标签: java minecraft minecraft-forge

您好,互联网的人,我想知道是否有办法让定制食品给你XP。我正在制作一个mod,并希望“SimonApple”给我XP。如果有办法,请告诉我。

package com.notsimon.blocksplus;

import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.registry.GameRegistry;
import net.minecraft.block.Block;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemStack;

@Mod(modid = "ep", name = "Experience Plus", version = "1.0")
public class ExperiencePlus {

    public static Item SimonApple;
    public static Item MagentaDust;
    public static Block MagentaOre;
    public static Block MagentaBlock;

    @EventHandler
    public void preInit(FMLPreInitializationEvent event) {
        //Item/Block init and registering
        //Config handling
        //X * 0.5 = 20 Hunger
        SimonApple = new ItemFood(10, 0.5F, false).setUnlocalizedName("SimonApple").setTextureName("bp:SimonApple").setCreativeTab(tabBlocksPlus);
        MagentaOre = new BlockTable(Material.iron).setBlockName("MagentaOre").setBlockTextureName("bp:MagentaOre").setCreativeTab(tabBlocksPlus);
        MagentaDust = new ItemTable().setUnlocalizedName("MagentaDust").setTextureName("bp:MagentaDust").setCreativeTab(tabBlocksPlus);
        MagentaBlock = new MagentaBlock(Material.iron).setBlockName("MagentaBlock").setBlockTextureName("bp:MagentaBlock").setCreativeTab(tabBlocksPlus);
        //item.itemTable and substring(5) removes "item."
        GameRegistry.registerItem(SimonApple, SimonApple.getUnlocalizedName().substring(5));
        GameRegistry.registerBlock(MagentaOre, MagentaOre.getUnlocalizedName().substring(5));
        GameRegistry.registerItem(MagentaDust, MagentaDust.getUnlocalizedName().substring(5));
        GameRegistry.registerBlock(MagentaBlock, MagentaBlock.getUnlocalizedName().substring(5));
        GameRegistry.registerWorldGenerator(new OreGeneration(), 0);
    }

    @EventHandler
    public void init(FMLInitializationEvent event) {
        //Proxy, TileEntity, entity, GUI and Packet Registering
        GameRegistry.addRecipe(new ItemStack(SimonApple, 2), new Object[]{"MMM","MBM","MMM", 'M', ExperiencePlus.MagentaDust, 'B', ExperiencePlus.MagentaBlock});
        GameRegistry.addRecipe(new ItemStack(MagentaBlock), new Object[] {"MMM", "MMM", "MMM",'M', ExperiencePlus.MagentaDust});
    }

    @EventHandler
    public void postInit(FMLPostInitializationEvent event) {

    }

    public static CreativeTabs tabBlocksPlus = new CreativeTabs("tabBlocksPlus"){
        @Override
        public Item getTabIconItem() {
            return new ItemStack(MagentaOre).getItem();
        }
    };




}

2 个答案:

答案 0 :(得分:1)

您无法编辑游戏中的当前苹果项目,您必须创建自己的项目作为伪造模式项目,这似乎是oyu所做的。要使一个项目给XP,你可以使用:

player.addExperienceLevel(1); //player is an EntityPlayer or an EntityPlayerMP

SimonApple项目类

这就是SimonApple的项目类(无导入):

public class SimonApple extends ItemFood {
    private static final int LevelsToAdd = 10; //just an example number; play around with it

    public SimonApple(String unlocalizedName, int healAmount, float saturationModifier, boolean wolvesFavorite, CreativeTab creativeTab) {
        super(healAmount, saturationModifier, wolvesFavorite);
        this.setUnlocalizedName(unlocalizedName);
        this.setTextureName(Main.MODID + ":" + unlocalizedName);
        this.setCreativeTab(creativeTab);
    }

    @Override
    protected void onFoodEaten(ItemStack stack, World world, EntityPlayer player) {
        super.onFoodEaten(stack, world, player);
        player.addExperienceLevel(LevelsToAdd);
    }
}

更改ExperiencePlus类中的变量

你需要改变这个:

public static Item SimonApple;

对于某些内容:

public static Item simonApple;

你需要改变这个:

SimonApple = new ItemFood(10, 0.5F, false).setUnlocalizedName("SimonApple").setTextureName("bp:SimonApple").setCreativeTab(tabBlocksPlus);

就这样:

simonApple = new SimonApple("SimonApple", 10, .5f, false, tabBlocksPlus);

注意: 10应该是治疗量,而.5f应该是饱和量(见表here

答案 1 :(得分:1)

创建Abob78建议的新项目,或者创建一个订阅要在Finish状态下触发的PlayerUseItem事件的eventHandler。

要限制触发它的项目,您必须使用itemstack NBT data来存储标记,以便从常规苹果中识别“simon apples”。这可以像布尔标志一样简单,例如“isSimonApple”

从该事件中,您应该能够提取可以投射到EntityLivingplayer reference引用。 然后要么增加触发玩家的XP,要么在他们的位置产生XP球。