Search in sources :

Example 1 with IMultipartContainer

use of mcmultipart.api.container.IMultipartContainer in project Charset by CharsetMC.

the class WireUtils method getAllWires.

public static Collection<Wire> getAllWires(IBlockAccess access, BlockPos pos) {
    Optional<IMultipartContainer> containerOpt = MultipartHelper.getContainer(access, pos);
    if (containerOpt.isPresent()) {
        IMultipartContainer container = containerOpt.get();
        Collection<Wire> wires = new ArrayList<>();
        for (IPartInfo partInfo : container.getParts().values()) {
            if (partInfo.getTile() instanceof TileWire) {
                wires.add(((TileWire) partInfo.getTile()).wire);
            }
        }
        return wires;
    } else {
        TileEntity tile = access.getTileEntity(pos);
        if (tile instanceof TileWire) {
            return Collections.singleton(((TileWire) tile).wire);
        } else {
            return Collections.emptySet();
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IMultipartContainer(mcmultipart.api.container.IMultipartContainer) IPartInfo(mcmultipart.api.container.IPartInfo) ArrayList(java.util.ArrayList)

Example 2 with IMultipartContainer

use of mcmultipart.api.container.IMultipartContainer in project Charset by CharsetMC.

the class WireUtils method hasCapability.

public static boolean hasCapability(Wire wire, BlockPos pos, Capability<?> capability, EnumFacing face, boolean ignoreWires) {
    TileWire.isWireCheckingForCaps = ignoreWires;
    if (wire.getLocation() != WireFace.CENTER) {
        Optional<IMultipartContainer> container = MultipartHelper.getContainer(wire.getContainer().world(), pos);
        if (container.isPresent()) {
            boolean result = MultipartCapabilityHelper.hasCapability(container.get(), capability, EnumEdgeSlot.fromFaces(wire.getLocation().facing, face), face);
            TileWire.isWireCheckingForCaps = false;
            return result;
        }
    }
    TileEntity tile = wire.getContainer().world().getTileEntity(pos);
    boolean result = tile != null && tile.hasCapability(capability, face);
    TileWire.isWireCheckingForCaps = false;
    return result;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IMultipartContainer(mcmultipart.api.container.IMultipartContainer)

Example 3 with IMultipartContainer

use of mcmultipart.api.container.IMultipartContainer in project Charset by CharsetMC.

the class WireUtils method getWire.

@Nullable
public static Wire getWire(IBlockAccess access, BlockPos pos, WireFace face) {
    IMultipartContainer container = null;
    if (access instanceof IMultipartBlockAccess) {
        access = ((IMultipartBlockAccess) access).getActualWorld();
    }
    Optional<IMultipartContainer> containerOpt = MultipartHelper.getContainer(access, pos);
    if (containerOpt.isPresent()) {
        container = containerOpt.get();
    }
    if (container != null) {
        Optional<IMultipartTile> tile = container.getPartTile(toPartSlot(face));
        if (tile.isPresent() && tile.get().getTileEntity() instanceof TileWire) {
            Wire wire = ((TileWire) tile.get().getTileEntity()).wire;
            if (wire != null && wire.getLocation() == face) {
                return ((TileWire) tile.get().getTileEntity()).wire;
            }
        }
        return null;
    }
    TileEntity tile = access.getTileEntity(pos);
    if (tile != null && tile instanceof TileWire && ((TileWire) tile).wire != null && ((TileWire) tile).wire.getLocation() == face) {
        return ((TileWire) tile).wire;
    } else {
        return null;
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IMultipartContainer(mcmultipart.api.container.IMultipartContainer) IMultipartBlockAccess(mcmultipart.api.world.IMultipartBlockAccess) IMultipartTile(mcmultipart.api.multipart.IMultipartTile) Nullable(javax.annotation.Nullable)

Example 4 with IMultipartContainer

use of mcmultipart.api.container.IMultipartContainer in project Charset by CharsetMC.

the class ItemWrench method tryRotateMultipart.

@net.minecraftforge.fml.common.Optional.Method(modid = "mcmultipart")
public EnumActionResult tryRotateMultipart(EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing targetFacing) {
    Optional<IMultipartContainer> uio = MultipartHelper.getContainer(worldIn, pos);
    if (uio.isPresent()) {
        IMultipartContainer ui = uio.get();
        Vec3d start = RayTraceUtils.getStart(playerIn);
        Vec3d end = RayTraceUtils.getEnd(playerIn);
        double dist = Double.POSITIVE_INFINITY;
        IPartInfo part = null;
        for (IPartInfo p : ui.getParts().values()) {
            RayTraceResult pResult = p.getPart().collisionRayTrace(p, start, end);
            if (pResult != null && pResult.hitVec != null) {
                double d = pResult.hitVec.squareDistanceTo(start);
                if (d <= dist) {
                    dist = d;
                    part = p;
                }
            }
        }
        if (part != null) {
            // TODO return ... ? EnumActionResult.SUCCESS : EnumActionResult.FAIL;
            return EnumActionResult.FAIL;
        } else {
            return EnumActionResult.FAIL;
        }
    } else {
        return EnumActionResult.PASS;
    }
}
Also used : IMultipartContainer(mcmultipart.api.container.IMultipartContainer) IPartInfo(mcmultipart.api.container.IPartInfo) RayTraceResult(net.minecraft.util.math.RayTraceResult) Vec3d(net.minecraft.util.math.Vec3d)

Aggregations

IMultipartContainer (mcmultipart.api.container.IMultipartContainer)4 TileEntity (net.minecraft.tileentity.TileEntity)3 IPartInfo (mcmultipart.api.container.IPartInfo)2 ArrayList (java.util.ArrayList)1 Nullable (javax.annotation.Nullable)1 IMultipartTile (mcmultipart.api.multipart.IMultipartTile)1 IMultipartBlockAccess (mcmultipart.api.world.IMultipartBlockAccess)1 RayTraceResult (net.minecraft.util.math.RayTraceResult)1 Vec3d (net.minecraft.util.math.Vec3d)1