use of crazypants.enderio.base.conduit.IConduitBundle in project EnderIO by SleepyTrousers.
the class TileCapBank method toggleIoModeForFace.
// ---------- IO
@Override
@Nonnull
public IoMode toggleIoModeForFace(@Nullable EnumFacing faceHit) {
if (faceHit == null) {
return IoMode.NONE;
}
IPowerInterface rec = getReceptorForFace(faceHit);
IoMode curMode = getIoMode(faceHit);
if (curMode == IoMode.PULL) {
setIoMode(faceHit, IoMode.PUSH, true);
return IoMode.PUSH;
}
if (curMode == IoMode.PUSH) {
setIoMode(faceHit, IoMode.DISABLED, true);
return IoMode.DISABLED;
}
if (curMode == IoMode.DISABLED) {
if (rec == null || rec.getProvider() instanceof IConduitBundle) {
setIoMode(faceHit, IoMode.NONE, true);
return IoMode.NONE;
}
}
setIoMode(faceHit, IoMode.PULL, true);
return IoMode.PULL;
}
use of crazypants.enderio.base.conduit.IConduitBundle in project EnderIO by SleepyTrousers.
the class ConduitBreakSpeedHandler method onBreakSpeed.
@SubscribeEvent
public static void onBreakSpeed(BreakSpeed event) {
if (event.getState().getBlock() == ConduitObject.block_conduit_bundle.getBlockNN()) {
ItemStack held = event.getEntityPlayer().getHeldItemMainhand();
if (held.getItem().getHarvestLevel(held, "pickaxe", event.getEntityPlayer(), event.getState()) == -1) {
event.setNewSpeed(event.getNewSpeed() + 2);
}
IConduitBundle te = (IConduitBundle) event.getEntity().world.getTileEntity(NullHelper.notnullF(event.getPos(), "BreakSpeed#getPos"));
if (te != null && te.getFacadeType().isHardened()) {
if (!YetaUtil.isSolidFacadeRendered(te, event.getEntityPlayer())) {
event.setNewSpeed(event.getNewSpeed() * 6);
} else {
event.setNewSpeed(event.getNewSpeed() * 2);
}
}
}
}
use of crazypants.enderio.base.conduit.IConduitBundle 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;
}
use of crazypants.enderio.base.conduit.IConduitBundle 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.IConduitBundle 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