首页 > 其他分享 >2020-12-17-mc模组开发笔记

2020-12-17-mc模组开发笔记

时间:2023-09-17 19:24:22浏览次数:48  
标签:12 17 mc level version deobf jei minecraft event

idea乱码

在help里进VM参数设置

https://www.huaweicloud.com/articles/9096546b90dc8c52d52138d01875b8ed.html

->与Lambda 表达式

tileEntityType ->

https://www.runoob.com/java/java8-lambda-expressions.html

简单说就是return后面一坨给前面,后面一坨可以是函数表达式

方块注册逻辑分析

事件类型分析

image-20201220020426110

有很详细的描述

LivingDeathEvent is fired when an Entity dies. 
This event is fired whenever an Entity dies in EntityLivingBase.onDeath(DamageSource), EntityPlayer.onDeath(DamageSource), and EntityPlayerMP.onDeath(DamageSource).  
This event is fired via the ForgeHooks.onLivingDeath(EntityLivingBase, DamageSource).

source contains the DamageSource that caused the entity to die.

This event is Cancelable. 
If this event is canceled, the Entity does not die.

This event does not have a result. net.minecraftforge.eventbus.api.Event.HasResult

This event is fired on the MinecraftForge.EVENT_BUS.

发送对话给玩家

import net.minecraft.entity.Entity;

Entity entity=event.getEntity();
String message="Hello world";
StringTextComponent text=new StringTextComponent(message);
entity.sendMessage(text,entity.getUniqueID());
import net.minecraft.entity.player.PlayerEntity;
PlayerEntity playerEntity= (PlayerEntity) entity;
playerEntity.sendMessage(new StringTextComponent("菜鸟<"+playerEntity.getName().getString()+">上线了~"),playerEntity.getUniqueID());
            
player.sendMessage(ITextComponent.getTextComponentOrEmpty("Good!"),player.getUniqueID());//PlayerEntity下的getUniqueID
//使用ITextComponent.getTextComponentOrEmpty直接转换string

记得先确认该代码不在服务器端运行

if (!event.getWorld().isRemote)
    

同时在调试时修改player.sendMessage然后重载是可以生效的

forge事件注册

@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE)//关键关键
public class Join {
    
    
    @SubscribeEvent
    public static void onPlayerJoin(EntityJoinWorldEvent event)//EntityJoinWorldEvent 关键,和onPlayerJoin类名无关
    {
        
    }

注册一个新的方块属性

private static final IntegerProperty state=IntegerProperty.create("count",0,1);//必须是private static

@Override
    protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
        builder.add(state);
        super.fillStateContainer(builder);
}

然后在构造函数中可以加入这段来默认属性

this.setDefaultState(this.stateContainer.getBaseState().with(state,0));

多属性方块的贴图

注意点:

方块贴图没啥问题,对应物品的贴图的json文件直接起和setRegistryName一样的名字

判断是不是在服务器执行

worldIn.isRemote 返回true在客户端执行

false在服务端执行

有价值的包

net.minecraft.block.properties

实现或重写快捷键

Ctrl+O

重载和重写

https://www.runoob.com/java/java-override-overload.html

以下内容针对MC1.18.1 Forge版本跟随

由于函数库的大变动,所以在这里写写

S1EQwrm.png

level是世界维度或者服务器

Blockpos是坐标,一般是xyz构造

Block是方块(哪种),BlockState是世界里的方块(哪个)

可以通过level获取state和entity

导入外部jar库的方案在1.17后有所改动

关键:

configurations {
    library
    implementation.extendsFrom library
}
minecraft.runs.all {
    lazyToken('minecraft_classpath') {
        configurations.library.copyRecursive().resolve().collect { it.absolutePath }.join(File.pathSeparator)
    }
}

library files("libs/luaj-jse-3.0.2.jar")//在dependencies里

而不是implementation

全貌

// Fix non-mod dependencies not being loaded in dev
configurations {
    library
    implementation.extendsFrom library
}
minecraft.runs.all {
    lazyToken('minecraft_classpath') {
        configurations.library.copyRecursive().resolve().collect { it.absolutePath }.join(File.pathSeparator)
    }
}


dependencies {
    // Specify the version of Minecraft to use. If this is any group other than 'net.minecraft', it is assumed
    // that the dep is a ForgeGradle 'patcher' dependency, and its patches will be applied.
    // The userdev artifact is a special name and will get all sorts of transformations applied to it.
    minecraft 'net.minecraftforge:forge:1.18.1-39.0.64'
    library files("libs/luaj-jse-3.0.2.jar")
//    compileOnly fg.deobf("mezz.jei:jei-${jei_version}:api")
//    implementation fg.deobf("mezz.jei:jei-${jei_version}")
//
//
    compileOnly fg.deobf("mezz.jei:jei-${mc_version}:${jei_version}:api")
    // at runtime, use the full JEI jar
    runtimeOnly fg.deobf("mezz.jei:jei-${mc_version}:${jei_version}")
    implementation fg.deobf("curse.maven:the-one-probe-245211:3550084")

    // Real mod deobf dependency examples - these get remapped to your current mappings
    // compileOnly fg.deobf("mezz.jei:jei-${mc_version}:${jei_version}:api") // Adds JEI API as a compile dependency
    // runtimeOnly fg.deobf("mezz.jei:jei-${mc_version}:${jei_version}") // Adds the full JEI mod as a runtime dependency
    // implementation fg.deobf("com.tterrag.registrate:Registrate:MC${mc_version}-${registrate_version}") // Adds registrate as a dependency

    // Examples using mod jars from ./libs

    // For more info...
    // http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
    // http://www.gradle.org/docs/current/userguide/dependency_management.html
}

