详细情况如下
https://www.mcbbs.net/forum.php?mod=viewthread&tid=1484155&page=1#pid29400264
"implements GeoEntity"是动画实体的部分对实体本身没有影响
https://www.mcbbs.net/forum.php?mod=viewthread&tid=1484155&page=1#pid29400264
"implements GeoEntity"是动画实体的部分对实体本身没有影响
https://boson.v2mcdev.com/entity/scratchentity.html
https://boson.v2mcdev.com/entity/passiveentityandai.html你看的是哪个教程?
可以看到这里并没有非常艰深的内容。首先我们从一个非常值得注意的地方说起。
@Override
public IPacket<?> createSpawnPacket() {
return NetworkHooks.getEntitySpawningPacket(this);
}
因为实体是在服务端创建以后再通知客户端创建,所以这里涉及到了发包操作,我们不能再这里复用Minecraft原版提供的方法,这里必须使用Forge提供的NetworkHooks.getEntitySpawningPacket(this);来在客户端创建实体。
https://boson.v2mcdev.com/entity/passiveentityandai.html
我们来看构造方法。
protected ObsidianAnimal(EntityType<? extends AnimalEntity> type, World worldIn) {
super(type, worldIn);
this.goalSelector.addGoal(0, new ObsidianGoal(this));
this.getAttributeManager().createInstanceIfAbsent(Attributes.MAX_HEALTH);
}
在这里我们调用 this.goalSelector.addGoal方法为我们的实体添加了一个AI或者说Goal(目的),而我们用this.getAttributeManager().createInstanceIfAbsent(Attributes.MAX_HEALTH);为我们的实体添加了一个属性,请注意Attributes.MAX_HEALTH这个属性是必须要添加的
接下来的我们来看看属性的注册。
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
public class AttributesSetEvent {
@SubscribeEvent
public static void setupAttributes(FMLCommonSetupEvent event) {
event.enqueueWork(() -> {
GlobalEntityTypeAttributes.put(EntityTypeRegistry.obsidianAnimal.get(), MobEntity.func_233666_p_().createMutableAttribute(Attributes.MAX_HEALTH, 10.0D).create());
});
}
}
可以看到,我们在FMLCommonSetupEvent这个事件中为我们的实体添加了属性,请注意这里的内容必须要放在event.enqueueWork中。
无敌三脚猫 发表于 2024-1-5 15:43
https://boson.v2mcdev.com/entity/scratchentity.html
https://boson.v2mcdev.com/entity/passiveentityan ...
抱歉哈,没看仔细。getAddEntityPacket是编译器直接生成的没注意。
GlobalEntityTypeAttributes.put方法已经被弃用,目前貌似就是event.put

this.getAttributeManager().createInstanceIfAbsent我没有找到应该是1.16.5改动了,我不太确定是那个是对应的方法目前找到这个 this.getAttributes().addTransientAttributeModifiers(Multimap<Attribute, AttributeModifier> p_233793_1_);但我不太清楚应该怎样填写这个