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

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

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

Entity.getCapability介绍

暂无

代码示例

代码示例来源:origin: SlimeKnights/TinkersConstruct

public static Optional<ITinkerProjectile> getTinkerProjectile(Entity entity) {
 ITinkerProjectile capability = null;
 if(entity != null && entity.hasCapability(CapabilityTinkerProjectile.PROJECTILE_CAPABILITY, null)) {
  capability = entity.getCapability(CapabilityTinkerProjectile.PROJECTILE_CAPABILITY, null);
 }
 return Optional.ofNullable(capability);
}

代码示例来源:origin: SlimeKnights/TinkersConstruct

@Nonnull
public static ItemStack findAmmoFromInventory(List<Item> ammoItems, Entity entity) {
 if(ammoItems == null || entity == null || !entity.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)) {
  return ItemStack.EMPTY;
 }
 // we specifically check the equipment inventory first because it contains the offhand
 IItemHandler itemHandler = entity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.NORTH);
 ItemStack ammo = ItemStack.EMPTY;
 if(itemHandler != null) {
  ammo = validAmmoInRange(itemHandler, ammoItems, 0, itemHandler.getSlots());
 }
 // and then the remaining inventory
 if(ammo.isEmpty()) {
  itemHandler = entity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.UP);
  if(itemHandler != null) {
   int hotbarSize = 0;
   // find an itemstack that matches our input. Hotbar first
   if(entity instanceof EntityPlayer) {
    hotbarSize = Math.min(InventoryPlayer.getHotbarSize(), itemHandler.getSlots());
    ammo = validAmmoInRange(itemHandler, ammoItems, 0, hotbarSize);
   }
   // then remaining inventory
   if(ammo.isEmpty()) {
    ammo = validAmmoInRange(itemHandler, ammoItems, hotbarSize, itemHandler.getSlots());
   }
  }
 }
 return ammo;
}

代码示例来源:origin: SlimeKnights/TinkersConstruct

IItemHandler itemHandler = entity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);

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

public static OverdriveExtendedProperties GetExtendedCapability(Entity entity) {
  if (entity == null)
    return null;
  return entity.getCapability(OverdriveExtendedProperties.CAPIBILITY, EnumFacing.DOWN);
}

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

@Nullable
@Override
public <T> T getCapability(Capability<T> capability, @Nullable EnumFacing facing) {
  if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
    return (T) inventory.storageInventory;
  }
  return super.getCapability(capability, facing);
}

代码示例来源:origin: sinkillerj/ProjectE

@Override
public void onUpdate(ItemStack stack, World world, Entity entity, int slot, boolean isHeld) 
{
  if (world.isRemote || !(entity instanceof EntityPlayer))
  {
    return;
  }
  
  condense(stack, entity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.UP));
}

代码示例来源:origin: PenguinSquad/Harvest-Festival

@SuppressWarnings("ConstantConditions, unchecked")
  @Nullable
  public static <A extends AnimalStats> A getStats(Entity target) {
    if (target != null && target.hasCapability(ANIMAL_STATS_CAPABILITY, EnumFacing.DOWN)) {
      return (A) target.getCapability(ANIMAL_STATS_CAPABILITY, EnumFacing.DOWN);
    }

    return null;
  }
}

代码示例来源:origin: Esteemed-Innovation/Esteemed-Innovation

private static void updateTicks(Entity entity, int ticks) {
  PlayerData nbt = entity.getCapability(EsteemedInnovation.PLAYER_DATA, null);
  nbt.setTickCache(ticks);
}

代码示例来源:origin: CoFH/CoFHCore

public static Iterable<ItemStack> getBaubles(Entity entity) {
  if (CAPABILITY_BAUBLES == null) {
    return Collections.emptyList();
  }
  IBaublesItemHandler handler = entity.getCapability(CAPABILITY_BAUBLES, null);
  if (handler == null) {
    return Collections.emptyList();
  }
  return IntStream.range(0, handler.getSlots()).mapToObj(handler::getStackInSlot).filter(stack -> !stack.isEmpty()).collect(Collectors.toList());
}

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

protected Optional<C> getCapability() {
  Entity e = getEntity();
  if(e != null && e.hasCapability(this.capability, this.side)) {
    return Optional.of(e.getCapability(this.capability, this.side));
  }
  return Optional.empty();
}

代码示例来源:origin: Esteemed-Innovation/Esteemed-Innovation

private static int getTicks(Entity entity) {
  PlayerData nbt = entity.getCapability(EsteemedInnovation.PLAYER_DATA, null);
  int ticks = nbt.getTickCache();
  if (ticks < 0) {
    nbt.setTickCache(0);
    ticks = 0;
  }
  return ticks;
}

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

