Search in sources :

Example 1 with ConduitConnectorType

use of crazypants.enderio.base.conduit.geom.ConduitConnectorType in project EnderIO by SleepyTrousers.

the class BlockConduitBundle method onBlockActivated.

@Override
public boolean onBlockActivated(@Nonnull World world, @Nonnull BlockPos pos, @Nonnull IBlockState state, @Nonnull EntityPlayer player, @Nonnull EnumHand hand, @Nonnull EnumFacing side, float hitX, float hitY, float hitZ) {
    IConduitBundle bundle = getTileEntity(world, pos);
    if (bundle == null) {
        return false;
    }
    ItemStack stack = player.getHeldItem(hand);
    // }
    if (stack.getItem() == ModObject.itemConduitFacade.getItem()) {
        // add or replace facade
        return handleFacadeClick(world, pos, player, side, bundle, stack, hand, hitX, hitY, hitZ);
    } else if (ConduitUtil.isConduitEquipped(player, hand)) {
        // Add conduit
        if (player.isSneaking()) {
            return false;
        }
        if (handleConduitClick(world, pos, player, bundle, stack, hand)) {
            return true;
        }
    } else if (ConduitUtil.isProbeEquipped(player, hand)) {
        // Handle copy / paste of settings
        if (handleConduitProbeClick(world, pos, player, bundle, stack)) {
            return true;
        }
    } else if (ToolUtil.isToolEquipped(player, hand) && player.isSneaking()) {
        // Break conduit with tool
        if (handleWrenchClick(world, pos, player, hand)) {
            return true;
        }
    }
    // Check conduit defined actions
    RaytraceResult closest = doRayTrace(world, pos, player);
    @Nonnull List<RaytraceResult> all = NullHelper.notnullJ(Collections.emptyList(), "Collections#emptyList");
    if (closest != null) {
        all = doRayTraceAll(world, pos, player);
    }
    final CollidableComponent closestComponent = closest == null ? null : closest.component;
    if (closestComponent != null && closestComponent.data instanceof ConduitConnectorType) {
        ConduitConnectorType conType = (ConduitConnectorType) closestComponent.data;
        if (conType == ConduitConnectorType.INTERNAL) {
            boolean result = false;
            // if its a connector pass the event on to all conduits
            for (IConduit con : bundle.getConduits()) {
                RaytraceResult res = getHitForConduitType(all, con.getCollidableType());
                if (res != null && YetaUtil.renderConduit(player, con.getCollidableType()) && con.onBlockActivated(player, hand, res, all)) {
                    bundle.getEntity().markDirty();
                    result = true;
                }
            }
            if (result) {
                return true;
            }
        } else {
            if (!world.isRemote) {
                openGui(world, pos, player, closestComponent.dir, closestComponent.dir.ordinal());
            }
            return true;
        }
    }
    if (closestComponent == null || closestComponent.conduitType == null && all.isEmpty()) {
        // Nothing of interest hit
        return false;
    }
    // Conduit specific actions
    if (all.isEmpty()) {
        RaytraceResult.sort(Util.getEyePosition(player), all);
        for (RaytraceResult rr : all) {
            final CollidableComponent component = rr.component;
            if (component != null && YetaUtil.renderConduit(player, component.conduitType) && !(component.data instanceof ConduitConnectorType)) {
                IConduit con = bundle.getConduit(component.conduitType);
                if (con != null && con.onBlockActivated(player, hand, rr, all)) {
                    bundle.getEntity().markDirty();
                    return true;
                }
            }
        }
    } else {
        IConduit closestConduit = bundle.getConduit(closestComponent.conduitType);
        if (closest != null && closestConduit != null && YetaUtil.renderConduit(player, closestConduit) && closestConduit.onBlockActivated(player, hand, closest, all)) {
            bundle.getEntity().markDirty();
            return true;
        }
    }
    return false;
}
Also used : Nonnull(javax.annotation.Nonnull) CollidableComponent(crazypants.enderio.base.conduit.geom.CollidableComponent) ConduitConnectorType(crazypants.enderio.base.conduit.geom.ConduitConnectorType) IConduitBundle(crazypants.enderio.base.conduit.IConduitBundle) IConduit(crazypants.enderio.base.conduit.IConduit) ItemStack(net.minecraft.item.ItemStack) RaytraceResult(crazypants.enderio.base.conduit.RaytraceResult)

Aggregations

IConduit (crazypants.enderio.base.conduit.IConduit)1 IConduitBundle (crazypants.enderio.base.conduit.IConduitBundle)1 RaytraceResult (crazypants.enderio.base.conduit.RaytraceResult)1 CollidableComponent (crazypants.enderio.base.conduit.geom.CollidableComponent)1 ConduitConnectorType (crazypants.enderio.base.conduit.geom.ConduitConnectorType)1 Nonnull (javax.annotation.Nonnull)1 ItemStack (net.minecraft.item.ItemStack)1