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;
}
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]);
}
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;
}
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()]);
}
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();
}
}
Aggregations