Search in sources :

Example 1 with WireFace

use of pl.asie.charset.api.wires.WireFace in project Charset by CharsetMC.

the class RendererWire method addWire.

public void addWire(Wire wire, WireSheet sheet, List<BakedQuad> quads) {
    WireFace side = wire.getLocation();
    int renderColor = wire.getRenderColor();
    if (side == WireFace.CENTER) {
        addWireFreestanding(wire, sheet, renderColor, quads);
        return;
    }
    float min = 8.0f - (sheet.width / 2);
    float max = 8.0f + (sheet.width / 2);
    float minH = 0.0f;
    float maxH = sheet.height;
    EnumFacing[] dirs = WireUtils.getConnectionsForRender(side);
    boolean[] connectionMatrix = new boolean[] { wire == null || wire.connectsAny(dirs[0]), wire == null || wire.connectsAny(dirs[1]), wire == null || wire.connectsAny(dirs[2]), wire == null || wire.connectsAny(dirs[3]) };
    int cmc = (connectionMatrix[0] ? 8 : 0) | (connectionMatrix[1] ? 4 : 0) | (connectionMatrix[2] ? 2 : 0) | (connectionMatrix[3] ? 1 : 0);
    boolean[] cornerConnectionMatrix = new boolean[] { wire == null || wire.connectsCorner(dirs[0]), wire == null || wire.connectsCorner(dirs[1]), wire == null || wire.connectsCorner(dirs[2]), wire == null || wire.connectsCorner(dirs[3]) };
    ModelRotation rot = ROTATIONS[side.ordinal()];
    // Center face
    Vector3f from = new Vector3f(min, sheet.height, min);
    Vector3f to = new Vector3f(max, sheet.height, max);
    if (connectionMatrix[0]) {
        from.setZ(0.0f);
    }
    if (connectionMatrix[1]) {
        to.setZ(16.0f);
    }
    if (connectionMatrix[2]) {
        from.setX(0.0f);
    }
    if (connectionMatrix[3]) {
        to.setX(16.0f);
    }
    quads.add(RenderUtils.BAKERY.makeBakedQuad(from, to, renderColor, new float[] { from.getX(), from.getZ(), to.getX(), to.getZ() }, sheet.top[cmc], EnumFacing.UP, rot, true));
    if (!wire.getFactory().isFlat()) {
        from.setY(0.0F);
        to.setY(0.0F);
        quads.add(RenderUtils.BAKERY.makeBakedQuad(from, to, renderColor, new float[] { from.getX(), from.getZ(), to.getX(), to.getZ() }, sheet.top[cmc], EnumFacing.DOWN, rot, true));
        // Side faces
        Vector3f fromZ = new Vector3f(from.getX(), 0.0f, min);
        Vector3f toZ = new Vector3f(to.getX(), sheet.height, min);
        Vector3f fromX = new Vector3f(min, 0.0f, from.getZ());
        Vector3f toX = new Vector3f(min, sheet.height, to.getZ());
        // Should we render a faux side wire on this side? (For bundled)
        boolean crossroadsX = connectionMatrix[2] && !connectionMatrix[3];
        boolean crossroadsZ = connectionMatrix[0] && !connectionMatrix[1];
        // getIcon(false, cmc == 1, crossroadsX, EnumFacing.WEST)
        if (sheet.side != null) {
            quads.add(RenderUtils.BAKERY.makeBakedQuad(fromX, toX, renderColor, new float[] { fromX.getZ(), fromX.getY(), toX.getZ(), toX.getY() }, sheet.side, EnumFacing.WEST, rot, false));
            // getIcon(false, cmc == 0 || cmc == 4, crossroadsZ, EnumFacing.NORTH)
            quads.add(RenderUtils.BAKERY.makeBakedQuad(fromZ, toZ, renderColor, new float[] { toZ.getX(), fromZ.getY(), fromZ.getX(), toZ.getY() }, sheet.side, EnumFacing.NORTH, rot, false));
        }
        fromX.setX(max);
        toX.setX(max);
        fromZ.setZ(max);
        toZ.setZ(max);
        if (sheet.side != null) {
            // getIcon(false, cmc == 2, crossroadsX, EnumFacing.EAST)
            quads.add(RenderUtils.BAKERY.makeBakedQuad(fromX, toX, renderColor, new float[] { toX.getZ(), fromX.getY(), fromX.getZ(), toX.getY() }, sheet.side, EnumFacing.EAST, rot, false));
            // getIcon(false, cmc == 0 || cmc == 8, crossroadsZ, EnumFacing.SOUTH)
            quads.add(RenderUtils.BAKERY.makeBakedQuad(fromZ, toZ, renderColor, new float[] { fromZ.getX(), fromZ.getY(), toZ.getX(), toZ.getY() }, sheet.side, EnumFacing.SOUTH, rot, false));
        }
        // Edge faces
        float[] edgeUV = new float[] { min, minH, max, maxH };
        float[] edgeUVFlipped = new float[] { max, minH, min, maxH };
        if (sheet.edge != null) {
            if (connectionMatrix[0]) {
                quads.add(RenderUtils.BAKERY.makeBakedQuad(new Vector3f(min, minH, 0.0F), new Vector3f(max, maxH, 0.0F), renderColor, edgeUVFlipped, sheet.edge, EnumFacing.NORTH, rot, false));
            }
            if (connectionMatrix[1]) {
                quads.add(RenderUtils.BAKERY.makeBakedQuad(new Vector3f(min, minH, 16.0F), new Vector3f(max, maxH, 16.0F), renderColor, edgeUV, sheet.edge, EnumFacing.SOUTH, rot, false));
            }
            if (connectionMatrix[2]) {
                quads.add(RenderUtils.BAKERY.makeBakedQuad(new Vector3f(0.0F, minH, min), new Vector3f(0.0F, maxH, max), renderColor, edgeUV, sheet.edge, EnumFacing.WEST, rot, false));
            }
            if (connectionMatrix[3]) {
                quads.add(RenderUtils.BAKERY.makeBakedQuad(new Vector3f(16.0F, minH, min), new Vector3f(16.0F, maxH, max), renderColor, edgeUVFlipped, sheet.edge, EnumFacing.EAST, rot, false));
            }
        }
        EnumFacing[] dirs0 = WireUtils.getConnectionsForRender(WireFace.DOWN);
        for (int i = 0; i < 4; i++) {
            if (cornerConnectionMatrix[i]) {
                addCorner(wire, sheet, dirs0[i], renderColor, quads);
            }
        }
    }
}
Also used : ModelRotation(net.minecraft.client.renderer.block.model.ModelRotation) EnumFacing(net.minecraft.util.EnumFacing) Vector3f(org.lwjgl.util.vector.Vector3f) WireFace(pl.asie.charset.api.wires.WireFace)

