本帖最后由 梦星桐 于 2021-12-20 09:58 编辑
我创建了个EntityCustomWolf类继承了EntityWolf然后一通改
在addEntity的时候发现只有落地的粒子特效,生物没出来
我发现我没注册
注册完以后的代码如下
EntityCustomWolf类
复制代码
生成实体代码
复制代码
但是我生物实体有了,但是没有生物模型,这是为什么
我创建了个EntityCustomWolf类继承了EntityWolf然后一通改
在addEntity的时候发现只有落地的粒子特效,生物没出来
我发现我没注册
注册完以后的代码如下
EntityCustomWolf类
- import com.google.common.collect.Sets;
- import net.minecraft.server.v1_12_R1.*;
- import org.bukkit.Bukkit;
- import org.bukkit.Location;
- import org.bukkit.craftbukkit.v1_12_R1.CraftWorld;
- import java.lang.reflect.Field;
- public class EntityCustomWolf extends EntityWolf {
- public static MinecraftKey minecraftKey;
- static{
- // 给我们的自定义实体做一个MinecraftKey
- EntityCustomWolf.minecraftKey = new MinecraftKey("unrealpet_wolf"); // minecraft:my_zombie
- // 实体注册
- EntityTypes.d.add(EntityCustomWolf.minecraftKey); // 将此key添加至EntityTypes的列表里
- EntityTypes.b.a(54, EntityCustomWolf.minecraftKey, EntityCustomWolf.class); // 对其注册
- }
- public EntityCustomWolf(World world) {
- super(world);
- }
- public EntityCustomWolf(Location loc) {
- this(((CraftWorld) loc.getWorld()).getHandle());
- try {
- Field dField = PathfinderGoalSelector.class.getDeclaredField("b");
- dField.setAccessible(true);
- dField.set(goalSelector, Sets.newLinkedHashSet());
- dField.set(targetSelector, Sets.newLinkedHashSet());
- this.goalSit = new PathfinderGoalSit(this);
- this.goalSelector.a(1, new PathfinderGoalFloat(this));
- this.goalSelector.a(2, this.goalSit);
- this.goalSelector.a(4, new PathfinderGoalLeapAtTarget(this, 0.4F));
- this.goalSelector.a(5, new PathfinderGoalMeleeAttack(this, 1.0D, true));
- this.goalSelector.a(6, new PathfinderGoalFollowOwner(this, 1.0D, 10.0F, 2.0F));
- this.targetSelector.a(1, new PathfinderGoalOwnerHurtByTarget(this));
- this.targetSelector.a(2, new PathfinderGoalOwnerHurtTarget(this));
- } catch (NoSuchFieldException | IllegalAccessException noSuchFieldException) {
- noSuchFieldException.printStackTrace();
- }
- }
- @Override
- public void postTick() {
- super.postTick();
- Bukkit.getPlayer("DS_Tong").sendMessage(world.getWorld().getName() + ";" + locX + ";" + locY + ";" + locZ);
- }
- public static MinecraftKey getMinecraftKey() {
- return minecraftKey;
- }
- }
生成实体代码
- EntityCustomWolf entity = new EntityCustomWolf(player.getLocation());
- ((CraftWorld)player.getWorld()).getHandle().addEntity((entity), CreatureSpawnEvent.SpawnReason.CUSTOM);
但是我生物实体有了,但是没有生物模型,这是为什么
