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();
}
}
}
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;
}
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;
}
}
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;
}
}
Aggregations