Example 2 with WireFace

use of pl.asie.charset.api.wires.WireFace in project Charset by CharsetMC.

the class Wire method updateConnections.

protected void updateConnections() {
    if (!connectionCheckDirty) {
        return;
    }
    Set<WireFace> validSides = EnumSet.noneOf(WireFace.class);
    Set<WireFace> invalidCornerSides = EnumSet.noneOf(WireFace.class);
    for (WireFace facing : WireFace.VALUES) {
        if (facing == location) {
            continue;
        }
        if (facing != WireFace.CENTER && location != WireFace.CENTER && location.facing.getAxis() == facing.facing.getAxis()) {
            continue;
        }
        validSides.add(facing);
    }
    int oldConnectionCache = getConnectionMask();
    internalConnections = externalConnections = cornerConnections = occludedSides = cornerOccludedSides = 0;
    // Occlusion test
    EnumFacing[] connFaces = WireUtils.getConnectionsForRender(location);
    for (int i = 0; i < connFaces.length; i++) {
        WireFace face = WireFace.get(connFaces[i]);
        if (validSides.contains(face)) {
            boolean found = false;
            AxisAlignedBB mask = factory.getBox(location, i + 1);
            if (mask != null) {
                if (OcclusionUtils.INSTANCE.intersects(Collections.singletonList(mask), container.world(), container.pos())) {
                    occludedSides |= 1 << connFaces[i].ordinal();
                    validSides.remove(face);
                    found = true;
                }
            }
        /*
                if (!found && location != WireFace.CENTER) {
                    BlockPos cPos = container.pos().offset(connFaces[i]);
                    AxisAlignedBB cornerMask = factory.getCornerBox(location, i ^ 1);
                    if (cornerMask != null) {
                        if (OcclusionUtils.PRIMARY.intersects(Collections.singletonList(cornerMask), container.world(), cPos)) {
                            cornerOccludedSides |= 1 << connFaces[i].ordinal();
                            invalidCornerSides.add(face);
                        }
                    }
                } */
        }
    }
    if (validSides.contains(WireFace.CENTER)) {
        AxisAlignedBB mask = factory.getBox(WireFace.CENTER, 1 + location.ordinal());
        if (mask != null) {
            if (OcclusionUtils.INSTANCE.intersects(Collections.singletonList(mask), container.world(), container.pos())) {
                occludedSides |= 1 << 6;
                validSides.remove(WireFace.CENTER);
            }
        }
    }
    // Connection test
    for (WireFace facing : validSides) {
        if (WireUtils.canConnectInternal(this, facing)) {
            internalConnections |= 1 << facing.ordinal();
        } else if (facing != WireFace.CENTER) {
            if (WireUtils.canConnectExternal(this, facing.facing)) {
                externalConnections |= 1 << facing.ordinal();
            } else if (location != WireFace.CENTER && !invalidCornerSides.contains(facing) && WireUtils.canConnectCorner(this, facing.facing)) {
                cornerConnections |= 1 << facing.ordinal();
            }
        }
    }
    int newConnectionCache = getConnectionMask();
    if (oldConnectionCache != newConnectionCache) {
        container.requestNeighborUpdate(oldConnectionCache ^ newConnectionCache);
        container.requestRenderUpdate();
    }
    connectionCheckDirty = false;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) EnumFacing(net.minecraft.util.EnumFacing) WireFace(pl.asie.charset.api.wires.WireFace)

