gpt4 book ai didi

java - 让苹果给你体验? | Minecraft Forge 模组 1.7.10

转载 作者:行者123 更新时间:2023-12-02 03:55:58 29 4
gpt4 key购买 nike

互联网上的人们大家好,我想知道是否有一种方法可以让定制食品为您提供XP。我正在制作一个模组,希望“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();
}
};




}

最佳答案

你无法在游戏中编辑当前的苹果元素,你必须创建自己的元素作为 Forge Mod 元素,这看起来就像 oyu 所做的那样。要使元素提供 XP,请使用以下命令:

player.addExperienceLevel(1);//player 是 EntityPlayer 或 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 应该是治疗量,0.5f 应该是饱和量(参见表 here )

关于java - 让苹果给你体验? | Minecraft Forge 模组 1.7.10,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35447473/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com