/**
 * Returns the capability with the specified ID
 * @param id
 */
@SuppressWarnings("unchecked")
public static <E extends Entity> EntityCapability<?, ?, E> getCapability(ResourceLocation id, E entity) {
  EntityCapability<?, ?, ?> entityCapability = ID_CAPABILITY_MAP.get(id);
  if(entityCapability != null && entity.hasCapability(entityCapability.getCapability(), null)) {
    return (EntityCapability<?, ?, E>) entity.getCapability(entityCapability.getCapability(), null);
  }
  return null;
}

代码示例来源:origin: ForestryMC/ForestryMC

@Override
  public void onPacketData(PacketBufferForestry data, EntityPlayerMP player) throws IOException {
    Entity entity = data.readEntityById(player.world);
    if (entity != null && entity.hasCapability(ClimateCapabilities.CLIMATE_LISTENER, null)) {
      IClimateListener listener = entity.getCapability(ClimateCapabilities.CLIMATE_LISTENER, null);
      if (listener != null) {
        listener.syncToClient(player);
      }
    }
  }
}

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

/**
 * Returns the entity capability that is specific to the specified entity
 * @param entity
 * @return
 */
@SuppressWarnings("unchecked")
public final EntityCapability<?, ?, E> getEntityCapability(E entity) {
  if(entity.hasCapability(this.getCapability(), null))
    return (EntityCapability<?, ?, E>) entity.getCapability(this.getCapability(), null);
  return null;
}

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

@SuppressWarnings("ConstantConditions")
@Override
public void onEntityRemoved(Entity entityIn) {
  if (entityIn.hasCapability(CapabilityRespawnData.RESPAWN_DATA_CAPABILITY, null)) {
    IRespawnData respawnData = entityIn.getCapability(CapabilityRespawnData.RESPAWN_DATA_CAPABILITY, null);
    if (respawnData.canRespawn() && ((EntityLivingBase) entityIn).getHealth() > 0 && !(entityIn instanceof NpcFaction)) { //NpcFaction is handled separately
      SpawnerHelper.createSpawner(respawnData, entityIn.world);
    }
  }
}

代码示例来源:origin: ForestryMC/ForestryMC

@Override
  public void onPacketData(PacketBufferForestry data, EntityPlayer player) throws IOException {
    Entity entity = data.readEntityById(player.world);
    IClimateState state = data.readClimateState();
    if (entity != null && entity.hasCapability(ClimateCapabilities.CLIMATE_LISTENER, null)) {
      IClimateListener listener = entity.getCapability(ClimateCapabilities.CLIMATE_LISTENER, null);
      if (listener != null) {
        listener.setClimateState(state);
      }
    }
  }
}

代码示例来源:origin: TeamLapen/Vampirism

@SubscribeEvent
public void onLivingDeath(LivingDeathEvent event) {
  if (event.getEntity() instanceof EntityPlayer) {
    for (Capability listener : listeners) {
      ((IPlayerEventListener) event.getEntity().getCapability(listener, null)).onDeath(event.getSource());
    }
  }
}

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

continue;
if(e.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null) && !(e instanceof EntityPlayer)) {
  if(scanInventory(e.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null), pstack))
    entIdBuilder.add(e.getEntityId());

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

@SuppressWarnings("ConstantConditions")
private void setRespawnData(Entity e) {
  if (e.hasCapability(CapabilityRespawnData.RESPAWN_DATA_CAPABILITY, null)) {
    IRespawnData respawnData = e.getCapability(CapabilityRespawnData.RESPAWN_DATA_CAPABILITY, null);
    respawnData.setRespawnPos(e.getPosition());
    respawnData.setSpawnerSettings(getParentSettings().getParentSettings().writeToNBT(new NBTTagCompound()));
    respawnData.setSpawnTime(e.world.getTotalWorldTime());
  }
}

代码示例来源:origin: TeamLapen/Vampirism

@SubscribeEvent
public void onEntityJoinWorld(EntityJoinWorldEvent event) {
  if (event.getEntity().getEntityWorld().isRemote) {
    if ((event.getEntity() instanceof EntityPlayerSP && HelperRegistry.getSyncablePlayerCaps().size() > 0)) {
      VampLib.dispatcher.sendToServer(new RequestPlayerUpdatePacket());
    }
  }
  if (event.getEntity() instanceof EntityPlayer) {
    for (Capability listener : listeners) {
      ((IPlayerEventListener) event.getEntity().getCapability(listener, null)).onJoinWorld();
    }
  }
}

相关文章

Entity类方法