Example 3 with WireFace

use of pl.asie.charset.api.wires.WireFace in project Charset by CharsetMC.

the class BlockWire method requestNeighborUpdate.

public void requestNeighborUpdate(World world, BlockPos pos, WireFace location, int connectionMask) {
    if ((connectionMask & 0xFF) != 0 && world instanceof IMultipartWorld) {
        IPartInfo info = ((IMultipartWorld) world).getPartInfo();
        info.getContainer().notifyChange(info);
    }
    for (EnumFacing facing : EnumFacing.VALUES) {
        if (world.isRemote) {
            if ((connectionMask & (1 << (facing.ordinal() + 8))) != 0) {
                WireUtils.getAllWires(world, pos.offset(facing)).forEach((wire) -> wire.onChanged(true));
            } else if (location != WireFace.CENTER && location.facing.getAxis() != facing.getAxis()) {
                WireUtils.getAllWires(world, pos.offset(facing).offset(location.facing)).forEach((wire) -> wire.onChanged(true));
            }
        } else {
            if ((connectionMask & (1 << (facing.ordinal() + 8))) != 0) {
                world.neighborChanged(pos.offset(facing), this, pos);
            } else if (location != WireFace.CENTER && location.facing.getAxis() != facing.getAxis()) {
                world.neighborChanged(pos.offset(facing).offset(location.facing), this, pos);
            }
        }
    }
}
Also used : IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) BlockStateContainer(net.minecraft.block.state.BlockStateContainer) IPartInfo(mcmultipart.api.container.IPartInfo) ExtendedBlockState(net.minecraftforge.common.property.ExtendedBlockState) BlockBase(pl.asie.charset.lib.block.BlockBase) IPartSlot(mcmultipart.api.slot.IPartSlot) ItemStack(net.minecraft.item.ItemStack) RayTraceResult(net.minecraft.util.math.RayTraceResult) IProperty(net.minecraft.block.properties.IProperty) Block(net.minecraft.block.Block) Vec3d(net.minecraft.util.math.Vec3d) Side(net.minecraftforge.fml.relauncher.Side) IMultipartWorld(mcmultipart.api.world.IMultipartWorld) IUnlistedProperty(net.minecraftforge.common.property.IUnlistedProperty) CreativeTabs(net.minecraft.creativetab.CreativeTabs) NonNullList(net.minecraft.util.NonNullList) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) EnumCenterSlot(mcmultipart.api.slot.EnumCenterSlot) IBlockAccess(net.minecraft.world.IBlockAccess) Nullable(javax.annotation.Nullable) SoundType(net.minecraft.block.SoundType) World(net.minecraft.world.World) PropertyBool(net.minecraft.block.properties.PropertyBool) EnumFacing(net.minecraft.util.EnumFacing) ITileEntityProvider(net.minecraft.block.ITileEntityProvider) BlockPos(net.minecraft.util.math.BlockPos) BlockRenderLayer(net.minecraft.util.BlockRenderLayer) IBlockState(net.minecraft.block.state.IBlockState) IMultipart(mcmultipart.api.multipart.IMultipart) List(java.util.List) Material(net.minecraft.block.material.Material) EntityLivingBase(net.minecraft.entity.EntityLivingBase) IMultipartBase(pl.asie.charset.lib.modcompat.mcmultipart.IMultipartBase) TileEntity(net.minecraft.tileentity.TileEntity) EnumFaceSlot(mcmultipart.api.slot.EnumFaceSlot) WireFace(pl.asie.charset.api.wires.WireFace) Collections(java.util.Collections) IPartInfo(mcmultipart.api.container.IPartInfo) EnumFacing(net.minecraft.util.EnumFacing) IMultipartWorld(mcmultipart.api.world.IMultipartWorld)

