Search in sources :

Example 26 with BoundingBox

use of com.enderio.core.client.render.BoundingBox in project EnderIO by SleepyTrousers.

the class DefaultConduitRenderer method renderConduitDynamic.

protected void renderConduitDynamic(TextureAtlasSprite tex, IClientConduit.WithDefaultRendering conduit, CollidableComponent component, float brightness) {
    GlStateManager.color(1, 1, 1);
    if (isNSEWUD(component.dir)) {
        float scaleFactor = 0.75f;
        float xLen = Math.abs(component.dir.getFrontOffsetX()) == 1 ? 1 : scaleFactor;
        float yLen = Math.abs(component.dir.getFrontOffsetY()) == 1 ? 1 : scaleFactor;
        float zLen = Math.abs(component.dir.getFrontOffsetZ()) == 1 ? 1 : scaleFactor;
        BoundingBox cube = component.bound;
        BoundingBox bb = cube.scale(xLen, yLen, zLen);
        drawDynamicSection(bb, tex.getMinU(), tex.getMaxU(), tex.getMinV(), tex.getMaxV(), component.dir, false, conduit.shouldMirrorTexture());
        if (conduit.getConnectionMode(component.dir) == ConnectionMode.DISABLED) {
            tex = ConduitBundleRenderManager.instance.getConnectorIcon(component.data);
            List<Vertex> corners = component.bound.getCornersWithUvForFace(component.dir, tex.getMinU(), tex.getMaxU(), tex.getMinV(), tex.getMaxV());
            RenderUtil.addVerticesToTessellator(corners, DefaultVertexFormats.POSITION_TEX, false);
        }
    } else {
        drawDynamicSection(component.bound, tex.getMinU(), tex.getMaxU(), tex.getMinV(), tex.getMaxV(), component.dir, true);
    }
}
Also used : Vertex(com.enderio.core.common.vecmath.Vertex) BoundingBox(com.enderio.core.client.render.BoundingBox)

Example 27 with BoundingBox

use of com.enderio.core.client.render.BoundingBox in project EnderIO by SleepyTrousers.

the class DefaultConduitRenderer method toCubes.

// This is a really hacky, imprecise and slow way to do this
public BoundingBox[] toCubes(BoundingBox bb) {
    // NB This on handles the really simple conduit case!
    double width = bb.maxX - bb.minX;
    double height = bb.maxY - bb.minY;
    double depth = bb.maxZ - bb.minZ;
    if (width > 0 && height > 0 && depth > 0) {
        if (width / depth > 1.5f || depth / width > 1.5f) {
            // split horizontally
            if (width > depth) {
                int numSplits = (int) Math.round(width / depth);
                double newWidth = width / numSplits;
                BoundingBox[] result = new BoundingBox[numSplits];
                double lastMax = bb.minX;
                for (int i = 0; i < numSplits; i++) {
                    double max = lastMax + newWidth;
                    result[i] = new BoundingBox(lastMax, bb.minY, bb.minZ, max, bb.maxY, bb.maxZ);
                    lastMax = max;
                }
                return result;
            } else {
                int numSplits = (int) Math.round(depth / width);
                double newWidth = depth / numSplits;
                BoundingBox[] result = new BoundingBox[numSplits];
                double lastMax = bb.minZ;
                for (int i = 0; i < numSplits; i++) {
                    double max = lastMax + newWidth;
                    result[i] = new BoundingBox(bb.minX, bb.minY, lastMax, bb.maxX, bb.maxY, max);
                    lastMax = max;
                }
                return result;
            }
        } else if (height / width > 1.5) {
            int numSplits = (int) Math.round(height / width);
            double newWidth = height / numSplits;
            BoundingBox[] result = new BoundingBox[numSplits];
            double lastMax = bb.minY;
            for (int i = 0; i < numSplits; i++) {
                double max = lastMax + newWidth;
                result[i] = new BoundingBox(bb.minX, lastMax, bb.minZ, bb.maxX, max, bb.maxZ);
                lastMax = max;
            }
            return result;
        }
    }
    return new BoundingBox[] { bb };
}
Also used : BoundingBox(com.enderio.core.client.render.BoundingBox)

Example 28 with BoundingBox

