Search in sources :

Example 11 with IMultipartContainer

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

the class RedstoneUtils method canConnectFace.

public static boolean canConnectFace(IBlockAccess world, BlockPos pos, IBlockState state, EnumFacing side, EnumFacing face) {
    Block block = state.getBlock();
    if ((block instanceof BlockRedstoneDiode || block instanceof BlockRedstoneWire || block instanceof BlockDaylightDetector || block instanceof BlockBasePressurePlate) && face != EnumFacing.DOWN) {
        return false;
    }
    if (block instanceof BlockLever && face != state.getValue(BlockLever.FACING).getFacing().getOpposite()) {
        return false;
    }
    if (block instanceof BlockButton && face != state.getValue(BlockButton.FACING).getOpposite()) {
        return false;
    }
    IMultipartContainer container = MultipartHelper.getPartContainer(world, pos);
    if (container != null) {
        return MultipartRedstoneHelper.canConnectRedstone(container, side, face);
    } else {
        return block.canConnectRedstone(world, pos, side);
    }
}
Also used : BlockBasePressurePlate(net.minecraft.block.BlockBasePressurePlate) BlockDaylightDetector(net.minecraft.block.BlockDaylightDetector) BlockLever(net.minecraft.block.BlockLever) BlockRedstoneDiode(net.minecraft.block.BlockRedstoneDiode) IMultipartContainer(mcmultipart.multipart.IMultipartContainer) Block(net.minecraft.block.Block) BlockButton(net.minecraft.block.BlockButton) BlockRedstoneWire(net.minecraft.block.BlockRedstoneWire)

Example 12 with IMultipartContainer

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

the class PacketPart method readData.

@Override
public void readData(ByteBuf buf) {
    int dim = buf.readInt();
    int x = buf.readInt();
    int y = buf.readUnsignedShort();
    int z = buf.readInt();
    long l1 = buf.readLong();
    long l2 = buf.readLong();
    UUID id = new UUID(l1, l2);
    World w = ModCharsetLib.proxy.getLocalWorld(dim);
    if (w != null) {
        IMultipartContainer container = MultipartHelper.getPartContainer(w, new BlockPos(x, y, z));
        if (container != null) {
            part = container.getPartFromID(id);
        }
    }
}
Also used : IMultipartContainer(mcmultipart.multipart.IMultipartContainer) BlockPos(net.minecraft.util.BlockPos) UUID(java.util.UUID) World(net.minecraft.world.World)

Example 13 with IMultipartContainer

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

the class PartGate method updateInputs.

private boolean updateInputs() {
    byte[] oldOutput = new byte[4];
    boolean changed = false;
    for (int i = 0; i <= 3; i++) {
        Connection conn = getType(side);
        if (conn.isOutput() && conn.isRedstone()) {
            oldOutput[i] = getOutputOutside(side);
        }
    }
    for (int i = 0; i <= 3; i++) {
        EnumFacing side = EnumFacing.getFront(i + 2);
        Connection conn = getType(side);
        if (conn.isInput() && conn.isRedstone()) {
            byte oi = inputs[i];
            inputs[i] = 0;
            EnumFacing real = gateToReal(side);
            World w = getWorld();
            BlockPos p = getPos().offset(real);
            IMultipartContainer container = MultipartHelper.getPartContainer(w, p);
            if (container != null) {
                inputs[i] = (byte) MultipartRedstoneHelper.getWeakSignal(container, real.getOpposite(), this.side);
            } else {
                TileEntity tile = w.getTileEntity(p);
                if (tile != null && tile.hasCapability(Capabilities.REDSTONE_EMITTER, real.getOpposite())) {
                    inputs[i] = (byte) tile.getCapability(Capabilities.REDSTONE_EMITTER, real.getOpposite()).getRedstoneSignal();
                } else {
                    IBlockState s = w.getBlockState(p);
                    if (RedstoneUtils.canConnectFace(w, p, s, real, this.side)) {
                        if (s.getBlock() instanceof BlockRedstoneWire) {
                            inputs[i] = s.getValue(BlockRedstoneWire.POWER).byteValue();
                        } else {
                            inputs[i] = (byte) s.getBlock().getWeakPower(w, p, s, real);
                        }
                    }
                }
            }
            if (conn.isDigital()) {
                inputs[i] = inputs[i] != 0 ? (byte) 15 : 0;
            }
            if (inputs[i] != oi) {
                changed = true;
            }
        }
    }
    if (!changed) {
        for (int i = 0; i <= 3; i++) {
            Connection conn = getType(side);
            if (conn.isOutput() && conn.isRedstone()) {
                if (getOutputOutside(side) != oldOutput[i]) {
                    changed = true;
                    break;
                }
            }
        }
    }
    return changed;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IBlockState(net.minecraft.block.state.IBlockState) IMultipartContainer(mcmultipart.multipart.IMultipartContainer) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.BlockPos) World(net.minecraft.world.World) BlockRedstoneWire(net.minecraft.block.BlockRedstoneWire)

Example 14 with IMultipartContainer

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

the class MultipartUtils method getInterface.

public static <T> T getInterface(Class<T> clazz, World world, BlockPos pos, EnumFacing side) {
    IMultipartContainer container = MultipartHelper.getPartContainer(world, pos);
    if (container == null) {
        TileEntity tile = world.getTileEntity(pos);
        return tile != null && clazz.isAssignableFrom(tile.getClass()) ? (T) tile : null;
    } else {
        if (side == null) {
            return getInterfaceCenter(clazz, container);
        }
        EnumFacing[] var2 = EnumFacing.VALUES;
        int var3 = var2.length;
        for (int var4 = 0; var4 < var3; ++var4) {
            EnumFacing face = var2[var4];
            if (face != side && face != side.getOpposite()) {
                T tmp = getInterface(clazz, container, side, face);
                if (tmp != null) {
                    return tmp;
                }
            }
        }
        return null;
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IMultipartContainer(mcmultipart.multipart.IMultipartContainer) EnumFacing(net.minecraft.util.EnumFacing)

Aggregations

IMultipartContainer (mcmultipart.multipart.IMultipartContainer)14 BlockPos (net.minecraft.util.BlockPos)7 EnumFacing (net.minecraft.util.EnumFacing)6 Block (net.minecraft.block.Block)4 BlockRedstoneWire (net.minecraft.block.BlockRedstoneWire)4 IBlockState (net.minecraft.block.state.IBlockState)4 TileEntity (net.minecraft.tileentity.TileEntity)4 WireFace (pl.asie.charset.api.wires.WireFace)4 PartWireBase (pl.asie.charset.wires.logic.PartWireBase)4 IMultipart (mcmultipart.multipart.IMultipart)3 ArrayList (java.util.ArrayList)2 World (net.minecraft.world.World)2 UUID (java.util.UUID)1 IMicroblock (mcmultipart.microblock.IMicroblock)1 IOccludingPart (mcmultipart.multipart.IOccludingPart)1 IRedstonePart (mcmultipart.multipart.IRedstonePart)1 ISlottedPart (mcmultipart.multipart.ISlottedPart)1 BlockBasePressurePlate (net.minecraft.block.BlockBasePressurePlate)1 BlockButton (net.minecraft.block.BlockButton)1 BlockDaylightDetector (net.minecraft.block.BlockDaylightDetector)1