Search in sources :

Example 6 with RaytraceResult

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;
}
Also used : RayTraceResult(net.minecraft.util.math.RayTraceResult) RaytraceResult(crazypants.enderio.base.conduit.RaytraceResult)

Example 7 with RaytraceResult

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;
}
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 8 with RaytraceResult

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;
}
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

RaytraceResult (crazypants.enderio.base.conduit.RaytraceResult)8 IConduitBundle (crazypants.enderio.base.conduit.IConduitBundle)4 CollidableComponent (crazypants.enderio.base.conduit.geom.CollidableComponent)4 Nonnull (javax.annotation.Nonnull)3 EnumFacing (net.minecraft.util.EnumFacing)3 NNList (com.enderio.core.common.util.NNList)2 ItemStack (net.minecraft.item.ItemStack)2 RayTraceResult (net.minecraft.util.math.RayTraceResult)2 BoundingBox (com.enderio.core.client.render.BoundingBox)1 DyeColor (com.enderio.core.common.util.DyeColor)1 ConduitDisplayMode (crazypants.enderio.base.conduit.ConduitDisplayMode)1 IConduit (crazypants.enderio.base.conduit.IConduit)1 ConduitConnectorType (crazypants.enderio.base.conduit.geom.ConduitConnectorType)1 IRedstoneConduit (crazypants.enderio.conduits.conduit.redstone.IRedstoneConduit)1 ArrayList (java.util.ArrayList)1 Block (net.minecraft.block.Block)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 TileEntity (net.minecraft.tileentity.TileEntity)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 BlockPos (net.minecraft.util.math.BlockPos)1