use of com.enderio.core.client.render.BoundingBox 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 29 with BoundingBox

use of com.enderio.core.client.render.BoundingBox in project EnderIO by SleepyTrousers.

the class TransceiverRenderer method renderTileEntity.

@Override
protected void renderTileEntity(@Nonnull TileTransceiver te, @Nonnull IBlockState blockState, float partialTicks, int destroyStage) {
    TextureAtlasSprite icon = ((BlockTransceiver) block_transceiver.getBlockNN()).getPortalIcon();
    if (icon == null) {
        return;
    }
    float time = Math.abs(50 - (EnderIO.proxy.getTickCount() % 100)) / 50f;
    float localScale = scale + 0.05f - time * 0.1f;
    float alpha = 0.7f + time * 0.25f;
    BoundingBox bb = BoundingBox.UNIT_CUBE.scale(localScale, localScale, localScale);
    GlStateManager.color(1, 1, 1, alpha);
    GlStateManager.enableNormalize();
    RenderUtil.renderBoundingBox(bb, icon);
    GlStateManager.disableNormalize();
}
Also used : TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) BoundingBox(com.enderio.core.client.render.BoundingBox) BlockTransceiver(crazypants.enderio.machines.machine.transceiver.BlockTransceiver)

Example 30 with BoundingBox

use of com.enderio.core.client.render.BoundingBox in project EnderIO by SleepyTrousers.

the class TileXPVacuum method doHoover.

private void doHoover() {
    boolean pickUpThisTick = xpCon.getFluidAmount() == 0;
    for (EntityXPOrb entity : world.getEntitiesWithinAABB(EntityXPOrb.class, new BoundingBox(getPos()).expand(VacuumConfig.vacuumXPRange.get()), this)) {
        // note the Predicate parameter
        double x = (pos.getX() + 0.5D - entity.posX);
        double y = (pos.getY() + 0.5D - entity.posY);
        double z = (pos.getZ() + 0.5D - entity.posZ);
        double distance = Math.sqrt(x * x + y * y + z * z);
        if (distance < 1.25) {
            if (pickUpThisTick && !world.isRemote && !entity.isDead) {
                int xpValue = entity.getXpValue();
                xpCon.addExperience(xpValue);
                entity.setDead();
            }
        } else {
            double distScale = Math.min(1d, Math.max(0.25d, 1d - distance / VacuumConfig.vacuumXPRange.get()));
            distScale *= distScale;
            entity.motionX += x / distance * distScale * speed;
            if (entity.posY < pos.getY()) {
                entity.motionY += y / distance * distScale * speed + .03;
            } else {
                entity.motionY += y / distance * distScale * speed;
            }
            entity.motionZ += z / distance * distScale * speed;
        }
    }
}
Also used : BoundingBox(com.enderio.core.client.render.BoundingBox) EntityXPOrb(net.minecraft.entity.item.EntityXPOrb)

Aggregations

BoundingBox (com.enderio.core.client.render.BoundingBox)30 Nonnull (javax.annotation.Nonnull)11 EnumFacing (net.minecraft.util.EnumFacing)11 Vector3d (com.enderio.core.common.vecmath.Vector3d)9 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)9 ArrayList (java.util.ArrayList)7 CollidableComponent (crazypants.enderio.base.conduit.geom.CollidableComponent)5 Vector4f (com.enderio.core.common.vecmath.Vector4f)4 Vertex (com.enderio.core.common.vecmath.Vertex)4 HalfBakedList (crazypants.enderio.base.render.util.HalfBakedQuad.HalfBakedList)3 FluidStack (net.minecraftforge.fluids.FluidStack)3 VertexRotationFacing (com.enderio.core.client.render.VertexRotationFacing)2 Offset (crazypants.enderio.base.conduit.geom.Offset)2 HashSet (java.util.HashSet)2 BufferBuilder (net.minecraft.client.renderer.BufferBuilder)2 TileEntity (net.minecraft.tileentity.TileEntity)2 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)2 BlockPos (net.minecraft.util.math.BlockPos)2 VertexTransform (com.enderio.core.api.client.render.VertexTransform)1 VertexRotation (com.enderio.core.client.render.VertexRotation)1