在平常的生存里,总是遇到各种各样的怪物,那么今天,我们就要用我们的手、键盘和鼠标统统消灭他们!

首先建一个类:

package fenge.fmltutor.item;import fenge.fmltutor.ExampleMod;
import fenge.fmltutor.creativetab.TabFMLTutor;
import fenge.fmltutor.entity.EntityDirtBallKing;
import fenge.fmltutor.event.EventHandler;
import fenge.fmltutor.potion.PotionRegistryHandler;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.world.World;public class ItemDirtSword extends ItemSword {public ItemDirtSword(){super(ItemRegistryHandler.DIRT_TOOL_MATERLAL_);this.setUnlocalizedName(ExampleMod.MODID + ".dirtSword");this.setCreativeTab(TabFMLTutor.TAB_FMLTUTOR);this.setRegistryName("dirt_sword");}//功能1,“芜湖起飞”@Overridepublic ActionResult<ItemStack> onItemRightClick(World p_77659_1_, EntityPlayer entityPlayer, EnumHand p_77659_3_) {effectPlayer(entityPlayer);if(entityPlayer.rotationPitch>30){EventHandler.lP4(entityPlayer);}else {EventHandler.lP2(entityPlayer);}ItemStack itemstack = entityPlayer.getHeldItem(p_77659_3_);return new ActionResult<>(EnumActionResult.SUCCESS, itemstack);}private void effectPlayer(EntityPlayer player){if(player.getActivePotionEffect(MobEffects.REGENERATION)==null || player.getActivePotionEffect(MobEffects.REGENERATION).getDuration()<=1){player.addPotionEffect(new PotionEffect(MobEffects.REGENERATION, 2, 5,false,true));}}//功能2,彻底清除被击中的怪物@Overridepublic boolean onLeftClickEntity(ItemStack p_onLeftClickEntity_1_, EntityPlayer p_onLeftClickEntity_2_, Entity p_onLeftClickEntity_3_) {if(p_onLeftClickEntity_3_.getName().equals("loli")){p_onLeftClickEntity_3_.isDead=true;}if(!(p_onLeftClickEntity_3_ instanceof EntityPlayer)){p_onLeftClickEntity_3_.setDead();p_onLeftClickEntity_3_=null;}return super.onLeftClickEntity(p_onLeftClickEntity_1_, p_onLeftClickEntity_2_, p_onLeftClickEntity_3_);}
}

我们可以发现,有很多方法和变量都不存在,不要慌,现在就加入

在EventHandler中加入:

    public static void lP(Entity target){target.world.createExplosion(target,target.posX,target.posY,target.posZ,10L,true);}public static void lP3(Entity target){target.world.createExplosion(null,target.posX,target.posY+0.5,target.posZ,10L,false);}public static void lP4(Entity target){target.world.createExplosion(null,target.posX,target.posY+4,target.posZ,10L,false);}public static void lP2(Entity target){target.world.createExplosion(null,target.posX,target.posY,target.posZ,10L,false);}

再加入范围秒杀(在EventHandler里):

 //秒杀protected static void dead(EntityLiving entityLiving){//entityLiving.attackEntityFrom(new DamageSource("fenge"),entityLiving.getHealth());entityLiving.setHealth(0);entityLiving.world.removeEntity(entityLiving);}   public static void ms(List<Entity> entity,Entity entity_){//秒杀客户端生物for (int i = 0;i<entity.size();i++){Entity j=entity.get(i);//遍历主世界所有的生物if (j.posX>entity_.posX-100 &&j.posX<entity_.posX+100){if (j.posZ>entity_.posZ-100 &&j.posZ<entity_.posZ+100){//如果生物在以玩家为中心100格以内if (entity_ instanceof EntityPlayer) {//如果使用技能者是玩家ItemStack currentItem = ((EntityPlayer) entity_).inventory.getCurrentItem();if (!(currentItem.getItem() instanceof ItemDirtSword)) {//如果没手持此剑dead((EntityLiving) j);//让肖恩给你看病(秒杀)if(j.world.isRemote)ss((EntityLivingBase) j, (EntityLivingBase) entity_);}}if (j instanceof EntityPlayer) {//如果生物是你的好基友(玩家)ItemStack currentItem = ((EntityPlayer) entity_).inventory.getCurrentItem();if (!(currentItem.getItem() instanceof ItemDirtSword)) {//如果没手持此剑dead((EntityLiving) j);if(j.world.isRemote)ss((EntityLivingBase) j, (EntityLivingBase) entity_);//肖恩:我觉的他已经死了(秒杀)MinecraftServer jServer =j.getServer();Entity jj=jServer.getEntityFromUuid(j.getUniqueID());//4行没用的代码if(!jj.world.isRemote){//jj.setDead();}}}if(!(j instanceof EntityPlayer)){if(j instanceof EntityLiving){//如果不是玩家dead((EntityLiving) j);//肖恩:拿来把你!(秒杀)if(j.world.isRemote)ss((EntityLivingBase) j, (EntityLivingBase) entity_);}}}}}}//秒杀服务端生物public static void ss(EntityLivingBase j,EntityLivingBase entity_){if (Minecraft.getMinecraft().getIntegratedServer() != null) {ms(Minecraft.getMinecraft().getIntegratedServer().getWorld(entity_.world.provider.getDimension()).getLoadedEntityList(), entity_);//将服务端秒杀一遍String message = "BEY BEY,"+j.getName()+"!";TextComponentString text = new TextComponentString(message);//来自玩家的嘲讽entity_.sendMessage(text);}}//当左键空气时@SubscribeEventpublic static void onLeftClickEmpty(PlayerInteractEvent.LeftClickEmpty event){Entity entity_=event.getEntity();List<Entity> entity=entity_.world.getLoadedEntityList();ItemStack currentItem = ((EntityPlayer) entity_).inventory.getCurrentItem();if (DIRT_SWORD.equals(currentItem.getItem())) {ms(entity,entity_);}}

