Search in sources :

Example 11 with IConduitBundle

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;
}
Also used : IPowerInterface(crazypants.enderio.base.power.IPowerInterface) IConduitBundle(crazypants.enderio.base.conduit.IConduitBundle) IoMode(crazypants.enderio.base.machine.modes.IoMode) Nonnull(javax.annotation.Nonnull)

Example 12 with IConduitBundle

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);
            }
        }
    }
}
Also used : IConduitBundle(crazypants.enderio.base.conduit.IConduitBundle) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 13 with IConduitBundle

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;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ConduitDisplayMode(crazypants.enderio.base.conduit.ConduitDisplayMode) CollidableComponent(crazypants.enderio.base.conduit.geom.CollidableComponent) NNList(com.enderio.core.common.util.NNList) RayTraceResult(net.minecraft.util.math.RayTraceResult) ArrayList(java.util.ArrayList) IConduitBundle(crazypants.enderio.base.conduit.IConduitBundle) RaytraceResult(crazypants.enderio.base.conduit.RaytraceResult) Nonnull(javax.annotation.Nonnull)

Example 14 with IConduitBundle

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;
}
Also used : Nonnull(javax.annotation.Nonnull) CollidableComponent(crazypants.enderio.base.conduit.geom.CollidableComponent) ConduitConnectorType(crazypants.enderio.base.conduit.geom.ConduitConnectorType) IConduitBundle(crazypants.enderio.base.conduit.IConduitBundle) IConduit(crazypants.enderio.base.conduit.IConduit) ItemStack(net.minecraft.item.ItemStack) RaytraceResult(crazypants.enderio.base.conduit.RaytraceResult)

Example 15 with IConduitBundle

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;
}
Also used : NNList(com.enderio.core.common.util.NNList) IConduitBundle(crazypants.enderio.base.conduit.IConduitBundle) ItemStack(net.minecraft.item.ItemStack) RaytraceResult(crazypants.enderio.base.conduit.RaytraceResult)

Aggregations

IConduitBundle (crazypants.enderio.base.conduit.IConduitBundle)17 Nonnull (javax.annotation.Nonnull)8 TileEntity (net.minecraft.tileentity.TileEntity)7 ItemStack (net.minecraft.item.ItemStack)6 RaytraceResult (crazypants.enderio.base.conduit.RaytraceResult)4 CollidableComponent (crazypants.enderio.base.conduit.geom.CollidableComponent)4 BlockPos (net.minecraft.util.math.BlockPos)4 ArrayList (java.util.ArrayList)3 World (net.minecraft.world.World)3 NNList (com.enderio.core.common.util.NNList)2 IConduit (crazypants.enderio.base.conduit.IConduit)2 IServerConduit (crazypants.enderio.base.conduit.IServerConduit)2 BoundingBox (com.enderio.core.client.render.BoundingBox)1 ConduitDisplayMode (crazypants.enderio.base.conduit.ConduitDisplayMode)1 IClientConduit (crazypants.enderio.base.conduit.IClientConduit)1 IConduitRenderer (crazypants.enderio.base.conduit.IConduitRenderer)1 ConduitConnectorType (crazypants.enderio.base.conduit.geom.ConduitConnectorType)1 IoMode (crazypants.enderio.base.machine.modes.IoMode)1 IPowerInterface (crazypants.enderio.base.power.IPowerInterface)1 TileConduitBundle (crazypants.enderio.conduits.conduit.TileConduitBundle)1