use of crazypants.enderio.base.conduit.RaytraceResult in project EnderIO by SleepyTrousers.
the class BlockConduitBundle method doRayTrace.
public RaytraceResult doRayTrace(@Nonnull World world, @Nonnull BlockPos pos, @Nonnull EntityPlayer entityPlayer) {
List<RaytraceResult> allHits = doRayTraceAll(world, pos, entityPlayer);
Vec3d origin = Util.getEyePosition(entityPlayer);
return RaytraceResult.getClosestHit(origin, allHits);
}
use of crazypants.enderio.base.conduit.RaytraceResult in project EnderIO by SleepyTrousers.
the class BlockConduitBundle method getSelectedBoundingBox.
@Override
@SideOnly(Side.CLIENT)
@Nonnull
public AxisAlignedBB getSelectedBoundingBox(@Nonnull IBlockState bs, @Nonnull World world, @Nonnull BlockPos pos) {
TileConduitBundle te = getTileEntity(world, pos);
EntityPlayer player = Minecraft.getMinecraft().player;
if (te == null) {
// FIXME is this valid?
return new AxisAlignedBB(0, 0, 0, 0, 0, 0);
}
IConduitBundle con = te;
BoundingBox minBB = null;
if (!YetaUtil.isSolidFacadeRendered(con, player)) {
List<RaytraceResult> results = doRayTraceAll(world, pos, player);
Iterator<RaytraceResult> iter = results.iterator();
while (iter.hasNext()) {
CollidableComponent component = iter.next().component;
if (component != null && component.conduitType == null && component.data != ConduitConnectorType.EXTERNAL) {
iter.remove();
}
}
// This is an ugly special case, TODO fix this
for (RaytraceResult hit : results) {
IRedstoneConduit cond = con.getConduit(IRedstoneConduit.class);
CollidableComponent component = hit.component;
EnumFacing dir = component == null ? null : component.dir;
if (cond != null && component != null && dir != null && cond.getExternalConnections().contains(dir) && component.data == InsulatedRedstoneConduit.COLOR_CONTROLLER_ID) {
minBB = component.bound;
}
}
if (minBB == null) {
RaytraceResult hit = RaytraceResult.getClosestHit(Util.getEyePosition(player), results);
CollidableComponent component = hit == null ? null : hit.component;
if (component != null) {
EnumFacing dir = component.dir;
minBB = component.bound;
if (dir != null && component.conduitType == null) {
dir = dir.getOpposite();
float trans = 0.0125f;
minBB = minBB.translate(dir.getFrontOffsetX() * trans, dir.getFrontOffsetY() * trans, dir.getFrontOffsetZ() * trans);
float scale = 0.7f;
minBB = minBB.scale(1 + Math.abs(dir.getFrontOffsetX()) * scale, 1 + Math.abs(dir.getFrontOffsetY()) * scale, 1 + Math.abs(dir.getFrontOffsetZ()) * scale);
} else {
minBB = minBB.scale(1.09, 1.09, 1.09);
}
}
}
} else {
minBB = new BoundingBox(0, 0, 0, 1, 1, 1);
}
if (minBB == null) {
minBB = new BoundingBox(0, 0, 0, 1, 1, 1);
}
return new AxisAlignedBB(pos.getX() + minBB.minX, pos.getY() + minBB.minY, pos.getZ() + minBB.minZ, pos.getX() + minBB.maxX, pos.getY() + minBB.maxY, pos.getZ() + minBB.maxZ);
}
use of crazypants.enderio.base.conduit.RaytraceResult in project EnderIO by SleepyTrousers.
the class BlockConduitBundle method handleConduitProbeClick.
private boolean handleConduitProbeClick(@Nonnull World world, @Nonnull BlockPos pos, @Nonnull EntityPlayer player, @Nonnull IConduitBundle bundle, @Nonnull ItemStack stack) {
if (stack.getItemDamage() != 1) {
// not in copy paste mode
return false;
}
RaytraceResult rr = doRayTrace(world, pos, player);
if (rr == null) {
return false;
}
CollidableComponent component = rr.component;
if (component == null) {
return false;
}
EnumFacing dir = component.dir;
if (dir == null) {
return false;
}
return ItemConduitProbe.copyPasteSettings(player, stack, bundle, dir);
}
use of crazypants.enderio.base.conduit.RaytraceResult in project EnderIO by SleepyTrousers.
the class InsulatedRedstoneConduit method onBlockActivated.
@Override
public boolean onBlockActivated(@Nonnull EntityPlayer player, @Nonnull EnumHand hand, @Nonnull RaytraceResult res, @Nonnull List<RaytraceResult> all) {
World world = getBundle().getEntity().getWorld();
if (!world.isRemote) {
DyeColor col = DyeColor.getColorFromDye(player.getHeldItem(hand));
if (col != null && res.component != null) {
setSignalColor(res.component.dir, col);
return true;
} else if (ToolUtil.isToolEquipped(player, hand)) {
if (res != null && res.component != null) {
EnumFacing connDir = res.component.dir;
EnumFacing faceHit = res.movingObjectPosition.sideHit;
boolean colorHit = false;
if (all != null && containsExternalConnection(connDir)) {
for (RaytraceResult rtr : all) {
if (rtr != null && rtr.component != null && COLOR_CONTROLLER_ID.equals(rtr.component.data)) {
colorHit = true;
}
}
}
if (colorHit) {
setSignalColor(connDir, DyeColor.getNext(getSignalColor(connDir)));
return true;
} else if (connDir == null || connDir == faceHit) {
BlockPos pos = getBundle().getLocation().offset(faceHit);
Block id = world.getBlockState(pos).getBlock();
if (id == ConduitRegistry.getConduitModObjectNN().getBlock()) {
IRedstoneConduit neighbour = ConduitUtil.getConduit(world, pos.getX(), pos.getY(), pos.getZ(), IRedstoneConduit.class);
if (neighbour != null && neighbour.getConnectionMode(faceHit.getOpposite()) == ConnectionMode.DISABLED) {
neighbour.setConnectionMode(faceHit.getOpposite(), ConnectionMode.NOT_SET);
}
setConnectionMode(faceHit, ConnectionMode.NOT_SET);
return ConduitUtil.connectConduits(this, faceHit);
}
forceConnectionMode(faceHit, ConnectionMode.IN_OUT);
return true;
} else if (externalConnections.contains(connDir)) {
if (network != null) {
network.destroyNetwork();
}
externalConnectionRemoved(connDir);
forceConnectionMode(connDir, ConnectionMode.DISABLED);
return true;
} else if (containsConduitConnection(connDir)) {
BlockPos pos = getBundle().getLocation().offset(connDir);
IRedstoneConduit neighbour = ConduitUtil.getConduit(getBundle().getEntity().getWorld(), pos.getX(), pos.getY(), pos.getZ(), IRedstoneConduit.class);
if (neighbour != null) {
if (network != null) {
network.destroyNetwork();
}
if (neighbour.getNetwork() != null) {
neighbour.getNetwork().destroyNetwork();
}
neighbour.conduitConnectionRemoved(connDir.getOpposite());
conduitConnectionRemoved(connDir);
neighbour.connectionsChanged();
connectionsChanged();
updateNetwork();
neighbour.updateNetwork();
return true;
}
}
}
}
}
return false;
}
use of crazypants.enderio.base.conduit.RaytraceResult in project EnderIO by SleepyTrousers.
the class BlockConduitBundle method doRayTraceAll.
@Nonnull
protected NNList<RaytraceResult> doRayTraceAll(@Nonnull IBlockState bs, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Vec3d origin, @Nonnull Vec3d direction, EntityPlayer player) {
TileEntity te = world.getTileEntity(pos);
if (!(te instanceof IConduitBundle)) {
return NNList.emptyList();
}
IConduitBundle bundle = (IConduitBundle) te;
NNList<RaytraceResult> hits = new NNList<RaytraceResult>();
if (YetaUtil.isSolidFacadeRendered(bundle, player)) {
setBlockBounds(0, 0, 0, 1, 1, 1);
RayTraceResult hitPos = super.collisionRayTrace(bs, world, pos, origin, direction);
if (hitPos != null) {
hits.add(new RaytraceResult(new CollidableComponent(null, BoundingBox.UNIT_CUBE, hitPos.sideHit, null), hitPos));
}
} else {
ConduitDisplayMode mode = YetaUtil.getDisplayMode(player);
for (CollidableComponent component : new ArrayList<CollidableComponent>(bundle.getCollidableComponents())) {
if (mode.isAll() || component.conduitType == null || YetaUtil.renderConduit(player, component.conduitType)) {
setBlockBounds(component.bound.minX, component.bound.minY, component.bound.minZ, component.bound.maxX, component.bound.maxY, component.bound.maxZ);
RayTraceResult hitPos = super.collisionRayTrace(bs, world, pos, origin, direction);
if (hitPos != null) {
hits.add(new RaytraceResult(component, hitPos));
}
}
}
// safety to prevent unbreakable empty bundles in case of a bug
if (bundle.getConduits().isEmpty() && !YetaUtil.isFacadeHidden(bundle, player)) {
setBlockBounds(0, 0, 0, 1, 1, 1);
RayTraceResult hitPos = super.collisionRayTrace(bs, world, pos, origin, direction);
if (hitPos != null) {
hits.add(new RaytraceResult(null, hitPos));
}
}
}
setBlockBounds(0, 0, 0, 1, 1, 1);
return hits;
}
Aggregations