Search in sources :

Example 6 with IConduit

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

the class BlockConduitBundle method getLightValue.

@Override
public int getLightValue(@Nonnull IBlockState bs, @Nonnull IBlockAccess world, @Nonnull BlockPos pos) {
    TileConduitBundle te = getTileEntitySafe(world, pos);
    if (te == null) {
        return super.getLightValue(bs, world, pos);
    }
    int result = 0;
    if (te.hasFacade()) {
        IBlockState paintSource = te.getPaintSourceNN();
        result = paintSource.getLightValue();
        if (paintSource.isOpaqueCube()) {
            return result;
        }
    }
    if (ConduitConfig.dynamicLighting.get()) {
        Collection<? extends IConduit> conduits = te.getConduits();
        for (IConduit conduit : conduits) {
            result += conduit.getLightValue();
        }
    }
    return result > 15 ? 15 : result;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IConduit(crazypants.enderio.base.conduit.IConduit)

Example 7 with IConduit

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

the class BlockConduitBundle method breakConduit.

private boolean breakConduit(IConduitBundle te, List<ItemStack> drop, RaytraceResult rt, EntityPlayer player) {
    if (rt == null) {
        return false;
    }
    CollidableComponent component = rt.component;
    if (component == null) {
        return false;
    }
    Class<? extends IConduit> type = component.conduitType;
    if (!YetaUtil.renderConduit(player, type)) {
        return false;
    }
    if (type == null) {
        // broke a connector so drop any conduits with no connections as there
        // is no other way to remove these
        List<IConduit> cons = new ArrayList<IConduit>(te.getConduits());
        boolean droppedUnconected = false;
        for (IConduit con : cons) {
            if (con.getConduitConnections().isEmpty() && con.getExternalConnections().isEmpty() && YetaUtil.renderConduit(player, con)) {
                te.removeConduit(con);
                drop.addAll(con.getDrops());
                droppedUnconected = true;
            }
        }
        // If there isn't, then drop em all
        if (!droppedUnconected) {
            for (IConduit con : cons) {
                if (con != null && YetaUtil.renderConduit(player, con)) {
                    te.removeConduit(con);
                    drop.addAll(con.getDrops());
                }
            }
        }
    } else {
        IConduit con = te.getConduit(type);
        if (con != null) {
            te.removeConduit(con);
            drop.addAll(con.getDrops());
        }
    }
    return true;
}
Also used : CollidableComponent(crazypants.enderio.base.conduit.geom.CollidableComponent) ArrayList(java.util.ArrayList) IConduit(crazypants.enderio.base.conduit.IConduit)

Example 8 with IConduit

use of crazypants.enderio.base.conduit.IConduit 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)

Example 9 with IConduit

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

the class TileConduitBundle method addConnectors.

