Search in sources :

Example 51 with NNList

use of com.enderio.core.common.util.NNList 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 52 with NNList

use of com.enderio.core.common.util.NNList 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)

Example 53 with NNList

use of com.enderio.core.common.util.NNList in project EnderIO by SleepyTrousers.

the class ContainerWiredCharger method addGhostslots.

public void addGhostslots(NNList<GhostSlot> ghostSlots) {
    NNList<ItemStack> empties = new NNList<>();
    NNList<ItemStack> fulls = new NNList<>();
    getValidPair(ItemHelper.getValidItems()).apply(new Callback<Triple<ItemStack, ItemStack, Integer>>() {

        @Override
        public void apply(@Nonnull Triple<ItemStack, ItemStack, Integer> e) {
            empties.add(e.getLeft());
            fulls.add(e.getMiddle());
        }
    });
    // JEI will cause initGui to be re-run after closing the recipe view, causing duplicate ghost
    ghostSlots.removeAllByClass(GhostBackgroundItemSlot.class);
    // slots
    final GhostBackgroundItemSlot ghost0 = new GhostBackgroundItemSlot(empties, getSlotFromInventory(0));
    ghost0.setDisplayStdOverlay(true);
    ghostSlots.add(ghost0);
    final GhostBackgroundItemSlot ghost1 = new GhostBackgroundItemSlot(fulls, getSlotFromInventory(1));
    ghost1.setDisplayStdOverlay(true);
    ghostSlots.add(ghost1);
}
Also used : Triple(org.apache.commons.lang3.tuple.Triple) GhostBackgroundItemSlot(com.enderio.core.client.gui.widget.GhostBackgroundItemSlot) NNList(com.enderio.core.common.util.NNList) ItemStack(net.minecraft.item.ItemStack)

Aggregations

NNList (com.enderio.core.common.util.NNList)53 ItemStack (net.minecraft.item.ItemStack)37 Nonnull (javax.annotation.Nonnull)12 BlockPos (net.minecraft.util.math.BlockPos)8 EntityItem (net.minecraft.entity.item.EntityItem)7 MachineRecipeInput (crazypants.enderio.base.recipe.MachineRecipeInput)5 Block (net.minecraft.block.Block)5 IBlockState (net.minecraft.block.state.IBlockState)5 IHarvestResult (crazypants.enderio.api.farm.IHarvestResult)4 ArrayList (java.util.ArrayList)4 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)4 GhostBackgroundItemSlot (com.enderio.core.client.gui.widget.GhostBackgroundItemSlot)3 Recipe (crazypants.enderio.base.recipe.Recipe)3 RecipeOutput (crazypants.enderio.base.recipe.RecipeOutput)3 ThingsRecipeInput (crazypants.enderio.base.recipe.ThingsRecipeInput)3 World (net.minecraft.world.World)3 Triple (org.apache.commons.lang3.tuple.Triple)3 IConduitBundle (crazypants.enderio.base.conduit.IConduitBundle)2 RaytraceResult (crazypants.enderio.base.conduit.RaytraceResult)2 IMachineRecipe (crazypants.enderio.base.recipe.IMachineRecipe)2