再在ItemRegistryHandler添加此剑的属性:

//这几个参数依次代表:材料(这个是枚举类的名称,全部大写)、挖掘等级(钻石镐是3)、耐久、挖特定方块的速度(倍数)、附魔能力
public static final Item.ToolMaterial DIRT_TOOL_MATERLAL_ = EnumHelper.addToolMaterial("DIRT",1000000000,100000000,100000000F,2147483647,5);

添加此剑(在ItemRegistryHandler里):

public static final ItemDirtSword DIRT_SWORD = new ItemDirtSword();

注册(在ItemRegistryHandler里):

@SubscribeEvent
public static void onRegistry(Register<Item> event)
{
IForgeRegistry<Item> registry= event.getRegistry();
registry.register(DIRT_SWORD);
//此处省略亿行代码(注册的有别的东西,这个方法可以注册此模组的所有物品)
}

注册模型(在ItemRegistryHandler里):

@SideOnly(Side.CLIENT)
private static void registerModel(Item item)
{ModelResourceLocation modelResourceLocation = new ModelResourceLocation(item.getRegistryName(), "inventory");ModelLoader.setCustomModelResourceLocation(item, 0, modelResourceLocation);
}@SubscribeEvent
@SideOnly(Side.CLIENT)
public static void onModelRegistry(ModelRegistryEvent event)
{
registerModel(DIRT_SWORD);
//此处省略亿行代码(注册的有别的东西,这个方法可以注册此模组的所有物品的模型)
}

添加模型(在src\main\resources\assets\fmltutor\blockstates\)

dirt_sword.json:

{"forge_marker": 1,"defaults": {"model": "minecraft:builtin/generated","textures": { "layer0": "fmltutor:items/dirt_sword" }},"variants": {"inventory": [{ "transform": "forge:default-tool" }]}
}

添加图片(src\main\resources\assets\fmltutor\textures\items\dirt_sword.png):

16*16或32*32的图片(我画的不怎么帅)

接下来在语言文件中添加物品名:
src\main\resources\assets\fmltutor\lang\zh_cn.lang:

item.fmltutor.dirtSword.name=俺滴剑

src\main\resources\assets\fmltutor\lang\en_us.lang:

item.fmltutor.dirtSword.name=My sword

来康康我们的剑扒:

真不戳,有范围秒杀+飞行+彻底清除的功能

