Skip to content

Commit

Permalink
Merge pull request #3229 from refinedmods/develop
Browse files Browse the repository at this point in the history
v1.10.0
  • Loading branch information
raoulvdberge authored Jan 25, 2022
2 parents 01dabbe + ff4b8c3 commit 0a5ae5b
Show file tree
Hide file tree
Showing 17 changed files with 110 additions and 64 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG-old.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
- Fixed Wireless Transmitter only working upright (Darkere)
- Fixed Portable Grid not opening when pointing at a block (Darkere)
- Fixed being able to circumvent locked slots by scrolling (Darkere)
- Processing patterns now use the order of items/fluids specified in the pattern (Darkere, necauqua)
- Fixed multiple bugs related to transferring recipes into the crafting grid (Darkere)
- Fixed autocrafting task getting stuck if two tasks fulfilled each others requirements (Darkere)
- Fixed fluid autocrafting breaking when using 2 stacks of the same fluid in a pattern (Darkere)
- Amount specifying screen is now limited to valid values (Darkere)

### 1.9.16

Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

### Fixed

- Fixed multiple bugs related to transferring recipes into the Crafting Grid.
- Processing patterns now use the order of items/fluids specified in the pattern
by [@necauqua](https://github.com/necauqua) and [@Darkere](https://github.com/Darkere).
- Fixed autocrafting task getting stuck if two tasks fulfilled each others requirements.
- Fixed fluid autocrafting breaking when using 2 stacks of the same fluid in a pattern.
- Amount specifying screen is now limited to valid values.
- Fixed crash on servers when starting with latest Forge.

## [v1.10.0-beta.4] - 2021-12-28

### Fixed

- Fixed client crash when hovering over a fluid in the Fluid Grid by [@jackodsteel](https://github.com/jackodsteel).
- Fixed random client crashes when starting the game.

Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ apply plugin: 'maven-publish'

group = 'com.refinedmods'
archivesBaseName = 'refinedstorage'
version = '1.10.0-beta.4'
version = '1.10.0'

if (System.getenv('GITHUB_SHA') != null) {
version += '+' + System.getenv('GITHUB_SHA').substring(0, 7)
Expand Down Expand Up @@ -102,7 +102,7 @@ processResources {
}

dependencies {
minecraft 'net.minecraftforge:forge:1.18.1-39.0.0'
minecraft 'net.minecraftforge:forge:1.18.1-39.0.59'

compileOnly fg.deobf("mezz.jei:jei-1.18.1:9.1.0.41:api")
runtimeOnly fg.deobf("mezz.jei:jei-1.18.1:9.1.0.41")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.refinedmods.refinedstorage.api.autocrafting;

import com.refinedmods.refinedstorage.api.util.Action;
import com.refinedmods.refinedstorage.api.util.StackListEntry;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.network.chat.Component;
Expand Down Expand Up @@ -152,7 +151,7 @@ default boolean hasConnectedFluidInventory() {
* @param action action to perform
* @return whether insertion was successful
*/
default boolean insertItemsIntoInventory(Collection<StackListEntry<ItemStack>> toInsert, Action action) {
default boolean insertItemsIntoInventory(Collection<ItemStack> toInsert, Action action) {
IItemHandler dest = getConnectedInventory();


Expand All @@ -164,11 +163,10 @@ default boolean insertItemsIntoInventory(Collection<StackListEntry<ItemStack>> t
return false;
}

Deque<StackListEntry<ItemStack>> stacks = new ArrayDeque<>(toInsert);
Deque<ItemStack> stacks = new ArrayDeque<>(toInsert);

StackListEntry<ItemStack> currentEntry = stacks.poll();

ItemStack current = currentEntry != null ? currentEntry.getStack() : null;
ItemStack current = stacks.poll();

List<Integer> availableSlots = IntStream.range(0, dest.getSlots()).boxed().collect(Collectors.toList());

Expand All @@ -189,9 +187,8 @@ default boolean insertItemsIntoInventory(Collection<StackListEntry<ItemStack>> t
}

if (remainder.isEmpty()) { // If we inserted successfully, get a next stack.
currentEntry = stacks.poll();
current = stacks.poll();

current = currentEntry != null ? currentEntry.getStack() : null;
} else if (current.getCount() == remainder.getCount()) { // If we didn't insert anything over ALL these slots, stop here.
break;
} else { // If we didn't insert all, continue with other slots and use our remainder.
Expand All @@ -215,7 +212,7 @@ default boolean insertItemsIntoInventory(Collection<StackListEntry<ItemStack>> t
* @param action action to perform
* @return whether insertion was successful
*/
default boolean insertFluidsIntoInventory(Collection<StackListEntry<FluidStack>> toInsert, Action action) {
default boolean insertFluidsIntoInventory(Collection<FluidStack> toInsert, Action action) {
IFluidHandler dest = getConnectedFluidInventory();

if (toInsert.isEmpty()) {
Expand All @@ -226,12 +223,12 @@ default boolean insertFluidsIntoInventory(Collection<StackListEntry<FluidStack>>
return false;
}

for (StackListEntry<FluidStack> entry : toInsert) {
int filled = dest.fill(entry.getStack(), action == Action.SIMULATE ? IFluidHandler.FluidAction.SIMULATE : IFluidHandler.FluidAction.EXECUTE);
for (FluidStack stack : toInsert) {
int filled = dest.fill(stack, action == Action.SIMULATE ? IFluidHandler.FluidAction.SIMULATE : IFluidHandler.FluidAction.EXECUTE);

if (filled != entry.getStack().getAmount()) {
if (filled != stack.getAmount()) {
if (action == Action.PERFORM) {
LogManager.getLogger().warn("Inventory unexpectedly didn't accept all of {}, the remainder has been voided!", entry.getStack().getTranslationKey());
LogManager.getLogger().warn("Inventory unexpectedly didn't accept all of {}, the remainder has been voided!", stack.getTranslationKey());
}

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.refinedmods.refinedstorage.api.util.IComparer;
import com.refinedmods.refinedstorage.api.util.IStackList;
import com.refinedmods.refinedstorage.api.util.StackListEntry;
import com.refinedmods.refinedstorage.apiimpl.API;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;

Expand All @@ -19,15 +18,15 @@ public final class IoUtil {
private IoUtil() {
}

public static IStackList<ItemStack> extractFromInternalItemStorage(IStackList<ItemStack> list, IStorageDisk<ItemStack> storage, Action action) {
IStackList<ItemStack> extracted = API.instance().createItemStackList();
public static List<ItemStack> extractFromInternalItemStorage(List<ItemStack> list, IStorageDisk<ItemStack> storage, Action action) {
List<ItemStack> extracted = new ArrayList<>();

for (StackListEntry<ItemStack> entry : list.getStacks()) {
ItemStack result = storage.extract(entry.getStack(), entry.getStack().getCount(), DEFAULT_EXTRACT_FLAGS, action);
for (ItemStack stack : list) {
ItemStack result = storage.extract(stack, stack.getCount(), DEFAULT_EXTRACT_FLAGS, action);

if (result.isEmpty() || result.getCount() != entry.getStack().getCount()) {
if (result.isEmpty() || result.getCount() != stack.getCount()) {
if (action == Action.PERFORM) {
throw new IllegalStateException("The internal crafting inventory reported that " + entry.getStack() + " was available but we got " + result);
throw new IllegalStateException("The internal crafting inventory reported that " + stack + " was available but we got " + result);
}

return null;
Expand All @@ -39,15 +38,15 @@ public static IStackList<ItemStack> extractFromInternalItemStorage(IStackList<It
return extracted;
}

public static IStackList<FluidStack> extractFromInternalFluidStorage(IStackList<FluidStack> list, IStorageDisk<FluidStack> storage, Action action) {
IStackList<FluidStack> extracted = API.instance().createFluidStackList();
public static List<FluidStack> extractFromInternalFluidStorage(List<FluidStack> list, IStorageDisk<FluidStack> storage, Action action) {
List<FluidStack> extracted = new ArrayList<>();

for (StackListEntry<FluidStack> entry : list.getStacks()) {
FluidStack result = storage.extract(entry.getStack(), entry.getStack().getAmount(), DEFAULT_EXTRACT_FLAGS, action);
for (FluidStack stack : list) {
FluidStack result = storage.extract(stack, stack.getAmount(), DEFAULT_EXTRACT_FLAGS, action);

if (result.isEmpty() || result.getAmount() != entry.getStack().getAmount()) {
if (result.isEmpty() || result.getAmount() != stack.getAmount()) {
if (action == Action.PERFORM) {
throw new IllegalStateException("The internal crafting inventory reported that " + entry.getStack() + " was available but we got " + result);
throw new IllegalStateException("The internal crafting inventory reported that " + stack + " was available but we got " + result);
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ private void calculateForFluids(int qty,
FluidStack fromSelf = fluidResults.get(possibleInput, IComparer.COMPARE_NBT);
FluidStack fromNetwork = fluidStorageSource.get(possibleInput, IComparer.COMPARE_NBT);

int remaining = possibleInput.getAmount() * qty;
int remaining = ingredient.getCount() * qty;

if (remaining < 0) { // int overflow
throw new CraftingCalculatorException(CalculationResultType.TOO_COMPLEX);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@
import net.minecraft.nbt.Tag;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.items.ItemHandlerHelper;

import javax.annotation.Nullable;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.*;

public class NodeRequirements {
private static final String NBT_ITEMS_TO_USE = "ItemsToUse";
Expand All @@ -32,9 +30,9 @@ public class NodeRequirements {
private final Map<Integer, Integer> fluidsNeededPerCraft = new LinkedHashMap<>();

@Nullable
private IStackList<ItemStack> cachedSimulatedItemRequirementSet = null;
private List<ItemStack> cachedSimulatedItemRequirementSet = null;
@Nullable
private IStackList<FluidStack> cachedSimulatedFluidRequirementSet = null;
private List<FluidStack> cachedSimulatedFluidRequirementSet = null;

public void addItemRequirement(int ingredientNumber, ItemStack stack, int size, int perCraft) {
if (!itemsNeededPerCraft.containsKey(ingredientNumber)) {
Expand All @@ -56,13 +54,13 @@ public void addFluidRequirement(int ingredientNumber, FluidStack stack, int size
cachedSimulatedFluidRequirementSet = null;
}

public IStackList<ItemStack> getSingleItemRequirementSet(boolean simulate) {
IStackList<ItemStack> cached = cachedSimulatedItemRequirementSet;
public List<ItemStack> getSingleItemRequirementSet(boolean simulate) {
List<ItemStack> cached = cachedSimulatedItemRequirementSet;
if (simulate && cached != null) {
return cached;
}

IStackList<ItemStack> toReturn = API.instance().createItemStackList();
List<ItemStack> toReturn = new ArrayList<>();

for (int i = 0; i < itemRequirements.size(); i++) {
int needed = itemsNeededPerCraft.get(i);
Expand All @@ -78,7 +76,7 @@ public IStackList<ItemStack> getSingleItemRequirementSet(boolean simulate) {
itemRequirements.get(i).remove(toUse, needed);
}

toReturn.add(toUse, needed);
toReturn.add(ItemHandlerHelper.copyStackWithSize(toUse, needed));

needed = 0;
} else {
Expand All @@ -101,13 +99,13 @@ public IStackList<ItemStack> getSingleItemRequirementSet(boolean simulate) {
return toReturn;
}

public IStackList<FluidStack> getSingleFluidRequirementSet(boolean simulate) {
IStackList<FluidStack> cached = cachedSimulatedFluidRequirementSet;
public List<FluidStack> getSingleFluidRequirementSet(boolean simulate) {
List<FluidStack> cached = cachedSimulatedFluidRequirementSet;
if (simulate && cached != null) {
return cached;
}

IStackList<FluidStack> toReturn = API.instance().createFluidStackList();
List<FluidStack> toReturn = new ArrayList<>();

for (int i = 0; i < fluidRequirements.size(); i++) {
int needed = fluidsNeededPerCraft.get(i);
Expand All @@ -123,7 +121,9 @@ public IStackList<FluidStack> getSingleFluidRequirementSet(boolean simulate) {
fluidRequirements.get(i).remove(toUse, needed);
}

toReturn.add(toUse, needed);
FluidStack stack = toUse.copy();
stack.setAmount(needed);
toReturn.add(stack);

needed = 0;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@
import com.refinedmods.refinedstorage.apiimpl.API;
import com.refinedmods.refinedstorage.apiimpl.autocrafting.task.v6.IoUtil;
import com.refinedmods.refinedstorage.apiimpl.autocrafting.task.v6.SerializationUtil;
import com.refinedmods.refinedstorage.apiimpl.util.FluidStackList;
import com.refinedmods.refinedstorage.apiimpl.util.ItemStackList;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.Tag;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;

import java.util.List;

public class ProcessingNode extends Node {
private static final String NBT_ITEMS_RECEIVED = "ItemsReceived";
private static final String NBT_FLUIDS_RECEIVED = "FluidsReceived";
Expand Down Expand Up @@ -69,7 +73,7 @@ private void initSetsToReceive() {
@Override
public void update(INetwork network, int ticks, NodeList nodes, IStorageDisk<ItemStack> internalStorage, IStorageDisk<FluidStack> internalFluidStorage, NodeListener listener) {
if (getQuantity() <= 0) {
if (state == ProcessingState.PROCESSED) {
if (totalQuantity == quantityFinished) {
listener.onAllDone(this);
}
return;
Expand Down Expand Up @@ -117,8 +121,8 @@ public void update(INetwork network, int ticks, NodeList nodes, IStorageDisk<Ite

boolean hasAllRequirements = false;

IStackList<ItemStack> extractedItems = IoUtil.extractFromInternalItemStorage(requirements.getSingleItemRequirementSet(true), internalStorage, Action.SIMULATE);
IStackList<FluidStack> extractedFluids = null;
List<ItemStack> extractedItems = IoUtil.extractFromInternalItemStorage(requirements.getSingleItemRequirementSet(true), internalStorage, Action.SIMULATE);
List<FluidStack> extractedFluids = null;
if (extractedItems != null) {
extractedFluids = IoUtil.extractFromInternalFluidStorage(requirements.getSingleFluidRequirementSet(true), internalFluidStorage, Action.SIMULATE);
if (extractedFluids != null) {
Expand All @@ -128,9 +132,9 @@ public void update(INetwork network, int ticks, NodeList nodes, IStorageDisk<Ite

boolean canInsertFullAmount = false;
if (hasAllRequirements) {
canInsertFullAmount = container.insertItemsIntoInventory(extractedItems.getStacks(), Action.SIMULATE);
canInsertFullAmount = container.insertItemsIntoInventory(extractedItems, Action.SIMULATE);
if (canInsertFullAmount) {
canInsertFullAmount = container.insertFluidsIntoInventory(extractedFluids.getStacks(), Action.SIMULATE);
canInsertFullAmount = container.insertFluidsIntoInventory(extractedFluids, Action.SIMULATE);
}
} else {
break;
Expand All @@ -151,8 +155,8 @@ public void update(INetwork network, int ticks, NodeList nodes, IStorageDisk<Ite
extractedItems = IoUtil.extractFromInternalItemStorage(requirements.getSingleItemRequirementSet(false), internalStorage, Action.PERFORM);
extractedFluids = IoUtil.extractFromInternalFluidStorage(requirements.getSingleFluidRequirementSet(false), internalFluidStorage, Action.PERFORM);

container.insertItemsIntoInventory(extractedItems.getStacks(), Action.PERFORM);
container.insertFluidsIntoInventory(extractedFluids.getStacks(), Action.PERFORM);
container.insertItemsIntoInventory(extractedItems, Action.PERFORM);
container.insertFluidsIntoInventory(extractedFluids, Action.PERFORM);

next();

Expand Down Expand Up @@ -239,18 +243,14 @@ public void updateFinishedQuantity() {
}

this.quantityFinished = tempQuantityFinished;

if (this.quantityFinished == this.totalQuantity) {
this.state = ProcessingState.PROCESSED;
}
}

@Override
public void onCalculationFinished() {
super.onCalculationFinished();

this.singleItemSetToRequire = requirements.getSingleItemRequirementSet(true);
this.singleFluidSetToRequire = requirements.getSingleFluidRequirementSet(true);
this.singleItemSetToRequire = new ItemStackList(requirements.getSingleItemRequirementSet(true));
this.singleFluidSetToRequire = new FluidStackList(requirements.getSingleFluidRequirementSet(true));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public void onRecipeTransfer(INetworkAwareGrid grid, Player player, ItemStack[][
// If we are connected, first try to get the possibilities from the network
if (network != null && grid.isGridActive()) {
for (ItemStack possibility : possibilities) {
ItemStack took = network.extractItem(possibility, 1, IComparer.COMPARE_NBT, Action.PERFORM);
ItemStack took = network.extractItem(possibility, possibility.getCount(), IComparer.COMPARE_NBT, Action.PERFORM);

if (!took.isEmpty()) {
grid.getCraftingMatrix().setItem(i, took);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ public class FluidStackList implements IStackList<FluidStack> {
private final ArrayListMultimap<Fluid, StackListEntry<FluidStack>> stacks = ArrayListMultimap.create();
private final Map<UUID, FluidStack> index = new HashMap<>();

public FluidStackList() {
}

public FluidStackList(Iterable<FluidStack> stacks) {
for (FluidStack stack : stacks) {
add(stack);
}
}

@Override
public StackListResult<FluidStack> add(@Nonnull FluidStack stack, int size) {
if (stack.isEmpty() || size <= 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ public class ItemStackList implements IStackList<ItemStack> {
private final ArrayListMultimap<Item, StackListEntry<ItemStack>> stacks = ArrayListMultimap.create();
private final Map<UUID, ItemStack> index = new HashMap<>();

public ItemStackList() {
}

public ItemStackList(Iterable<ItemStack> stacks) {
for (ItemStack stack : stacks) {
add(stack);
}
}

@Override
public StackListResult<ItemStack> add(@Nonnull ItemStack stack, int size) {
if (stack.isEmpty() || size <= 0) {
Expand Down
Loading

0 comments on commit 0a5ae5b

Please sign in to comment.