Search in sources :

Example 1 with IMultipart

use of mcmultipart.multipart.IMultipart in project Charset by CharsetMC.

the class CharsetHelperImpl method getInterfaceList.

@Override
public <T> List<T> getInterfaceList(Class<T> clazz, World world, BlockPos pos) {
    IMultipartContainer container = MultipartHelper.getPartContainer(world, pos);
    List<T> list = new ArrayList<T>();
    if (container == null) {
        TileEntity tile = world.getTileEntity(pos);
        if (tile != null && clazz.isAssignableFrom(tile.getClass())) {
            list.add((T) tile);
        }
    } else {
        for (IMultipart part : container.getParts()) {
            if (clazz.isAssignableFrom(part.getClass())) {
                list.add((T) part);
            }
        }
    }
    return list;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IMultipartContainer(mcmultipart.multipart.IMultipartContainer) ArrayList(java.util.ArrayList) IMultipart(mcmultipart.multipart.IMultipart)

Example 2 with IMultipart

use of mcmultipart.multipart.IMultipart in project Charset by CharsetMC.

the class WireUtils method getRedstoneLevel.

public static int getRedstoneLevel(World world, BlockPos pos, IBlockState state, EnumFacing facing, WireFace face, boolean weak) {
    int power = 0;
    IMultipartContainer container = MultipartHelper.getPartContainer(world, pos);
    if (container != null) {
        if (getWire(container, face) != null || getWire(container, WireFace.get(facing.getOpposite())) != null) {
            return 0;
        }
        for (IMultipart part : container.getParts()) {
            if (!(part instanceof PartWireBase)) {
                if (part instanceof IRedstonePart) {
                    power = Math.max(power, ((IRedstonePart) part).getWeakSignal(facing.getOpposite()));
                }
            }
        }
    }
    if (MultipartUtils.hasCapability(Capabilities.REDSTONE_EMITTER, world, pos, WireUtils.getSlotForFace(face), facing)) {
        power = Math.max(power, MultipartUtils.getCapability(Capabilities.REDSTONE_EMITTER, world, pos, WireUtils.getSlotForFace(face), facing).getRedstoneSignal());
    }
    Block block = state.getBlock();
    if (power == 0) {
        if (weak) {
            if (block instanceof BlockRedstoneWire && face == WireFace.DOWN) {
                return state.getValue(BlockRedstoneWire.POWER);
            }
            return block.shouldCheckWeakPower(world, pos, facing) ? block.getStrongPower(world, pos, state, facing) : block.getWeakPower(world, pos, state, facing);
        } else {
            return block.getStrongPower(world, pos, state, facing);
        }
    } else {
        return power;
    }
}
Also used : IRedstonePart(mcmultipart.multipart.IRedstonePart) PartWireBase(pl.asie.charset.wires.logic.PartWireBase) IMultipartContainer(mcmultipart.multipart.IMultipartContainer) Block(net.minecraft.block.Block) IMultipart(mcmultipart.multipart.IMultipart) BlockRedstoneWire(net.minecraft.block.BlockRedstoneWire)

Example 3 with IMultipart

use of mcmultipart.multipart.IMultipart in project Charset by CharsetMC.

the class MultipartUtils method getInterfaceCenter.

public static <T> T getInterfaceCenter(Class<T> clazz, IMultipartContainer container) {
    ISlottedPart part = container.getPartInSlot(PartSlot.CENTER);
    if (part != null && clazz.isAssignableFrom(part.getClass())) {
        return (T) part;
    } else {
        Iterator var4 = container.getParts().iterator();
        IMultipart p;
        do {
            do {
                if (!var4.hasNext()) {
                    return null;
                }
                p = (IMultipart) var4.next();
            } while (p instanceof ISlottedPart && !((ISlottedPart) p).getSlotMask().isEmpty());
        } while (p == null || !clazz.isAssignableFrom(p.getClass()));
        return (T) p;
    }
}
Also used : Iterator(java.util.Iterator) IMultipart(mcmultipart.multipart.IMultipart) ISlottedPart(mcmultipart.multipart.ISlottedPart)

Example 4 with IMultipart

use of mcmultipart.multipart.IMultipart in project Charset by CharsetMC.

the class PartWireBase method updateConnections.

public void updateConnections() {
    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 = internalConnections << 12 | externalConnections << 6 | cornerConnections;
    internalConnections = externalConnections = cornerConnections = occludedSides = cornerOccludedSides = 0;
    // Occlusion test
    EnumFacing[] connFaces = WireUtils.getConnectionsForRender(location);
    List<IMultipart> parts = new ArrayList<IMultipart>();
    for (IMultipart p : getContainer().getParts()) {
        if (p != this && p instanceof IOccludingPart && !(p instanceof PartWireBase)) {
            parts.add(p);
        }
    }
    if (parts.size() > 0) {
        for (int i = 0; i < connFaces.length; i++) {
            WireFace face = WireFace.get(connFaces[i]);
            if (validSides.contains(face)) {
                boolean found = false;
                AxisAlignedBB mask = getBox(i + 1);
                if (mask != null) {
                    if (!OcclusionHelper.occlusionTest(parts, this, mask)) {
                        occludedSides |= 1 << connFaces[i].ordinal();
                        validSides.remove(face);
                        found = true;
                    }
                }
                if (!found && location != WireFace.CENTER) {
                    BlockPos cPos = getPos().offset(connFaces[i]);
                    AxisAlignedBB cornerMask = getCornerBox(i ^ 1);
                    if (cornerMask != null) {
                        IMultipartContainer cornerContainer = MultipartHelper.getPartContainer(getWorld(), cPos);
                        if (cornerContainer != null) {
                            if (!OcclusionHelper.occlusionTest(cornerContainer.getParts(), cornerMask)) {
                                cornerOccludedSides |= 1 << connFaces[i].ordinal();
                                invalidCornerSides.add(face);
                            }
                        } else {
                            List<AxisAlignedBB> boxes = new ArrayList<AxisAlignedBB>();
                            IBlockState cState = getWorld().getBlockState(cPos);
                            cState.getBlock().addCollisionBoxesToList(getWorld(), cPos, cState, cornerMask.offset(cPos.getX(), cPos.getY(), cPos.getZ()), boxes, null);
                            if (boxes.size() > 0) {
                                cornerOccludedSides |= 1 << connFaces[i].ordinal();
                                invalidCornerSides.add(face);
                            }
                        }
                    }
                }
            }
        }
    }
    if (validSides.contains(WireFace.CENTER)) {
        AxisAlignedBB mask = getCenterBox(1 + location.ordinal());
        if (mask != null) {
            if (!OcclusionHelper.occlusionTest(parts, this, mask)) {
                occludedSides |= 1 << 6;
                validSides.remove(WireFace.CENTER);
            }
        }
    }
    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 = internalConnections << 12 | externalConnections << 6 | cornerConnections;
    if (oldConnectionCache != newConnectionCache) {
        scheduleNeighborUpdate((oldConnectionCache ^ newConnectionCache) >> 6);
        schedulePropagationUpdate();
        scheduleRenderUpdate();
    }
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) IBlockState(net.minecraft.block.state.IBlockState) IMultipartContainer(mcmultipart.multipart.IMultipartContainer) EnumFacing(net.minecraft.util.EnumFacing) ArrayList(java.util.ArrayList) WireFace(pl.asie.charset.api.wires.WireFace) BlockPos(net.minecraft.util.BlockPos) IMultipart(mcmultipart.multipart.IMultipart) IOccludingPart(mcmultipart.multipart.IOccludingPart)

Example 5 with IMultipart

use of mcmultipart.multipart.IMultipart in project Charset by CharsetMC.

the class PartWireBase method pokeExtendedNeighbors.

private void pokeExtendedNeighbors() {
    if (getContainer() != null) {
        for (IMultipart multipart : getContainer().getParts()) {
            if (multipart instanceof PartWireBase) {
                multipart.onNeighborBlockChange(MCMultiPartMod.multipart);
            }
        }
    }
    World world = this.getWorld();
    BlockPos pos = this.getPos();
    if (world != null) {
        world.notifyNeighborsRespectDebug(pos, MCMultiPartMod.multipart);
        for (EnumFacing facing : EnumFacing.VALUES) {
            world.notifyNeighborsOfStateExcept(pos.offset(facing), MCMultiPartMod.multipart, facing.getOpposite());
        }
    }
}
Also used : EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.BlockPos) IMultipart(mcmultipart.multipart.IMultipart) World(net.minecraft.world.World)

Aggregations

IMultipart (mcmultipart.multipart.IMultipart)5 IMultipartContainer (mcmultipart.multipart.IMultipartContainer)3 ArrayList (java.util.ArrayList)2 BlockPos (net.minecraft.util.BlockPos)2 EnumFacing (net.minecraft.util.EnumFacing)2 Iterator (java.util.Iterator)1 IOccludingPart (mcmultipart.multipart.IOccludingPart)1 IRedstonePart (mcmultipart.multipart.IRedstonePart)1 ISlottedPart (mcmultipart.multipart.ISlottedPart)1 Block (net.minecraft.block.Block)1 BlockRedstoneWire (net.minecraft.block.BlockRedstoneWire)1 IBlockState (net.minecraft.block.state.IBlockState)1 TileEntity (net.minecraft.tileentity.TileEntity)1 AxisAlignedBB (net.minecraft.util.AxisAlignedBB)1 World (net.minecraft.world.World)1 WireFace (pl.asie.charset.api.wires.WireFace)1 PartWireBase (pl.asie.charset.wires.logic.PartWireBase)1