本文整理了Java中net.minecraft.entity.Entity.hasCapability()
方法的一些代码示例,展示了Entity.hasCapability()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Entity.hasCapability()
方法的具体详情如下:
包路径:net.minecraft.entity.Entity
类名称:Entity
方法名:hasCapability
暂无
代码示例来源: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 getMatchingItemstackFromInventory(ItemStack stack, Entity entity, boolean damagedOnly) {
if(stack == null || !entity.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)) {
return ItemStack.EMPTY;
代码示例来源: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: 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: MatterOverdrive/MatterOverdrive-Legacy-Edition
public static AndroidPlayer GetAndroidCapability(Entity entity) {
if (entity == null)
return null;
return entity.hasCapability(AndroidPlayer.CAPABILITY, null) ? entity.getCapability(AndroidPlayer.CAPABILITY, null) : null;
}
代码示例来源: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: vadis365/TheErebus
/**
* Returns a list of all found registered capabilities on an entity
* @param entity
* @return
*/
@SuppressWarnings("unchecked")
private static <E extends Entity> List<EntityCapability<?, ?, E>> getEntityCapabilities(E entity) {
List<EntityCapability<?, ?, E>> capabilities = new ArrayList<EntityCapability<?, ?, E>>();
for(EntityCapability<?, ?, ?> capability : REGISTERED_CAPABILITIES) {
if(entity.hasCapability(capability.getCapability(), null))
capabilities.add((EntityCapability<?, ?, E>) entity.getCapability(capability.getCapability(), null));
}
return capabilities;
}
代码示例来源: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: McJtyMods/TheOneProbe
@SubscribeEvent
public void onEntityConstructing(AttachCapabilitiesEvent<Entity> event){
if (event.getObject() instanceof EntityPlayer) {
if (!event.getObject().hasCapability(PlayerProperties.PLAYER_GOT_NOTE, null)) {
event.addCapability(new ResourceLocation(TheOneProbe.MODID, "Properties"), new PropertiesDispatcher());
}
}
}
代码示例来源:origin: Vazkii/Botania
if(e == player)
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());
}
}
内容来源于网络,如有侵权,请联系作者删除!