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

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

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

Entity.writeToNBT介绍

暂无

代码示例

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

@Override
public BaseEntity getState() {
  net.minecraft.entity.Entity entity = entityRef.get();
  if (entity != null) {
    String id = EntityList.getEntityString(entity);
    if (id != null) {
      NBTTagCompound tag = new NBTTagCompound();
      entity.writeToNBT(tag);
      return new BaseEntity(EntityTypes.get(id), NBTConverter.fromNative(tag));
    } else {
      return null;
    }
  } else {
    return null;
  }
}

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

@Override
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
  //moving passengers to the same position as vehicle on save otherwise they can end up in a different chunk and MC will kill them on load
  getPassengers().forEach(e -> e.setPosition(posX, posY, posZ));
  return super.writeToNBT(compound);
}

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

private NBTTagCompound getCustomSpawnTag(Entity entity) {
  NBTTagCompound entityTag = new NBTTagCompound();
  entity.writeToNBT(entityTag);
  return EntitySpawnNBTRegistry.getEntitySpawnNBT(entity, entityTag);
}

代码示例来源:origin: Lunatrius/Schematica

public static NBTTagCompound writeEntitiesToCompound(final List<Entity> entities, final NBTTagCompound compound) {
  final NBTTagList tagList = new NBTTagList();
  for (final Entity entity : entities) {
    final NBTTagCompound entityCompound = new NBTTagCompound();
    entity.writeToNBT(entityCompound);
    tagList.appendTag(entityCompound);
  }
  compound.setTag(Names.NBT.ENTITIES, tagList);
  return compound;
}

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

@Override
public NBTTagCompound writeToNBT(NBTTagCompound tag) {
  tag = super.writeToNBT(tag);
  NBTTagCompound broomItemTag = new NBTTagCompound();
  getBroomStack().writeToNBT(broomItemTag);
  tag.setTag("broomItem", broomItemTag);
  return tag;
}

代码示例来源:origin: vadis365/TheErebus

private NBTTagCompound trapEntity(Entity entity) {
    NBTTagCompound entityNBT = new NBTTagCompound();
    entity.writeToNBT(entityNBT);
    String mobName = EntityList.getKey(entity).toString();
    entityNBT.setString("id", mobName);

    return entityNBT;
  }
}

代码示例来源:origin: DimensionalDevelopment/VanillaFix

@Inject(method = "addEntityCrashInfo", at = @At("TAIL"))
  private void onAddEntityCrashInfo(CrashReportCategory category, CallbackInfo ci) {
    if (!noNBT) {
      noNBT = true;
      category.addDetail("Entity NBT", () -> ((Entity) (Object) this).writeToNBT(new NBTTagCompound()).toString());
      noNBT = false;
    }
  }
}

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

public TemplateRuleEntity(World world, Entity entity, int turns, int x, int y, int z) {
  super(world, entity, turns, x, y, z);
  registryName = EntityList.getKey(entity);
  rotation = (entity.rotationYaw + 90.f * turns) % 360.f;
  float x1 = (float) (entity.posX % 1.d);
  float z1 = (float) (entity.posZ % 1.d);
  if (x1 < 0) {
    x1++;
  }
  if (z1 < 0) {
    z1++;
  }
  xOffset = BlockTools.rotateFloatX(x1, z1, turns);
  zOffset = BlockTools.rotateFloatZ(x1, z1, turns);
  yOffset = (float) (entity.posY % 1d);
  tag = entity.writeToNBT(new NBTTagCompound());
  tag.removeTag("UUIDMost");
  tag.removeTag("UUIDLeast");
}

代码示例来源:origin: TehNut/HWYLA

@Override
public NBTTagCompound getNBTData() {
  if ((this.tileEntity != null) && this.isTagCorrectTileEntity(this.remoteNbt))
    return remoteNbt;
  if ((this.entity != null) && this.isTagCorrectEntity(this.remoteNbt))
    return remoteNbt;
  if (this.tileEntity != null) {
    NBTTagCompound tag = new NBTTagCompound();
    try {
      this.tileEntity.writeToNBT(tag);
    } catch (Exception e) {
    }
    return tag;
  }
  if (this.entity != null) {
    NBTTagCompound tag = new NBTTagCompound();
    this.entity.writeToNBT(tag);
    return tag;
  }
  return new NBTTagCompound();
}

代码示例来源:origin: TehNut/HWYLA