@SuppressWarnings("unchecked")
private void addConnectors(List<CollidableComponent> result) {
    if (getConduits().isEmpty()) {
        return;
    }
    for (IConduit con : getConduits()) {
        boolean b = con.haveCollidablesChangedSinceLastCall();
        collidablesDirty = collidablesDirty || b;
        connectorsDirty = connectorsDirty || b;
    }
    if (!connectorsDirty && !cachedConnectors.isEmpty()) {
        result.addAll(cachedConnectors);
        return;
    }
    cachedConnectors.clear();
    // TODO: What an unholly mess! (and it doesn't even work correctly...)
    List<CollidableComponent> coreBounds = new ArrayList<CollidableComponent>();
    for (IConduit con : getConduits()) {
        addConduitCores(coreBounds, con);
    }
    cachedConnectors.addAll(coreBounds);
    result.addAll(coreBounds);
    // 1st algorithm
    List<CollidableComponent> conduitsBounds = new ArrayList<CollidableComponent>();
    for (IConduit con : getConduits()) {
        conduitsBounds.addAll(con.getCollidableComponents());
        addConduitCores(conduitsBounds, con);
    }
    Set<Class<IConduit>> collidingTypes = new HashSet<Class<IConduit>>();
    for (CollidableComponent conCC : conduitsBounds) {
        for (CollidableComponent innerCC : conduitsBounds) {
            if (!InsulatedRedstoneConduit.COLOR_CONTROLLER_ID.equals(innerCC.data) && !InsulatedRedstoneConduit.COLOR_CONTROLLER_ID.equals(conCC.data) && conCC != innerCC && conCC.bound.intersects(innerCC.bound)) {
                collidingTypes.add((Class<IConduit>) conCC.conduitType);
            }
        }
    }
    // TODO: Remove the core geometries covered up by this as no point in rendering these
    if (!collidingTypes.isEmpty()) {
        List<CollidableComponent> colCores = new ArrayList<CollidableComponent>();
        for (Class<IConduit> c : collidingTypes) {
            IConduit con = getConduit(c);
            if (con != null) {
                addConduitCores(colCores, con);
            }
        }
        BoundingBox bb = null;
        for (CollidableComponent cBB : colCores) {
            if (bb == null) {
                bb = cBB.bound;
            } else {
                bb = bb.expandBy(cBB.bound);
            }
        }
        if (bb != null) {
            bb = bb.scale(1.05, 1.05, 1.05);
            CollidableComponent cc = new CollidableComponent(null, bb, null, ConduitConnectorType.INTERNAL);
            result.add(cc);
            cachedConnectors.add(cc);
        }
    }
    // 2nd algorithm
    for (IConduit con : getConduits()) {
        if (con.hasConnections()) {
            List<CollidableComponent> cores = new ArrayList<CollidableComponent>();
            addConduitCores(cores, con);
            if (cores.size() > 1) {
                BoundingBox bb = cores.get(0).bound;
                double area = bb.getArea();
                for (CollidableComponent cc : cores) {
                    bb = bb.expandBy(cc.bound);
                }
                if (bb.getArea() > area * 1.5f) {
                    bb = bb.scale(1.05, 1.05, 1.05);
                    CollidableComponent cc = new CollidableComponent(null, bb, null, ConduitConnectorType.INTERNAL);
                    result.add(cc);
                    cachedConnectors.add(cc);
                }
            }
        }
    }
    // Merge all internal conduit connectors into one box
    BoundingBox conBB = null;
    for (int i = 0; i < result.size(); i++) {
        CollidableComponent cc = result.get(i);
        if (cc.conduitType == null && cc.data == ConduitConnectorType.INTERNAL) {
            conBB = conBB == null ? cc.bound : conBB.expandBy(cc.bound);
            result.remove(i);
            i--;
            cachedConnectors.remove(cc);
        }
    }
    if (conBB != null) {
        CollidableComponent cc = new CollidableComponent(null, conBB, null, ConduitConnectorType.INTERNAL);
        result.add(cc);
        cachedConnectors.add(cc);
    }
    // External Connectors
    EnumSet<EnumFacing> externalDirs = EnumSet.noneOf(EnumFacing.class);
    for (IConduit con : getConduits()) {
        Set<EnumFacing> extCons = con.getExternalConnections();
        for (EnumFacing dir : extCons) {
            if (con.getConnectionMode(NullHelper.notnull(dir, "IConduit#getExternalConnections#iterator#next")) != ConnectionMode.DISABLED) {
                externalDirs.add(dir);
            }
        }
    }
    for (EnumFacing dir : externalDirs) {
        BoundingBox bb = ConduitGeometryUtil.instance.getExternalConnectorBoundingBox(dir);
        if (bb != null) {
            CollidableComponent cc = new CollidableComponent(null, bb, dir, ConduitConnectorType.EXTERNAL);
            result.add(cc);
            cachedConnectors.add(cc);
        }
    }
    connectorsDirty = false;
}
Also used : EnumFacing(net.minecraft.util.EnumFacing) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) IConduit(crazypants.enderio.base.conduit.IConduit) CollidableComponent(crazypants.enderio.base.conduit.geom.CollidableComponent) BoundingBox(com.enderio.core.client.render.BoundingBox) HashSet(java.util.HashSet)

Example 10 with IConduit

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

the class TileConduitBundle method getCollidableComponents.

@Override
public List<CollidableComponent> getCollidableComponents() {
    for (IConduit con : getConduits()) {
        collidablesDirty = collidablesDirty || con.haveCollidablesChangedSinceLastCall();
    }
    if (collidablesDirty) {
        connectorsDirty = true;
    }
    if (!collidablesDirty && !cachedCollidables.isEmpty()) {
        return cachedCollidables;
    }
    cachedCollidables.clear();
    for (IConduit conduit : getConduits()) {
        cachedCollidables.addAll(conduit.getCollidableComponents());
    }
    addConnectors(cachedCollidables);
    collidablesDirty = false;
    return cachedCollidables;
}
Also used : IConduit(crazypants.enderio.base.conduit.IConduit)

Aggregations

IConduit (crazypants.enderio.base.conduit.IConduit)13 CollidableComponent (crazypants.enderio.base.conduit.geom.CollidableComponent)5 IServerConduit (crazypants.enderio.base.conduit.IServerConduit)4 Nonnull (javax.annotation.Nonnull)3 ItemStack (net.minecraft.item.ItemStack)3 TileEntity (net.minecraft.tileentity.TileEntity)3 EnumFacing (net.minecraft.util.EnumFacing)3 IConduitBundle (crazypants.enderio.base.conduit.IConduitBundle)2 ArrayList (java.util.ArrayList)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 IBlockState (net.minecraft.block.state.IBlockState)2 World (net.minecraft.world.World)2 BoundingBox (com.enderio.core.client.render.BoundingBox)1 IClientConduit (crazypants.enderio.base.conduit.IClientConduit)1 RaytraceResult (crazypants.enderio.base.conduit.RaytraceResult)1 ConduitConnectorType (crazypants.enderio.base.conduit.geom.ConduitConnectorType)1 ConduitCacheKey (crazypants.enderio.conduits.render.BlockStateWrapperConduitBundle.ConduitCacheKey)1 HashSet (java.util.HashSet)1 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1