Java Code Examples for net.minecraft.entity.Entity#getCapability()

The following examples show how to use net.minecraft.entity.Entity#getCapability() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EntityRequest.java    From HoloInventory with MIT License 6 votes vote down vote up
@Override
public ResponseMessage onMessage(EntityRequest message, MessageContext ctx)
{
    World world = DimensionManager.getWorld(message.dim);
    if (world == null) return null;
    Entity entity = world.getEntityByID(message.id);
    if (entity == null) return null;

    if (entity instanceof IInventory) return new PlainInventory(message.id, (IInventory) entity);
    else if (entity instanceof IMerchant) return new MerchantRecipes(message.id, (IMerchant) entity, ctx.getServerHandler().player);
    else if (entity.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null))
    {
        return new PlainInventory(message.id, entity.getName(), entity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null));
    }

    return null;
}
 
Example 2
Source File: SquashableMod.java    From CommunityMod with GNU Lesser General Public License v2.1 5 votes vote down vote up
@SubscribeEvent
public static void onEntityTrack(PlayerEvent.StartTracking event) {
    Entity target = event.getTarget();
    Squashable squashable = target.getCapability(squashableCap(), null);
    if (squashable == null) {
        return;
    }

    EnumFacing.Axis squashedAxis = squashable.getSquashedAxis();
    if (squashedAxis != null) {
        NETWORK.sendTo(new SquashEntityMessage(target, squashedAxis), (EntityPlayerMP) event.getEntityPlayer());
    }
}
 
Example 3
Source File: PacketUpdateMinecartEngineState.java    From Signals with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void handleClientSide(EntityPlayer player){
    Entity entity = player.world.getEntityByID(entityId);
    if(entity != null) {
        CapabilityMinecartDestination cap = entity.getCapability(CapabilityMinecartDestination.INSTANCE, null);
        if(cap != null) {
            cap.setEngineActive(active);
        }
    }
}
 
Example 4
Source File: EventHandler.java    From Signals with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onEntityRemoved(Entity entityIn){
    if(entityIn instanceof EntityMinecart && !entityIn.world.isRemote) {
        EntityMinecart cart = (EntityMinecart)entityIn;
        CapabilityMinecartDestination cap = entityIn.getCapability(CapabilityMinecartDestination.INSTANCE, null);
        if(cap != null) cap.onCartBroken(cart);
    }
}
 
Example 5
Source File: BlockEnderUtilitiesPortal.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void updatePortalCooldown(Entity entity, long currentTime)
{
    IPortalCooldownCapability cap = entity.getCapability(EnderUtilitiesCapabilities.CAPABILITY_PORTAL_COOLDOWN, null);

    if (cap != null)
    {
        cap.setLastInPortalTime(currentTime);
    }
}
 
Example 6
Source File: MessageBackpackUpdate.java    From WearableBackpacks with MIT License 5 votes vote down vote up
@Override
@SideOnly(Side.CLIENT)
public void handle(MessageBackpackUpdate message, MessageContext ctx) {
	Entity entity = getWorld(ctx).getEntityByID(message._entityId);
	if (entity == null) return;
	BackpackCapability backpack = (BackpackCapability)entity
		.getCapability(IBackpack.CAPABILITY, null);
	if (backpack == null) return;
	switch (message._type) {
		case STACK: backpack.stack = message._stack; break;
		case OPEN: backpack.playersUsing = (message._open ? 1 : 0); break;
		default: throw new RuntimeException("Invalid UpdateType");
	}
}
 
Example 7
Source File: MiscCapabilityProvider.java    From Wizardry with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Nullable
public static IMiscCapability getCap(Entity entity) {
	return entity.getCapability(miscCapability, null);
}
 
Example 8
Source File: ManaCapabilityProvider.java    From Wizardry with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Nullable
public static IManaCapability getCap(Entity entity) {
	return entity.getCapability(MANA_CAPABILITY, null);
}
 
Example 9
Source File: BlockEnderUtilitiesPortal.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
private boolean isEntityUnderPortalCooldown(Entity entity, long currentTime, int cooldown)
{
    IPortalCooldownCapability cap = entity.getCapability(EnderUtilitiesCapabilities.CAPABILITY_PORTAL_COOLDOWN, null);
    return cap != null && ((currentTime - cap.getLastInPortalTime()) < cooldown);
}
 
Example 10
Source File: BackpackHelper.java    From WearableBackpacks with MIT License 4 votes vote down vote up
/** Returns the entity's backpack capability, or null if the
 *  entity either can't or currently doesn't have one equipped. */
public static IBackpack getBackpack(Entity entity) {
	if (entity == null) return null;
	IBackpack backpack = entity.getCapability(IBackpack.CAPABILITY, null);
	return ((backpack != null) && !backpack.getStack().isEmpty()) ? backpack : null;
}
 
Example 11
Source File: CyberwareAPI.java    From Cyberware with MIT License 2 votes vote down vote up
/**
 * Assistant method to hasCapability. A shortcut to get you the ICyberwareUserData
 * of a specific entity. Note that you must verify if it has the capability first.
 * 
 * @param targetEntity	The entity whose ICyberwareUserData you want
 * @return				The ICyberwareUserData associated with the entity
 */
public static ICyberwareUserData getCapability(Entity targetEntity)
{
	return targetEntity.getCapability(CYBERWARE_CAPABILITY, EnumFacing.EAST);
}