梦星桐
本帖最后由 梦星桐 于 2021-12-20 09:58 编辑

我创建了个EntityCustomWolf类继承了EntityWolf然后一通改
在addEntity的时候发现只有落地的粒子特效,生物没出来
我发现我没注册
注册完以后的代码如下
EntityCustomWolf类
  1. import com.google.common.collect.Sets;
  2. import net.minecraft.server.v1_12_R1.*;
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.Location;
  5. import org.bukkit.craftbukkit.v1_12_R1.CraftWorld;

  6. import java.lang.reflect.Field;

  7. public class EntityCustomWolf extends EntityWolf {
  8.     public static MinecraftKey minecraftKey;
  9.     static{
  10.         // 给我们的自定义实体做一个MinecraftKey
  11.         EntityCustomWolf.minecraftKey = new MinecraftKey("unrealpet_wolf"); // minecraft:my_zombie
  12.         // 实体注册
  13.         EntityTypes.d.add(EntityCustomWolf.minecraftKey); // 将此key添加至EntityTypes的列表里
  14.         EntityTypes.b.a(54, EntityCustomWolf.minecraftKey, EntityCustomWolf.class); // 对其注册
  15.     }
  16.     public EntityCustomWolf(World world) {
  17.         super(world);
  18.     }

  19.     public EntityCustomWolf(Location loc) {
  20.         this(((CraftWorld) loc.getWorld()).getHandle());
  21.         try {
  22.             Field dField = PathfinderGoalSelector.class.getDeclaredField("b");
  23.             dField.setAccessible(true);
  24.             dField.set(goalSelector, Sets.newLinkedHashSet());
  25.             dField.set(targetSelector, Sets.newLinkedHashSet());
  26.             this.goalSit = new PathfinderGoalSit(this);
  27.             this.goalSelector.a(1, new PathfinderGoalFloat(this));
  28.             this.goalSelector.a(2, this.goalSit);
  29.             this.goalSelector.a(4, new PathfinderGoalLeapAtTarget(this, 0.4F));
  30.             this.goalSelector.a(5, new PathfinderGoalMeleeAttack(this, 1.0D, true));
  31.             this.goalSelector.a(6, new PathfinderGoalFollowOwner(this, 1.0D, 10.0F, 2.0F));
  32.             this.targetSelector.a(1, new PathfinderGoalOwnerHurtByTarget(this));
  33.             this.targetSelector.a(2, new PathfinderGoalOwnerHurtTarget(this));
  34.         } catch (NoSuchFieldException | IllegalAccessException noSuchFieldException) {
  35.             noSuchFieldException.printStackTrace();
  36.         }

  37.     }
  38.     @Override
  39.     public void postTick() {
  40.         super.postTick();
  41.         Bukkit.getPlayer("DS_Tong").sendMessage(world.getWorld().getName() + ";" + locX + ";" + locY + ";" + locZ);
  42.     }
  43.     public static MinecraftKey getMinecraftKey() {
  44.         return minecraftKey;
  45.     }
  46. }
复制代码

生成实体代码
  1. EntityCustomWolf entity = new EntityCustomWolf(player.getLocation());
  2.         ((CraftWorld)player.getWorld()).getHandle().addEntity((entity), CreatureSpawnEvent.SpawnReason.CUSTOM);
复制代码

但是我生物实体有了,但是没有生物模型,这是为什么




第一页 上一页 下一页 最后一页