Search in sources :

Example 11 with CollidableComponent

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

the class DefaultConduitRenderer method addBakedQuads.

// ------------ Static Model ---------------------------------------------
@Override
public void addBakedQuads(@Nonnull TileEntitySpecialRenderer<?> conduitBundleRenderer, @Nonnull IConduitBundle bundle, @Nonnull IClientConduit.WithDefaultRendering conduit, float brightness, @Nonnull BlockRenderLayer layer, List<BakedQuad> quads) {
    Collection<CollidableComponent> components = conduit.getCollidableComponents();
    transmissionScaleFactor = conduit.getTransmitionGeometryScale();
    for (CollidableComponent component : components) {
        if (renderComponent(component)) {
            float selfIllum = Math.max(brightness, conduit.getSelfIlluminationForState(component));
            final TextureAtlasSprite transmitionTextureForState = conduit.getTransmitionTextureForState(component);
            if (layer != null && isNSEWUD(component.dir) && transmitionTextureForState != null) {
                Vector4f color = conduit.getTransmitionTextureColorForState(component);
                addTransmissionQuads(transmitionTextureForState, color, conduit, component, selfIllum, quads);
            }
            TextureAtlasSprite tex = conduit.getTextureForState(component);
            if (tex == null) {
                tex = Minecraft.getMinecraft().getTextureMapBlocks().getMissingSprite();
            }
            addConduitQuads(bundle, conduit, tex, component, selfIllum, layer, quads);
        }
    }
}
Also used : Vector4f(com.enderio.core.common.vecmath.Vector4f) CollidableComponent(crazypants.enderio.base.conduit.geom.CollidableComponent) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite)

Example 12 with CollidableComponent

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

the class BlockConduitBundle method addHitEffects.

@SideOnly(Side.CLIENT)
@Override
public boolean addHitEffects(@Nonnull IBlockState state, @Nonnull World world, @Nonnull RayTraceResult target, @Nonnull ParticleManager effectRenderer) {
    TileConduitBundle cb = getTileEntity(world, target.getBlockPos());
    if (cb == null) {
        return false;
    }
    TextureAtlasSprite tex = null;
    if (YetaUtil.isSolidFacadeRendered(cb, Minecraft.getMinecraft().player)) {
        IBlockState paintSource = cb.getPaintSource();
        if (paintSource != null) {
            tex = RenderUtil.getTexture(paintSource);
        }
    } else if (target.hitInfo instanceof CollidableComponent) {
        CollidableComponent cc = (CollidableComponent) target.hitInfo;
        IConduit con = cb.getConduit(cc.conduitType);
        if (con != null && con instanceof IClientConduit.WithDefaultRendering) {
            tex = ((IClientConduit.WithDefaultRendering) con).getTextureForState(cc);
        }
    }
    if (tex == null) {
        tex = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes().getTexture(ModObject.block_machine_base.getBlockNN().getDefaultState());
    }
    lastHitIcon = tex;
    addBlockHitEffects(world, effectRenderer, target.hitVec.x, target.hitVec.y, target.hitVec.z, target.sideHit, tex);
    return true;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) CollidableComponent(crazypants.enderio.base.conduit.geom.CollidableComponent) IConduit(crazypants.enderio.base.conduit.IConduit) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 13 with CollidableComponent

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

the class BlockConduitBundle method doRayTraceAll.

@Nonnull
protected NNList<RaytraceResult> doRayTraceAll(@Nonnull IBlockState bs, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Vec3d origin, @Nonnull Vec3d direction, EntityPlayer player) {
    TileEntity te = world.getTileEntity(pos);
    if (!(te instanceof IConduitBundle)) {
        return NNList.emptyList();
    }
    IConduitBundle bundle = (IConduitBundle) te;
    NNList<RaytraceResult> hits = new NNList<RaytraceResult>();
    if (YetaUtil.isSolidFacadeRendered(bundle, player)) {
        setBlockBounds(0, 0, 0, 1, 1, 1);
        RayTraceResult hitPos = super.collisionRayTrace(bs, world, pos, origin, direction);
        if (hitPos != null) {
            hits.add(new RaytraceResult(new CollidableComponent(null, BoundingBox.UNIT_CUBE, hitPos.sideHit, null), hitPos));
        }
    } else {
        ConduitDisplayMode mode = YetaUtil.getDisplayMode(player);
        for (CollidableComponent component : new ArrayList<CollidableComponent>(bundle.getCollidableComponents())) {
            if (mode.isAll() || component.conduitType == null || YetaUtil.renderConduit(player, component.conduitType)) {
                setBlockBounds(component.bound.minX, component.bound.minY, component.bound.minZ, component.bound.maxX, component.bound.maxY, component.bound.maxZ);
                RayTraceResult hitPos = super.collisionRayTrace(bs, world, pos, origin, direction);
                if (hitPos != null) {
                    hits.add(new RaytraceResult(component, hitPos));
                }
            }
        }
        // safety to prevent unbreakable empty bundles in case of a bug
        if (bundle.getConduits().isEmpty() && !YetaUtil.isFacadeHidden(bundle, player)) {
            setBlockBounds(0, 0, 0, 1, 1, 1);
            RayTraceResult hitPos = super.collisionRayTrace(bs, world, pos, origin, direction);
            if (hitPos != null) {
                hits.add(new RaytraceResult(null, hitPos));
            }
        }
    }
    setBlockBounds(0, 0, 0, 1, 1, 1);
    return hits;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ConduitDisplayMode(crazypants.enderio.base.conduit.ConduitDisplayMode) CollidableComponent(crazypants.enderio.base.conduit.geom.CollidableComponent) NNList(com.enderio.core.common.util.NNList) RayTraceResult(net.minecraft.util.math.RayTraceResult) ArrayList(java.util.ArrayList) IConduitBundle(crazypants.enderio.base.conduit.IConduitBundle) RaytraceResult(crazypants.enderio.base.conduit.RaytraceResult) Nonnull(javax.annotation.Nonnull)

Example 14 with CollidableComponent

use of crazypants.enderio.base.conduit.geom.CollidableComponent 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 15 with CollidableComponent

use of crazypants.enderio.base.conduit.geom.CollidableComponent 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

CollidableComponent (crazypants.enderio.base.conduit.geom.CollidableComponent)17 ArrayList (java.util.ArrayList)7 Nonnull (javax.annotation.Nonnull)7 EnumFacing (net.minecraft.util.EnumFacing)6 BoundingBox (com.enderio.core.client.render.BoundingBox)5 IConduit (crazypants.enderio.base.conduit.IConduit)5 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)5 IConduitBundle (crazypants.enderio.base.conduit.IConduitBundle)4 RaytraceResult (crazypants.enderio.base.conduit.RaytraceResult)4 Vector4f (com.enderio.core.common.vecmath.Vector4f)2 IClientConduit (crazypants.enderio.base.conduit.IClientConduit)2 IConduitRenderer (crazypants.enderio.base.conduit.IConduitRenderer)2 HashSet (java.util.HashSet)2 ItemStack (net.minecraft.item.ItemStack)2 RayTraceResult (net.minecraft.util.math.RayTraceResult)2 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)2 NNList (com.enderio.core.common.util.NNList)1 ConduitDisplayMode (crazypants.enderio.base.conduit.ConduitDisplayMode)1 ConduitConnectorType (crazypants.enderio.base.conduit.geom.ConduitConnectorType)1 IRedstoneConduit (crazypants.enderio.conduits.conduit.redstone.IRedstoneConduit)1