use of crazypants.enderio.base.conduit.RaytraceResult in project EnderIO by SleepyTrousers.
the class BlockConduitBundle method collisionRayTrace.
@SuppressWarnings("null")
@Override
public RayTraceResult collisionRayTrace(@Nonnull IBlockState state, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Vec3d origin, @Nonnull Vec3d direction) {
RaytraceResult raytraceResult = doRayTrace(world, pos, origin, direction, null);
RayTraceResult ret = null;
if (raytraceResult != null) {
ret = raytraceResult.movingObjectPosition;
// FIXME No it's not!!
ret.hitInfo = raytraceResult.component;
}
return ret;
}
use of crazypants.enderio.base.conduit.RaytraceResult in project EnderIO by SleepyTrousers.
the class BlockConduitBundle method onBlockActivated.
@Override
public boolean onBlockActivated(@Nonnull World world, @Nonnull BlockPos pos, @Nonnull IBlockState state, @Nonnull EntityPlayer player, @Nonnull EnumHand hand, @Nonnull EnumFacing side, float hitX, float hitY, float hitZ) {
IConduitBundle bundle = getTileEntity(world, pos);
if (bundle == null) {
return false;
}
ItemStack stack = player.getHeldItem(hand);
// }
if (stack.getItem() == ModObject.itemConduitFacade.getItem()) {
// add or replace facade
return handleFacadeClick(world, pos, player, side, bundle, stack, hand, hitX, hitY, hitZ);
} else if (ConduitUtil.isConduitEquipped(player, hand)) {
// Add conduit
if (player.isSneaking()) {
return false;
}
if (handleConduitClick(world, pos, player, bundle, stack, hand)) {
return true;
}
} else if (ConduitUtil.isProbeEquipped(player, hand)) {
// Handle copy / paste of settings
if (handleConduitProbeClick(world, pos, player, bundle, stack)) {
return true;
}
} else if (ToolUtil.isToolEquipped(player, hand) && player.isSneaking()) {
// Break conduit with tool
if (handleWrenchClick(world, pos, player, hand)) {
return true;
}
}
// Check conduit defined actions
RaytraceResult closest = doRayTrace(world, pos, player);
@Nonnull List<RaytraceResult> all = NullHelper.notnullJ(Collections.emptyList(), "Collections#emptyList");
if (closest != null) {
all = doRayTraceAll(world, pos, player);
}
final CollidableComponent closestComponent = closest == null ? null : closest.component;
if (closestComponent != null && closestComponent.data instanceof ConduitConnectorType) {
ConduitConnectorType conType = (ConduitConnectorType) closestComponent.data;
if (conType == ConduitConnectorType.INTERNAL) {
boolean result = false;
// if its a connector pass the event on to all conduits
for (IConduit con : bundle.getConduits()) {
RaytraceResult res = getHitForConduitType(all, con.getCollidableType());
if (res != null && YetaUtil.renderConduit(player, con.getCollidableType()) && con.onBlockActivated(player, hand, res, all)) {
bundle.getEntity().markDirty();
result = true;
}
}
if (result) {
return true;
}
} else {
if (!world.isRemote) {
openGui(world, pos, player, closestComponent.dir, closestComponent.dir.ordinal());
}
return true;
}
}
if (closestComponent == null || closestComponent.conduitType == null && all.isEmpty()) {
// Nothing of interest hit
return false;
}
// Conduit specific actions
if (all.isEmpty()) {
RaytraceResult.sort(Util.getEyePosition(player), all);
for (RaytraceResult rr : all) {
final CollidableComponent component = rr.component;
if (component != null && YetaUtil.renderConduit(player, component.conduitType) && !(component.data instanceof ConduitConnectorType)) {
IConduit con = bundle.getConduit(component.conduitType);
if (con != null && con.onBlockActivated(player, hand, rr, all)) {
bundle.getEntity().markDirty();
return true;
}
}
}
} else {
IConduit closestConduit = bundle.getConduit(closestComponent.conduitType);
if (closest != null && closestConduit != null && YetaUtil.renderConduit(player, closestConduit) && closestConduit.onBlockActivated(player, hand, closest, all)) {
bundle.getEntity().markDirty();
return true;
}
}
return false;
}
use of crazypants.enderio.base.conduit.RaytraceResult in project EnderIO by SleepyTrousers.
the class BlockConduitBundle method removedByPlayer.
@Override
public boolean removedByPlayer(@Nonnull IBlockState bs, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull EntityPlayer player, boolean willHarvest) {
IConduitBundle te = (IConduitBundle) world.getTileEntity(pos);
if (te == null) {
return true;
}
boolean breakBlock = true;
NNList<ItemStack> drop = new NNList<>();
if (YetaUtil.isSolidFacadeRendered(te, player)) {
breakBlock = false;
ItemStack fac = new ItemStack(ModObject.itemConduitFacade.getItemNN(), 1, EnumFacadeType.getMetaFromType(te.getFacadeType()));
PaintUtil.setSourceBlock(fac, te.getPaintSource());
drop.add(fac);
ConduitUtil.playBreakSound(te.getPaintSourceNN().getBlock().getSoundType(), world, pos);
te.setPaintSource(null);
te.setFacadeType(EnumFacadeType.BASIC);
}
if (breakBlock) {
List<RaytraceResult> results = doRayTraceAll(world, pos, player);
RaytraceResult.sort(Util.getEyePosition(player), results);
for (RaytraceResult rt : results) {
if (breakConduit(te, drop, rt, player)) {
break;
}
}
}
breakBlock = te.getConduits().isEmpty() && !te.hasFacade();
if (!breakBlock) {
world.notifyBlockUpdate(pos, bs, bs, 3);
}
if (!world.isRemote && !player.capabilities.isCreativeMode) {
for (ItemStack st : drop) {
Util.dropItems(world, NullHelper.notnullM(st, "NNList#iterator.next()"), pos, false);
}
}
if (breakBlock) {
world.setBlockToAir(pos);
return true;
}
return false;
}
Aggregations