Search in sources :

Example 1 with IRobotOverlayItem

use of buildcraft.api.robots.IRobotOverlayItem in project BuildCraft by BuildCraft.

the class EntityRobot method interact.

@Override
protected boolean interact(EntityPlayer player) {
    ItemStack stack = player.getCurrentEquippedItem();
    if (stack == null || stack.getItem() == null) {
        return false;
    }
    RobotEvent.Interact robotInteractEvent = new RobotEvent.Interact(this, player, stack);
    MinecraftForge.EVENT_BUS.post(robotInteractEvent);
    if (robotInteractEvent.isCanceled()) {
        return false;
    }
    if (player.isSneaking() && stack.getItem() instanceof IToolWrench) {
        RobotEvent.Dismantle robotDismantleEvent = new RobotEvent.Dismantle(this, player);
        MinecraftForge.EVENT_BUS.post(robotDismantleEvent);
        if (robotDismantleEvent.isCanceled()) {
            return false;
        }
        onRobotHit(false);
        if (worldObj.isRemote) {
            ((IToolWrench) stack.getItem()).wrenchUsed(player, this);
        }
        return true;
    } else if (wearables.size() < MAX_WEARABLES && stack.getItem().isValidArmor(stack, 0, this)) {
        if (!worldObj.isRemote) {
            wearables.add(stack.splitStack(1));
            syncWearablesToClient();
        } else {
            player.swingItem();
        }
        return true;
    } else if (wearables.size() < MAX_WEARABLES && stack.getItem() instanceof IRobotOverlayItem && ((IRobotOverlayItem) stack.getItem()).isValidRobotOverlay(stack)) {
        if (!worldObj.isRemote) {
            wearables.add(stack.splitStack(1));
            syncWearablesToClient();
        } else {
            player.swingItem();
        }
        return true;
    } else if (wearables.size() < MAX_WEARABLES && stack.getItem() instanceof ItemSkull) {
        if (!worldObj.isRemote) {
            ItemStack skullStack = stack.splitStack(1);
            initSkullItem(skullStack);
            wearables.add(skullStack);
            syncWearablesToClient();
        } else {
            player.swingItem();
        }
        return true;
    } else {
        return super.interact(player);
    }
}
Also used : IToolWrench(buildcraft.api.tools.IToolWrench) IRobotOverlayItem(buildcraft.api.robots.IRobotOverlayItem) ItemStack(net.minecraft.item.ItemStack) RobotEvent(buildcraft.api.events.RobotEvent) ItemSkull(net.minecraft.item.ItemSkull)

Aggregations

RobotEvent (buildcraft.api.events.RobotEvent)1 IRobotOverlayItem (buildcraft.api.robots.IRobotOverlayItem)1 IToolWrench (buildcraft.api.tools.IToolWrench)1 ItemSkull (net.minecraft.item.ItemSkull)1 ItemStack (net.minecraft.item.ItemStack)1