我的世界mod开发(5)做一把无敌的剑相关推荐

  1. 我的世界mod开发(6)无敌的护甲

    现在,我们有了一把无敌的剑,但仅靠这些显然是不够的,我们还需要一套无敌的盔甲,具体要实现:无视伤害,全套时可以飞行 直接上代码 ItemDirtArmor.java: package fenge.fm ...

  2. 【MC 网易-我的世界-mod开发基础笔记】 --- 创建第一个空白Mod

    目录 创建Mod文件夹 构建Mod的基本目录结构 构建行为包基本结构 构建脚本文件夹基本结构 构建 mod 启动入口脚本 构建资源包基本结构 构建国际化文件基本结构 自定义物品配置中文名称 自定义方块 ...

  3. 【MC 网易-我的世界-mod开发基础笔记】 --- 运行测试第一个空白Mod

    这里写目录标题 前提 创建 空白世界,并在此世界中添加第一个空白的mod 前提 在[MC 网易-我的世界-mod开发基础笔记] - 创建第一个空白Mod 创建完成之后,进行测试. 创建 空白世界,并在 ...

  4. [Minecraft][Mod开发]如何做一个告示牌点赞mod

    本文选用的mc版本是1.16.5,但理论上可用于1.14+.若有人尝试成功,欢迎评论区留言. 需要实现的内容: 1:告示牌写上特定文本后使其作为点赞告示牌 2:点赞告示牌每次点赞后点赞数增加 3:点赞 ...

  5. 【MC 网易-我的世界-mod开发基础笔记】 --- 前期准备

    文章目录 说明 前提: 准备工作 建议: 说明 通过网易官方文档的内容已经官方提供的视频相结合,总结的mod开发笔记. 开发必须要掌握基础的python编程基础,且此笔记中,官方的mc开发工具仅仅只是 ...

  6. 我的世界mod开发(3番外)自定义方块/物品模型

    Blockbench下载 先做一个模型(图片与模型名字要相同): 按Ctrl+S把模型放置在 src\main\resources\assets\fmltutor\models\block (src\ ...

  7. 【MineCraft】-- 使用Java开发我的世界Mod

    使用idea 2019版本; 确保idea可以正常使用后↓ 一.下载框架 https://github.com/IdeallandEarthDept/IdeallandFramework 下载后解压打 ...

  8. 游戏世界里面的武器道具辣么帅,你不想做一把属于自己的战斗武器吗?次世代3D武器制作流程

    游戏世界里面的武器道具辣么帅,你不想做一把属于自己的战斗武器吗?次世代3D武器制作流程 游戏世界里面的武器道具辣么帅,你不想做一把属于自己的战斗武器吗?次世代3D武器制作流程

  9. 我的世界php开发教程视频,我的世界建筑教程 教你做一个新手小屋

    我的世界新手小屋怎么做,新手小屋复杂吗?新手小屋是玩家们在游戏中的第一个家,下面小编就给大家讲讲如何搭建一个新手小屋. 01. 我们首先需要这些主要建筑材料:原木.原木木板.石台阶.莹石.铁栅栏.原石 ...

最新文章

  1. mysql主从同步 sql_mysql主从同步报错;Slave_SQL_Running: No
  2. VTK:平面源用法实战
  3. Codeforce 1042 D. Petya and Array(树状数组、前缀和)
  4. 敏捷武士:看敏捷高手交付卓越软件pdf
  5. java数据类型的站位_Java 数据类型在实际开发中应用
  6. IntelliJ IDEA 注释模版 输入/**后 不显示配置好的模板
  7. SqlSessionFactoryBean
  8. WIN10开启Hyper-V虚拟化功能
  9. 正弦交流电有效值系数sqrt(2)的推导
  10. 大型机、小型机、x86架构以及ARM架构服务器的区别大型机、小型机、x86架构以及ARM架构服务器的区别
  11. 易车网李斌:一个放牛娃的梦想(转载)
  12. win10 提升来宾账户为管理员账户
  13. 游戏开发全免费下载资源网站
  14. 小米笔记本开机提示:no bootable device -- insert boot disk and press any key
  15. Web指纹识别器系列1:开源项目搜集和反思
  16. Apache Spark RDD 论文(中文翻译)
  17. 黑桃k游戏java实战_#Java小案例 扑克牌小游戏
  18. 关联规则—Apriori、FP-growth/FP-Tree
  19. 介词php,介词短语作状语
  20. 2020年春节复工后的十大高薪职业,IT技术岗榜上有名!

热门文章

  1. seo排名工具:网站快速排名需要哪些seo推广工具?
  2. 代码优雅之路-如何优雅的去除冗杂的if-else语句
  3. 商品交易系统之---产品介绍
  4. 睡到自然醒的7个关键
  5. 平板电脑是中国制造转向中国创造的机遇
  6. 三星可能已后悔离开中国制造,它在越南的工厂无奈大幅减产
  7. 美式英语和英式英语不同发音总结
  8. ubuntu 20.04 安装 免费 Beyond Compare对比工具
  9. 12306采用Pivotal GemFire分布式解决方案 解决尖峰高流量并发
  10. data:image/png;base64,iVBORw0KGg... 表示的是一张图片