方块点击是重写use方法

public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult trace) {
        if (!level.isClientSide) {
            System.out.println("Hello From code1!");
            BlockState a=level.getBlockState(pos);
        }
    return InteractionResult.SUCCESS;
}

方块最基本的属性,blockstate属性

BlockState a=level.getBlockState(pos);

通过pos(xyz)坐标配合方法得出BlockState对象,而不是直接构造函数

世界是level,可以通过玩家获取,或者use函数自带

Blockentity方块实体属性

也可以通过level得到

BlockEntity getBlockEntity

找一个方法

首先定位到它的类型,比如定位到Blockentity,然后想要查看它的得到方法

image-20220212010404876

中键,然后右上角选择在查找框打开

image-20220212010538715

按照返回值类型查找

image-20220212010650533

按照逻辑找到得到方法

image-20220212010811736

如果找到了接口要找实现,不应该对方法中键,应该在右边找到图标搜索实现

image-20220212010911383

获取player方案

1.UUID获取

2.通过玩家主动交互获取

获取level方案

1.通过player获取

标签:12,17,mc,level,version,deobf,jei,minecraft,event
From: https://www.cnblogs.com/xutongxin/p/17709531.html

相关文章

  • 2020-12-10-xtx第14周开发日志
    layout:posttitle:xtx第14周开发日志categories:日志tags:-日志-2020日志BGImage:'https://cdn.jsdelivr.net/gh/xutongxin1/xutongxin1.github.io@bebc52fb1b67a08f8db0026051b9716a88a37900/asset/%E6%97%A5%E5%BF%97/75065066_p0.jpg'jekyll-theme-Wu......
  • 2020-12-1-xtx第13周开发日记
    layout:posttitle:xtx第13周开发日志categories:日志tags:-日志-2020日志BGImage:'https://cdn.jsdelivr.net/gh/xutongxin1/xutongxin1.github.io@d65706f589a6ace903309ed982a3058a2b3251e3/asset/%E6%97%A5%E5%BF%97/20201211144323.png'jekyll-theme......
  • 2020-12-1-myy13周日志
    layout:posttitle:myy通讯录日志categories:日志tags:-日志-2020日志jekyll-theme-WuK:background_music:'<iframeframeborder="no"border="0"marginwidth="0"marginheight="0"width=100%height=86sr......
  • 2020-11-27-myy12周日志
    layout:posttitle:myy通讯录日志categories:日志tags:-日志-2020日志jekyll-theme-WuK:background_music:'<iframeframeborder="no"border="0"marginwidth="0"marginheight="0"width=100%height=86sr......
  • 2020-11-23-第12周开发日记
    layout:posttitle:xtx第12周开发日志categories:日志tags:-日志-2020日志BGImage:'https://cdn.jsdelivr.net/gh/xutongxin1/xutongxin1.github.io@a09d6cce1e133e1819736340f4016f10a0226969/asset/background/75006825_p0.jpg'jekyll-theme-WuK:m......
  • 开学测试修改(9.17)
    packagehomework;publicclassWarehouseInformation{privateStringitemno;privateStringitemname;privateStringsuppliername;privateStringwarehousingtime;privateStringshipmenttime;privateStringwarehousenumber;privateStr......
  • tinymce编辑器导入docx、doc格式Word文档完整版
    看此文章之前需要注意一点在前端使用导入Word文档并自动解析成html再插入到tinymce编辑器中,在这里我使用的是mammoth.js识别Word内容,并set到编辑器中,使用mammoth只可解析.docx格式的Word,目前的mammoth不支持.doc格式,后续升级也许会加上解析doc的功能。为什么解析不了.doc.docx......
  • 20211312徐元琦学习笔记2
    第9章I/O库函数——教材知识点归纳9.1~9.2系统调用和I/O库函数系统调用:操作系统中,进程以两种不同的方式运行:内核模式(Kmode)和用户模式(Umode)。Umode权限有限,特殊权限的操作需要在Kmode下进行。系统调用(SystemCall)机制允许进程进入Kmode,执行更高权限的操作。系统调用和I/O......
  • CSP 20123 入门组第一轮
    2023CCF非专业级别软件能力认证第一轮,(CSP-J1)入门级C++语言试题考生注意事项:●试题纸共有10页。答题纸共有2页,满分100分。请在答题纸上作答,写在试题纸上的一律无效。●不得使用任何电子设备(如计算器、手机、电子网费等)或查阅任何书籍资料。一、单项选择题(共15题,每......
  • sql 牛客网 175题
    https://www.nowcoder.com/practice/f022c9ec81044d4bb7e0711ab794531a?tpId=268&tags=&title=&difficulty=0&judgeStatus=0&rp=0&sourceUrl=%2Fexam%2Fintelligent%3FquestionJobId%3D10%26tagId%3D21003题本身的思路并不难,我的方法是采用union连接两个查询(selectd......