Example 4 with WireFace

use of pl.asie.charset.api.wires.WireFace in project Charset by CharsetMC.

the class BlockWire method getSlotForPlacement.

@Override
public IPartSlot getSlotForPlacement(World world, BlockPos pos, IBlockState state, EnumFacing facing, float hitX, float hitY, float hitZ, EntityLivingBase placer) {
    ItemStack stack = placer.getHeldItemMainhand();
    WireFace location = (stack.getMetadata() & 1) != 0 ? WireFace.CENTER : WireFace.get(facing.getOpposite());
    return WireUtils.toPartSlot(location);
}
Also used : ItemStack(net.minecraft.item.ItemStack) WireFace(pl.asie.charset.api.wires.WireFace)

Example 5 with WireFace

use of pl.asie.charset.api.wires.WireFace in project Charset by CharsetMC.

the class ItemWire method placeWirePartAt.

public boolean placeWirePartAt(ItemStack stack, EntityPlayer player, EnumHand hand, World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, IMultipart multipartBlock, IBlockState state) {
    WireProvider factory = WireManager.REGISTRY.getValue(stack.getMetadata() >> 1);
    WireFace location = (stack.getMetadata() & 1) != 0 ? WireFace.CENTER : WireFace.get(facing.getOpposite());
    if (!factory.canPlace(world, pos, location)) {
        return false;
    }
    return ItemBlockMultipart.placePartAt(stack, player, hand, world, pos, facing, hitX, hitY, hitZ, multipartBlock, state);
}
Also used : WireFace(pl.asie.charset.api.wires.WireFace)

Aggregations

WireFace (pl.asie.charset.api.wires.WireFace)11 EnumFacing (net.minecraft.util.EnumFacing)6 IMultipartContainer (mcmultipart.multipart.IMultipartContainer)4 IBlockState (net.minecraft.block.state.IBlockState)3 TileEntity (net.minecraft.tileentity.TileEntity)3 BlockPos (net.minecraft.util.BlockPos)3 Block (net.minecraft.block.Block)2 ItemStack (net.minecraft.item.ItemStack)2 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)2 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 Nullable (javax.annotation.Nullable)1 IPartInfo (mcmultipart.api.container.IPartInfo)1 IMultipart (mcmultipart.api.multipart.IMultipart)1 EnumCenterSlot (mcmultipart.api.slot.EnumCenterSlot)1 EnumFaceSlot (mcmultipart.api.slot.EnumFaceSlot)1 IPartSlot (mcmultipart.api.slot.IPartSlot)1 IMultipartWorld (mcmultipart.api.world.IMultipartWorld)1 IMultipart (mcmultipart.multipart.IMultipart)1