net.minecraft.entity.Entity.readFromNBT()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(3.2k)|赞(0)|评价(0)|浏览(147)

本文整理了Java中net.minecraft.entity.Entity.readFromNBT()方法的一些代码示例,展示了Entity.readFromNBT()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Entity.readFromNBT()方法的具体详情如下:
包路径:net.minecraft.entity.Entity
类名称:Entity
方法名:readFromNBT

Entity.readFromNBT介绍

暂无

代码示例

代码示例来源:origin: EngineHub/WorldEdit

@Nullable
@Override
public Entity createEntity(Location location, BaseEntity entity) {
  World world = getWorld();
  net.minecraft.entity.Entity createdEntity = EntityList.createEntityByIDFromName(new ResourceLocation(entity.getType().getId()), world);
  if (createdEntity != null) {
    CompoundTag nativeTag = entity.getNbtData();
    if (nativeTag != null) {
      NBTTagCompound tag = NBTConverter.toNative(entity.getNbtData());
      for (String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) {
        tag.removeTag(name);
      }
      createdEntity.readFromNBT(tag);
    }
    createdEntity.setLocationAndAngles(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
    world.spawnEntity(createdEntity);
    return new ForgeEntity(createdEntity);
  } else {
    return null;
  }
}

代码示例来源:origin: P3pp3rF1y/AncientWarfare2

protected Optional<Entity> createEntity(World world, int turns, BlockPos pos, IStructureBuilder builder) {
  Entity e = EntityList.createEntityByIDFromName(registryName, world);
  if (e == null) {
    AncientWarfareStructure.LOG.warn("Could not create entity for name: " + registryName.toString() + " Entity skipped during structure creation.\n" + "Entity data: " + tag);
    return Optional.empty();
  }
  e.readFromNBT(getEntityNBT(pos, turns));
  updateEntityOnPlacement(turns, pos, e);
  return Optional.of(e);
}

代码示例来源:origin: CyclopsMC/EvilCraft

@Override
  public void readFromNBT(NBTTagCompound tagCompound) {
    super.readFromNBT(tagCompound);
    ItemStack broomStack = new ItemStack(tagCompound.getCompoundTag("broomItem"));
    if (broomStack != null) {
      setBroomStack(broomStack);
    }
  }
}

代码示例来源:origin: Vazkii/Patchouli

entity = constructor.newInstance(world);
if(useNbt != null)
  entity.readFromNBT(useNbt);

代码示例来源:origin: P3pp3rF1y/AncientWarfare2

private void setDataFromTag(Entity e) {
    if (customTag != null) {
      NBTTagCompound temp = new NBTTagCompound();
      if (e instanceof NpcFaction && customTag.hasKey(FACTION_NAME_TAG)) {
        ((NpcFaction) e).setFactionNameAndDefaults(customTag.getString(FACTION_NAME_TAG));
      }
      e.writeToNBT(temp);
      Set<String> keys = customTag.getKeySet();
      for (String key : keys) {
        temp.setTag(key, customTag.getTag(key));
      }
      e.readFromNBT(temp);
    }
  }
}

代码示例来源:origin: MatterOverdrive/MatterOverdrive-Legacy-Edition

entity.readFromNBT(nbtTagCompound);

代码示例来源:origin: PrinceOfAmber/Cyclic

@Override
protected void processImpact(RayTraceResult mop) {
 if (getCaptured() == null || getCaptured().hasTagCompound() == false) {
  //client desync maybe
  return;
 }
 Entity spawnEntity = EntityList.createEntityFromNBT(getCaptured().getTagCompound(), this.getEntityWorld());
 if (spawnEntity != null) {
  spawnEntity.readFromNBT(getCaptured().getTagCompound());
  spawnEntity.setLocationAndAngles(this.posX, this.posY + 1.1F, this.posZ, this.rotationYaw, 0.0F);
  this.getEntityWorld().spawnEntity(spawnEntity);
  if (spawnEntity instanceof EntityLivingBase) {
   UtilSound.playSound((EntityLivingBase) spawnEntity, SoundRegistry.monster_ball_release);
   UtilItemStack.dropItemStackInWorld(this.getEntityWorld(), this.getPosition(), new ItemStack(getCaptured().getItem()));
  }
 }
 this.setDead();
}

相关文章

Entity类方法