Search in sources :

Example 16 with NNList

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

the class Recipe method getInputStackAlternatives.

@Override
@Nonnull
public NNList<List<ItemStack>> getInputStackAlternatives() {
    NNList<List<ItemStack>> res = new NNList<>();
    for (int i = 0; i < inputs.length; i++) {
        IRecipeInput in = inputs[i];
        if (in != null && !in.isFluid()) {
            final int slotNumber = in.getSlotNumber() >= 0 ? in.getSlotNumber() : i;
            while (res.size() <= slotNumber) {
                res.add(new NNList<>());
            }
            ItemStack[] equivelentInputs = in.getEquivelentInputs();
            if (equivelentInputs != null && equivelentInputs.length != 0) {
                ((NNList<ItemStack>) res.get(slotNumber)).addAll(equivelentInputs);
            } else {
                ItemStack input = in.getInput();
                if (Prep.isValid(input)) {
                    ((NNList<ItemStack>) res.get(slotNumber)).add(input);
                }
            }
        }
    }
    return res;
}
Also used : NNList(com.enderio.core.common.util.NNList) List(java.util.List) NNList(com.enderio.core.common.util.NNList) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) Nonnull(javax.annotation.Nonnull)

Example 17 with NNList

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

the class AbstractMachineRecipe method getCompletedResult.

@Override
@Nonnull
public ResultStack[] getCompletedResult(long nextSeed, float chanceMultiplier, @Nonnull NNList<MachineRecipeInput> inputs) {
    if (inputs.size() <= 0) {
        return new ResultStack[0];
    }
    IRecipe recipe = getRecipeForInputs(inputs);
    if (recipe == null) {
        return new ResultStack[0];
    }
    RecipeOutput[] outputs = recipe.getOutputs();
    if (outputs.length == 0) {
        return new ResultStack[0];
    }
    NNList<ResultStack> result = new NNList<ResultStack>();
    Random rand = new Random(nextSeed);
    for (RecipeOutput output : outputs) {
        if (output.isFluid()) {
            FluidStack fluidOutput = output.getFluidOutput();
            if (fluidOutput != null && (rand.nextFloat() < output.getChance() * chanceMultiplier)) {
                result.add(new ResultStack(fluidOutput = fluidOutput.copy()));
            }
        } else {
            ItemStack stack = output.getOutput().copy();
            int stackSize = 0;
            for (int i = 0; i < stack.getCount(); i++) {
                if (rand.nextFloat() < output.getChance() * chanceMultiplier) {
                    stackSize++;
                }
            }
            stack.setCount(stackSize);
            if (Prep.isValid(stack)) {
                result.add(new ResultStack(stack));
            }
        }
    }
    return result.toArray(new ResultStack[0]);
}
Also used : Random(java.util.Random) FluidStack(net.minecraftforge.fluids.FluidStack) NNList(com.enderio.core.common.util.NNList) ItemStack(net.minecraft.item.ItemStack) Nonnull(javax.annotation.Nonnull)

Example 18 with NNList

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

the class TileSoulBinder method isMachineItemValidForSlot.

@Override
public boolean isMachineItemValidForSlot(int slot, @Nonnull ItemStack item) {
    if (!slotDefinition.isInputSlot(slot)) {
        return false;
    }
    MachineRecipeInput newInput = new MachineRecipeInput(slot, item);
    int otherSlot = slot == 0 ? 1 : 0;
    if (Prep.isInvalid(getStackInSlot(otherSlot))) {
        List<IMachineRecipe> recipes = MachineRecipeRegistry.instance.getRecipesForInput(getMachineName(), newInput);
        if (recipes.isEmpty()) {
            return false;
        }
        for (IMachineRecipe rec : recipes) {
            if (rec != null && rec.isValidInput(newInput)) {
                return true;
            }
        }
    } else {
        NNList<MachineRecipeInput> inputs = new NNList<>(newInput, new MachineRecipeInput(otherSlot, getStackInSlot(otherSlot)));
        return MachineRecipeRegistry.instance.getRecipeForInputs(getMachineName(), inputs) != null;
    }
    return false;
}
Also used : NNList(com.enderio.core.common.util.NNList) MachineRecipeInput(crazypants.enderio.base.recipe.MachineRecipeInput) IMachineRecipe(crazypants.enderio.base.recipe.IMachineRecipe)

