aboutsummaryrefslogtreecommitdiff
path: root/RoughlyEnoughItems-runtime/src/main/java/me
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2020-08-21 18:03:13 +0800
committershedaniel <daniel@shedaniel.me>2020-08-21 18:03:13 +0800
commit28b5f0d67e4e7e87063c613dbe60849f86b58edf (patch)
treeaa8cb01e8ae245b95d0fa4dafe9e09a622bb8668 /RoughlyEnoughItems-runtime/src/main/java/me
parent88025ee2dd9830aacaa380f5394c1072ed661f8f (diff)
downloadRoughlyEnoughItems-28b5f0d67e4e7e87063c613dbe60849f86b58edf.tar.gz
RoughlyEnoughItems-28b5f0d67e4e7e87063c613dbe60849f86b58edf.tar.bz2
RoughlyEnoughItems-28b5f0d67e4e7e87063c613dbe60849f86b58edf.zip
Fix #402
Signed-off-by: shedaniel <daniel@shedaniel.me>
Diffstat (limited to 'RoughlyEnoughItems-runtime/src/main/java/me')
-rw-r--r--RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsNetwork.java13
-rw-r--r--RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/FluidEntryStack.java2
-rw-r--r--RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/server/InputSlotCrafter.java17
3 files changed, 16 insertions, 16 deletions
diff --git a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsNetwork.java b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsNetwork.java
index 044b2ae4a..07936f4eb 100644
--- a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsNetwork.java
+++ b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsNetwork.java
@@ -24,7 +24,6 @@
package me.shedaniel.rei;
import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
import io.netty.buffer.Unpooled;
import me.shedaniel.math.api.Executor;
import me.shedaniel.rei.server.InputSlotCrafter;
@@ -42,11 +41,10 @@ import net.minecraft.text.TranslatableText;
import net.minecraft.util.Formatting;
import net.minecraft.util.Identifier;
import net.minecraft.util.Util;
+import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.math.MathHelper;
-import java.util.Comparator;
import java.util.List;
-import java.util.Map;
public class RoughlyEnoughItemsNetwork implements ModInitializer {
@@ -115,7 +113,7 @@ public class RoughlyEnoughItemsNetwork implements ModInitializer {
PlayerContainer playerContainer = player.playerContainer;
try {
boolean shift = packetByteBuf.readBoolean();
- Map<Integer, List<ItemStack>> input = Maps.newHashMap();
+ DefaultedList<List<ItemStack>> input = DefaultedList.of();
int mapSize = packetByteBuf.readInt();
for (int i = 0; i < mapSize; i++) {
List<ItemStack> list = Lists.newArrayList();
@@ -123,7 +121,7 @@ public class RoughlyEnoughItemsNetwork implements ModInitializer {
for (int j = 0; j < count; j++) {
list.add(packetByteBuf.readItemStack());
}
- input.put(i, list);
+ input.add(list);
}
try {
InputSlotCrafter.start(category, container, player, input, shift);
@@ -132,13 +130,12 @@ public class RoughlyEnoughItemsNetwork implements ModInitializer {
return;
PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
buf.writeInt(input.size());
- input.entrySet().stream().sorted(Comparator.comparingInt(Map.Entry::getKey)).forEach(entry -> {
- List<ItemStack> stacks = entry.getValue();
+ for (List<ItemStack> stacks : input) {
buf.writeInt(stacks.size());
for (ItemStack stack : stacks) {
buf.writeItemStack(stack);
}
- });
+ }
if (ServerSidePacketRegistry.INSTANCE.canPlayerReceive(player, NOT_ENOUGH_ITEMS_PACKET)) {
ServerSidePacketRegistry.INSTANCE.sendToPlayer(player, NOT_ENOUGH_ITEMS_PACKET, buf);
}
diff --git a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/FluidEntryStack.java b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/FluidEntryStack.java
index bced484c6..b50f70f05 100644
--- a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/FluidEntryStack.java
+++ b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/FluidEntryStack.java
@@ -195,7 +195,7 @@ public class FluidEntryStack extends AbstractEntryStack {
if (!get(Settings.TOOLTIP_ENABLED).get() || isEmpty())
return null;
List<Text> toolTip = Lists.newArrayList(asFormattedText());
- if (!amount.isLessThan(Fraction.empty())) {
+ if (!amount.isLessThan(Fraction.empty()) && !amount.equals(IGNORE_AMOUNT)) {
String amountTooltip = get(Settings.Fluid.AMOUNT_TOOLTIP).apply(this);
if (amountTooltip != null)
toolTip.addAll(Stream.of(amountTooltip.split("\n")).map(LiteralText::new).collect(Collectors.toList()));
diff --git a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/server/InputSlotCrafter.java b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/server/InputSlotCrafter.java
index 4447256e2..5d3143019 100644
--- a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/server/InputSlotCrafter.java
+++ b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/server/InputSlotCrafter.java
@@ -25,17 +25,20 @@ package me.shedaniel.rei.server;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList;
+import me.shedaniel.rei.utils.CollectionUtils;
import net.minecraft.container.Container;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.Inventory;
-import net.minecraft.item.Item;
+import net.minecraft.item.ItemConvertible;
import net.minecraft.item.ItemStack;
import net.minecraft.recipe.Ingredient;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
import net.minecraft.util.collection.DefaultedList;
-import java.util.*;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Objects;
public class InputSlotCrafter<C extends Inventory> implements RecipeGridAligner<Integer>, ContainerContext {
@@ -50,12 +53,12 @@ public class InputSlotCrafter<C extends Inventory> implements RecipeGridAligner<
this.containerInfo = containerInfo;
}
- public static <C extends Inventory> void start(Identifier category, Container craftingContainer_1, ServerPlayerEntity player, Map<Integer, List<ItemStack>> map, boolean hasShift) {
+ public static <C extends Inventory> void start(Identifier category, Container craftingContainer_1, ServerPlayerEntity player, DefaultedList<List<ItemStack>> map, boolean hasShift) {
ContainerInfo<? extends Container> containerInfo = Objects.requireNonNull(ContainerInfoHandler.getContainerInfo(category, craftingContainer_1.getClass()), "Container Info does not exist on the server!");
new InputSlotCrafter<C>(craftingContainer_1, containerInfo).fillInputSlots(player, map, hasShift);
}
- private void fillInputSlots(ServerPlayerEntity player, Map<Integer, List<ItemStack>> map, boolean hasShift) {
+ private void fillInputSlots(ServerPlayerEntity player, DefaultedList<List<ItemStack>> map, boolean hasShift) {
this.player = player;
this.inventoryStacks = this.containerInfo.getInventoryStacks(this);
this.gridStacks = this.containerInfo.getGridStacks(this);
@@ -67,9 +70,9 @@ public class InputSlotCrafter<C extends Inventory> implements RecipeGridAligner<
RecipeFinder recipeFinder = new RecipeFinder();
this.containerInfo.getRecipeFinderPopulator().populate(this).accept(recipeFinder);
DefaultedList<Ingredient> ingredients = DefaultedList.of();
- map.entrySet().stream().sorted(Comparator.comparingInt(Map.Entry::getKey)).forEach(entry -> {
- ingredients.add(Ingredient.ofItems(entry.getValue().stream().map(ItemStack::getItem).toArray(Item[]::new)));
- });
+ for (List<ItemStack> itemStacks : map) {
+ ingredients.add(Ingredient.ofItems(CollectionUtils.map(itemStacks, ItemStack::getItem).toArray(new ItemConvertible[0])));
+ }
if (recipeFinder.findRecipe(ingredients, null)) {
this.fillInputSlots(recipeFinder, ingredients, hasShift);