use of mcmultipart.api.container.IPartInfo in project Charset by CharsetMC.
the class WireHighlightHandler method drawWireHighlight.
@SubscribeEvent
public void drawWireHighlight(DrawBlockHighlightEvent event) {
if (event.getTarget() != null && event.getTarget().typeOfHit == RayTraceResult.Type.BLOCK) {
Wire wire;
BlockPos pos = event.getTarget().getBlockPos();
if (event.getTarget().hitInfo instanceof IPartInfo) {
wire = WireUtils.getAnyWire(((IPartInfo) event.getTarget().hitInfo).getTile().getTileEntity());
} else {
wire = WireUtils.getAnyWire(event.getPlayer().getEntityWorld(), pos);
}
if (wire != null) {
event.setCanceled(true);
int lineMaskCenter = 0xFFF;
EnumFacing[] faces = WireUtils.getConnectionsForRender(wire.getLocation());
GlStateManager.pushMatrix();
GlStateManager.translate(pos.getX(), pos.getY(), pos.getZ());
for (int i = 0; i < faces.length; i++) {
EnumFacing face = faces[i];
if (wire.connectsAny(face)) {
int lineMask = 0xfff;
lineMask &= ~RenderUtils.getSelectionMask(face.getOpposite());
RenderUtils.drawSelectionBoundingBox(wire.getFactory().getSelectionBox(wire.getLocation(), i + 1), lineMask);
lineMaskCenter &= ~RenderUtils.getSelectionMask(face);
}
}
if (lineMaskCenter != 0) {
RenderUtils.drawSelectionBoundingBox(wire.getFactory().getSelectionBox(wire.getLocation(), 0), lineMaskCenter);
}
GlStateManager.popMatrix();
}
}
}
use of mcmultipart.api.container.IPartInfo 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);
}
}
}
}
use of mcmultipart.api.container.IPartInfo in project LogisticsPipes by RS485.
the class LPMicroblockBlock method addHitEffects.
@Override
@SideOnly(Side.CLIENT)
@ModDependentMethod(modId = LPConstants.mcmpModID)
public boolean addHitEffects(IBlockState mpState, World world, RayTraceResult hit, ParticleManager manager) {
if (hit != null && hit.subHit >= 0) {
BlockPos pos = hit.getBlockPos();
IPartInfo part = getTile(world, pos).get().get(MCMultiPart.slotRegistry.getValue(hit.subHit)).get();
if (!part.getPart().addHitEffects(part, (RayTraceResult) hit.hitInfo, manager)) {
if (part.getPart().getRenderType(part) != EnumBlockRenderType.INVISIBLE) {
int x = pos.getX(), y = pos.getY(), z = pos.getZ();
AxisAlignedBB aabb = part.getPart().getBoundingBox(part);
double pX = x + world.rand.nextDouble() * (aabb.maxX - aabb.minX - 0.2) + 0.1 + aabb.minX;
double pY = y + world.rand.nextDouble() * (aabb.maxY - aabb.minY - 0.2) + 0.1 + aabb.minY;
double pZ = z + world.rand.nextDouble() * (aabb.maxZ - aabb.minZ - 0.2) + 0.1 + aabb.minZ;
switch(hit.sideHit) {
case DOWN:
pY = y + aabb.minY - 0.1;
break;
case UP:
pY = y + aabb.maxY + 0.1;
break;
case NORTH:
pZ = z + aabb.minZ - 0.1;
break;
case SOUTH:
pZ = z + aabb.maxZ + 0.1;
break;
case WEST:
pX = x + aabb.minX - 0.1;
break;
case EAST:
pX = x + aabb.maxX + 0.1;
break;
}
manager.addEffect(new ParticleDigging(world, pX, pY, pZ, 0.0D, 0.0D, 0.0D, part.getPart().getActualState(part.getPartWorld(), pos, part)) {
}.setBlockPos(pos).multiplyVelocity(0.2F).multipleParticleScaleBy(0.6F));
}
}
return true;
}
return false;
}
use of mcmultipart.api.container.IPartInfo 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.IPartInfo 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