Example 19 with NNList

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

the class SolarPanelNetwork method getConduitProbeData.

@Nonnull
@Override
public String[] getConduitProbeData(@Nonnull EntityPlayer player, @Nullable EnumFacing side) {
    NNList<String> result = new NNList<>();
    @Nonnull final String text = String.format(" Energy was last accessed %d ticks ago", EnderIO.proxy.getServerTickCount() - lastTick);
    result.add(String.format("%d panels producing %d µI/t now and %d µI/t peak", panels.size(), getEnergyAvailablePerTick(), getEnergyMaxPerTick()));
    result.add(text);
    for (BlockPos panel : panels) {
        if (TileSolarPanel.canSeeSun(world, panel)) {
            result.add(String.format(" Panel at %s cannot see the sun!", BlockCoord.chatString(panel, TextFormatting.RESET)));
        }
    }
    if (result.size() == 2) {
        result.add(String.format(" All panels can see the sun!"));
    }
    return result.toArray(new String[result.size()]);
}
Also used : Nonnull(javax.annotation.Nonnull) NNList(com.enderio.core.common.util.NNList) BlockPos(net.minecraft.util.math.BlockPos) Nonnull(javax.annotation.Nonnull)

Example 20 with NNList

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

the class SolarPanelNetwork method cleanupMemberlist.

void cleanupMemberlist() {
    if (!panels.isEmpty()) {
        Iterator<BlockPos> iterator = panels.iterator();
        Set<BlockPos> candidates = new HashSet<BlockPos>();
        while (iterator.hasNext()) {
            BlockPos panel = iterator.next();
            if (panel != null && world.isBlockLoaded(panel)) {
                TileEntity tileEntity = world.getTileEntity(panel);
                if (tileEntity instanceof TileSolarPanel && !tileEntity.isInvalid() && tileEntity.hasWorld()) {
                    if (((TileSolarPanel) tileEntity).network == this) {
                        for (NNIterator<EnumFacing> facings = NNList.FACING_HORIZONTAL.fastIterator(); facings.hasNext(); ) {
                            final BlockPos neighbor = panel.offset(facings.next());
                            if (!panels.contains(neighbor) && world.isBlockLoaded(neighbor)) {
                                candidates.add(neighbor);
                            }
                        }
                        continue;
                    }
                }
            }
            iterator.remove();
        }
        while (!candidates.isEmpty()) {
            NNList<BlockPos> candidateList = new NNList<BlockPos>(candidates);
            for (NNIterator<BlockPos> candidateItr = candidateList.iterator(); candidateItr.hasNext(); ) {
                BlockPos candidate = candidateItr.next();
                if (!panels.contains(candidate) && canConnect(candidate)) {
                    TileEntity tileEntity = world.getTileEntity(candidate);
                    if (tileEntity instanceof TileSolarPanel && !tileEntity.isInvalid() && tileEntity.hasWorld()) {
                        panels.add(candidate.toImmutable());
                        final ISolarPanelNetwork otherNetwork = ((TileSolarPanel) tileEntity).network;
                        if (otherNetwork != this) {
                            ((TileSolarPanel) tileEntity).setNetwork(this);
                            for (BlockPos other : otherNetwork.getPanels()) {
                                if (other != null && !panels.contains(other) && world.isBlockLoaded(other)) {
                                    candidates.add(other);
                                }
                            }
                            otherNetwork.destroyNetwork();
                            for (NNIterator<EnumFacing> facings = NNList.FACING_HORIZONTAL.fastIterator(); facings.hasNext(); ) {
                                final BlockPos neighbor = candidate.offset(facings.next());
                                if (!panels.contains(neighbor) && world.isBlockLoaded(neighbor)) {
                                    candidates.add(neighbor);
                                }
                            }
                        }
                    }
                }
                candidates.remove(candidate);
            }
        }
    }
    if (panels.isEmpty()) {
        destroyNetwork();
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) EnumFacing(net.minecraft.util.EnumFacing) NNList(com.enderio.core.common.util.NNList) BlockPos(net.minecraft.util.math.BlockPos) HashSet(java.util.HashSet)

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