accessor.getEntity().writeToNBT(tag);
  accessor.remoteNbt = tag;
} catch (Exception e) {

代码示例来源:origin: vadis365/TheErebus

entity.writeToNBT(nbt);
nbt.setString("id", EntityList.getKey(entity).toString());
tile.rotation = (byte) rand.nextInt(4);

代码示例来源:origin: vadis365/TheErebus

protected void setAmberBlock(World world, BlockPos pos, Random rand) {
  if (rand.nextFloat() > BUGGED_AMBER_CHANCE)
    world.setBlockState(pos, ModBlocks.AMBER.getDefaultState());
  else {
    world.setBlockState(pos, ModBlocks.PRESERVED_BLOCK.getDefaultState(), 3);
    TileEntityPreservedBlock tile = Utils.getTileEntity(world, pos, TileEntityPreservedBlock.class);
    if (tile != null)
      try {
        Entity entity;
        if (rand.nextFloat() > WAND_CHANCE) {
          Class<? extends EntityLiving> cls = ModEntities.getRandomEntityClass();
          entity = cls.getConstructor(new Class[] { World.class }).newInstance(world);
        } else {
          EntityItem item = new EntityItem(world);
          item.setItem(new ItemStack(ModItems.WAND_OF_PRESERVATION));
          entity = item;
        }
        entity.setPosition(pos.getX(), pos.getY(), pos.getZ());
        world.spawnEntity(entity);
        NBTTagCompound nbt = new NBTTagCompound();
        entity.writeToNBT(nbt);
        nbt.setString("id", EntityList.getKey(entity).toString());
        tile.rotation = (byte) rand.nextInt(4);
        tile.setEntityNBT(nbt);
        entity.setDead();
      } catch (Exception e) {
        e.printStackTrace();
      }
  }
}

代码示例来源: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: TeamLapen/Vampirism

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
  EntityPlayer player = getCommandSenderAsPlayer(sender);
  List<Entity> l = player.getEntityWorld().getEntitiesWithinAABBExcludingEntity(player, player.getEntityBoundingBox().grow(3, 2, 3));
  for (Entity o : l) {
    NBTTagCompound nbt = new NBTTagCompound();
    o.writeToNBT(nbt);
    VampirismMod.log.i("InfoEntity", "Data %s", nbt);
  }
  sender.sendMessage(new TextComponentString("Printed info to log"));
}

代码示例来源:origin: Darkhax-Minecraft/Bookshelf

((Entity) value).writeToNBT(newTag);
dataTag.setTag(tagName, newTag);

代码示例来源:origin: FTBTeam/FTB-Utilities

@Override
  public NBTTagCompound editNBT(EntityPlayerMP player, NBTTagCompound info, String[] args) throws CommandException
  {
    checkArgs(player, args, 1);
    int id = parseInt(args[0]);
    Entity entity = player.world.getEntityByID(id);
    NBTTagCompound nbt = new NBTTagCompound();
    if (entity != null)
    {
      info.setString("type", "entity");
      info.setInteger("id", id);
      entity.writeToNBT(nbt);
      NBTTagList list = new NBTTagList();
      addInfo(list, new TextComponentString("Class"), new TextComponentString(entity.getClass().getName()));
      ResourceLocation key = EntityList.getKey(entity.getClass());
      addInfo(list, new TextComponentString("ID"), new TextComponentString(key == null ? "null" : key.toString()));
      addInfo(list, new TextComponentString("Mod"), new TextComponentString(key == null ? "null" : Loader.instance().getIndexedModList().get(key.getNamespace()).getName()));
      info.setTag("text", list);
      info.setString("title", ITextComponent.Serializer.componentToJson(entity.getDisplayName()));
    }
    return nbt;
  }
}

代码示例来源:origin: TehNut/HWYLA

@Override
  public IMessage onMessage(final MessageRequestEntity message, final MessageContext ctx) {
    final MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
    server.addScheduledTask(() -> {
      World world = DimensionManager.getWorld(message.dim);
      Entity entity = world.getEntityByID(message.entityId);
      EntityPlayerMP player = ctx.getServerHandler().player;
      if (entity == null)
        return;
      NBTTagCompound tag = new NBTTagCompound();
      if (ModuleRegistrar.instance().hasNBTEntityProviders(entity)) {
        for (List<IWailaEntityProvider> providersList : ModuleRegistrar.instance().getNBTEntityProviders(entity).values())
          for (IWailaEntityProvider provider : providersList)
            tag = provider.getNBTData(player, entity, tag, world);
      } else {
        entity.writeToNBT(tag);
        tag = NBTUtil.createTag(tag, message.keys);
      }
      tag.setInteger("WailaEntityID", entity.getEntityId());
      Waila.NETWORK_WRAPPER.sendTo(new MessageReceiveData(tag), player);
    });
    return null;
  }
}

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

@Override
 protected void processImpact(RayTraceResult mop) {
  if (mop.entityHit != null
    && mop.entityHit instanceof EntityLivingBase
    && (mop.entityHit instanceof EntityPlayer) == false
    && isInBlacklist(mop.entityHit) == false) {
   ItemStack captured = new ItemStack(renderSnowball);
   NBTTagCompound entity = new NBTTagCompound();
   mop.entityHit.writeToNBT(entity);
   //id is the special magic tag thats used by EntityList to respawn it. see EntityList.createEntityFromNBT
   entity.setString(ItemProjectileMagicNet.NBT_ENTITYID, EntityList.getKey(mop.entityHit.getClass()).toString()); // was getEntityStringFromClass
   entity.setString("tooltip", mop.entityHit.getName());
   captured.setTagCompound(entity);
   mop.entityHit.setDead();
   UtilItemStack.dropItemStackInWorld(this.getEntityWorld(), this.getPosition(), captured);
   UtilSound.playSound((EntityLivingBase) mop.entityHit, SoundRegistry.monster_ball_capture);
  }
  else {
   UtilItemStack.dropItemStackInWorld(this.getEntityWorld(), this.getPosition(), renderSnowball);
  }
  this.setDead();
 }
}

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

ItemStack outStack = ProxyRegistry.newStack(slime_bucket);
NBTTagCompound cmp = new NBTTagCompound();
event.getTarget().writeToNBT(cmp);
ItemNBTHelper.setCompound(outStack, ItemSlimeBucket.TAG_ENTITY_DATA, cmp);

相关文章

Entity类方法