port over changes on 1.10
related to autocrafting and pattern transfering
This commit is contained in:
@@ -76,14 +76,26 @@ public final class RSUtils {
|
||||
QUANTITY_FORMATTER.setRoundingMode(RoundingMode.DOWN);
|
||||
}
|
||||
|
||||
public static void writeItemStack(ByteBuf buf, INetworkMaster network, ItemStack stack, boolean displayCraftText) {
|
||||
public static void writeItemStack(ByteBuf buf, ItemStack stack) {
|
||||
writeItemStack(buf, stack, null, false);
|
||||
}
|
||||
|
||||
public static void writeItemStack(ByteBuf buf, ItemStack stack, INetworkMaster network, boolean displayCraftText) {
|
||||
buf.writeInt(Item.getIdFromItem(stack.getItem()));
|
||||
buf.writeInt(stack.getCount());
|
||||
buf.writeInt(stack.getItemDamage());
|
||||
ByteBufUtils.writeTag(buf, stack.getItem().getNBTShareTag(stack));
|
||||
buf.writeInt(API.instance().getItemStackHashCode(stack));
|
||||
buf.writeBoolean(network.hasPattern(stack));
|
||||
buf.writeBoolean(displayCraftText);
|
||||
if (network != null) {
|
||||
ByteBufUtils.writeTag(buf, stack.getItem().getNBTShareTag(stack));
|
||||
buf.writeInt(API.instance().getItemStackHashCode(stack));
|
||||
buf.writeBoolean(network.hasPattern(stack));
|
||||
buf.writeBoolean(displayCraftText);
|
||||
}
|
||||
}
|
||||
|
||||
public static ItemStack readItemStack(ByteBuf buf) {
|
||||
ItemStack stack = new ItemStack(Item.getItemById(buf.readInt()), buf.readInt(), buf.readInt());
|
||||
stack.setTagCompound(ByteBufUtils.readTag(buf));
|
||||
return stack;
|
||||
}
|
||||
|
||||
public static void writeFluidStack(ByteBuf buf, FluidStack stack) {
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.raoulvdberge.refinedstorage.api.autocrafting;
|
||||
import com.raoulvdberge.refinedstorage.api.util.IComparer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -46,8 +47,9 @@ public interface ICraftingPattern {
|
||||
|
||||
/**
|
||||
* @param took the items took
|
||||
* @return the outputs based on the items took
|
||||
* @return the outputs based on the items took, null when failed
|
||||
*/
|
||||
@Nullable
|
||||
List<ItemStack> getOutputs(ItemStack[] took);
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,6 +15,7 @@ import net.minecraft.world.World;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import net.minecraftforge.oredict.ShapedOreRecipe;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -193,6 +194,7 @@ public class CraftingPattern implements ICraftingPattern {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public List<ItemStack> getOutputs(ItemStack[] took) {
|
||||
List<ItemStack> outputs = new ArrayList<>();
|
||||
|
||||
@@ -209,7 +211,11 @@ public class CraftingPattern implements ICraftingPattern {
|
||||
}
|
||||
}
|
||||
|
||||
ItemStack cleaned = recipe.getCraftingResult(inv).copy();
|
||||
ItemStack cleaned = recipe.getCraftingResult(inv);
|
||||
if (cleaned.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
cleaned = cleaned.copy();
|
||||
if (mekanism && cleaned.hasTagCompound()) {
|
||||
cleaned.getTagCompound().removeTag("mekData");
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ public abstract class CraftingStep implements ICraftingStep {
|
||||
return AvailableType.ITEM;
|
||||
}
|
||||
|
||||
protected boolean extractItems(IStackList<ItemStack> actualInputs, int compare, Deque<ItemStack> toInsertItems) {
|
||||
protected boolean extractItems(List<ItemStack> actualInputs, int compare, Deque<ItemStack> toInsertItems) {
|
||||
for (ItemStack insertStack : getToInsert()) {
|
||||
// This will be a tool, like a hammer
|
||||
if (insertStack.isItemStackDamageable()) {
|
||||
@@ -203,7 +203,7 @@ public abstract class CraftingStep implements ICraftingStep {
|
||||
|
||||
if (abort) {
|
||||
// Abort task re-insert taken stacks and reset state
|
||||
toInsertItems.addAll(actualInputs.getStacks());
|
||||
toInsertItems.addAll(actualInputs);
|
||||
startedProcessing = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -61,23 +61,32 @@ public class CraftingStepCraft extends CraftingStep {
|
||||
|
||||
@Override
|
||||
public void execute(Deque<ItemStack> toInsertItems, Deque<FluidStack> toInsertFluids) {
|
||||
IStackList<ItemStack> actualInputs = API.instance().createItemStackList();
|
||||
List<ItemStack> actualInputs = new LinkedList<>();
|
||||
int compare = CraftingTask.DEFAULT_COMPARE | (getPattern().isOredict() ? IComparer.COMPARE_OREDICT : 0);
|
||||
if (extractItems(actualInputs, compare, toInsertItems)) {
|
||||
IStackList<ItemStack> stackList = API.instance().createItemStackList();
|
||||
actualInputs.forEach(stackList::add);
|
||||
|
||||
ItemStack[] took = StackListItem.toCraftingGrid(actualInputs, toInsert, compare);
|
||||
ItemStack[] took = StackListItem.toCraftingGrid(stackList, toInsert, compare);
|
||||
|
||||
List<ItemStack> outputs = pattern.isOredict() ? pattern.getOutputs(took) : pattern.getOutputs();
|
||||
if (outputs == null) {
|
||||
toInsertItems.addAll(actualInputs);
|
||||
startedProcessing = false;
|
||||
return;
|
||||
}
|
||||
|
||||
for (ItemStack output : outputs) {
|
||||
if (output != null) {
|
||||
toInsertItems.add(output.copy());
|
||||
}
|
||||
}
|
||||
|
||||
for (ItemStack byproduct : (pattern.isOredict() ? pattern.getByproducts(took) : pattern.getByproducts())) {
|
||||
if (byproduct != null) {
|
||||
toInsertItems.add(byproduct.copy());
|
||||
}
|
||||
}
|
||||
|
||||
for (ItemStack output : (pattern.isOredict() ? pattern.getOutputs(took) : pattern.getOutputs())) {
|
||||
if (output != null) {
|
||||
toInsertItems.add(output.copy());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -72,12 +72,12 @@ public class CraftingStepProcess extends CraftingStep {
|
||||
|
||||
@Override
|
||||
public void execute(Deque<ItemStack> toInsertItems, Deque<FluidStack> toInsertFluids) {
|
||||
IStackList<ItemStack> actualInputs = API.instance().createItemStackList();
|
||||
List<ItemStack> actualInputs = new LinkedList<>();
|
||||
int compare = CraftingTask.DEFAULT_COMPARE | (getPattern().isOredict() ? IComparer.COMPARE_OREDICT : 0);
|
||||
if (extractItems(actualInputs, compare, toInsertItems)) {
|
||||
IItemHandler inventory = getPattern().getContainer().getFacingInventory();
|
||||
if (insertSimulation(inventory, new ArrayDeque<>(actualInputs.getStacks()))) {
|
||||
actualInputs.getStacks().forEach(stack -> ItemHandlerHelper.insertItem(inventory, stack, false));
|
||||
if (insertSimulation(inventory, new ArrayDeque<>(actualInputs))) {
|
||||
actualInputs.forEach(stack -> ItemHandlerHelper.insertItem(inventory, stack, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,14 +226,19 @@ public class CraftingTask implements ICraftingTask {
|
||||
}
|
||||
}
|
||||
|
||||
for (ItemStack byproduct : (!pattern.isProcessing() && pattern.isOredict() && missing.isEmpty() ? pattern.getByproducts(took) : pattern.getByproducts())) {
|
||||
toInsert.add(byproduct.copy());
|
||||
List<ItemStack> outputs = !pattern.isProcessing() && pattern.isOredict() && missing.isEmpty() ? pattern.getOutputs(took) : pattern.getOutputs();
|
||||
if (outputs == null) { // Bla Bla what evs
|
||||
outputs = pattern.getOutputs();
|
||||
}
|
||||
|
||||
for (ItemStack output : (!pattern.isProcessing() && pattern.isOredict() && missing.isEmpty() ? pattern.getOutputs(took) : pattern.getOutputs())) {
|
||||
for (ItemStack output : outputs) {
|
||||
toInsert.add(output.copy());
|
||||
}
|
||||
|
||||
for (ItemStack byproduct : (!pattern.isProcessing() && pattern.isOredict() && missing.isEmpty() ? pattern.getByproducts(took) : pattern.getByproducts())) {
|
||||
toInsert.add(byproduct.copy());
|
||||
}
|
||||
|
||||
usedPatterns.remove(pattern);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,8 +20,7 @@ public class ClientStackItem implements IClientStack {
|
||||
private boolean displayCraftText;
|
||||
|
||||
public ClientStackItem(ByteBuf buf) {
|
||||
stack = new ItemStack(Item.getItemById(buf.readInt()), buf.readInt(), buf.readInt());
|
||||
stack.setTagCompound(ByteBufUtils.readTag(buf));
|
||||
stack = RSUtils.readItemStack(buf);
|
||||
hash = buf.readInt();
|
||||
craftable = buf.readBoolean();
|
||||
|
||||
|
||||
@@ -90,7 +90,13 @@ public class ItemBlockFluidStorage extends ItemBlockBase {
|
||||
|
||||
@Override
|
||||
public NBTTagCompound getNBTShareTag(ItemStack stack) {
|
||||
return !isValid(stack) ? super.getNBTShareTag(stack) : StorageFluidNBT.getNBTShareTag(stack.getTagCompound().getCompoundTag(TileFluidStorage.NBT_STORAGE));
|
||||
if (!isValid(stack)) {
|
||||
return super.getNBTShareTag(stack);
|
||||
} else {
|
||||
NBTTagCompound shareTag = new NBTTagCompound();
|
||||
shareTag.setTag(TileFluidStorage.NBT_STORAGE, StorageFluidNBT.getNBTShareTag(stack.getTagCompound().getCompoundTag(TileFluidStorage.NBT_STORAGE)));
|
||||
return shareTag;
|
||||
}
|
||||
}
|
||||
|
||||
public static ItemStack initNBT(ItemStack stack) {
|
||||
|
||||
@@ -90,7 +90,13 @@ public class ItemBlockStorage extends ItemBlockBase {
|
||||
|
||||
@Override
|
||||
public NBTTagCompound getNBTShareTag(ItemStack stack) {
|
||||
return !isValid(stack) ? super.getNBTShareTag(stack) : StorageItemNBT.getNBTShareTag(stack.getTagCompound().getCompoundTag(TileStorage.NBT_STORAGE));
|
||||
if (!isValid(stack)) {
|
||||
return super.getNBTShareTag(stack);
|
||||
} else {
|
||||
NBTTagCompound shareTag = new NBTTagCompound();
|
||||
shareTag.setTag(TileStorage.NBT_STORAGE, StorageItemNBT.getNBTShareTag(stack.getTagCompound().getCompoundTag(TileStorage.NBT_STORAGE)));
|
||||
return shareTag;
|
||||
}
|
||||
}
|
||||
|
||||
public static ItemStack initNBT(ItemStack stack) {
|
||||
|
||||
@@ -35,7 +35,7 @@ public class MessageGridItemDelta implements IMessage, IMessageHandler<MessageGr
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
RSUtils.writeItemStack(buf, network, stack, false);
|
||||
RSUtils.writeItemStack(buf, stack, network, false);
|
||||
buf.writeInt(delta);
|
||||
}
|
||||
|
||||
|
||||
@@ -46,13 +46,13 @@ public class MessageGridItemUpdate implements IMessage, IMessageHandler<MessageG
|
||||
buf.writeInt(size);
|
||||
|
||||
for (ItemStack stack : network.getItemStorageCache().getList().getStacks()) {
|
||||
RSUtils.writeItemStack(buf, network, stack, false);
|
||||
RSUtils.writeItemStack(buf, stack, network, false);
|
||||
}
|
||||
|
||||
for (ICraftingPattern pattern : network.getPatterns()) {
|
||||
for (ItemStack output : pattern.getOutputs()) {
|
||||
if (output != null) {
|
||||
RSUtils.writeItemStack(buf, network, output, true);
|
||||
RSUtils.writeItemStack(buf, output, network, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package com.raoulvdberge.refinedstorage.network;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.RSUtils;
|
||||
import com.raoulvdberge.refinedstorage.container.ContainerProcessingPatternEncoder;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fml.common.network.ByteBufUtils;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -29,7 +29,7 @@ public class MessageProcessingPatternEncoderTransfer extends MessageHandlerPlaye
|
||||
this.inputs = new ArrayList<>(size);
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
this.inputs.add(ByteBufUtils.readItemStack(buf));
|
||||
this.inputs.add(RSUtils.readItemStack(buf));
|
||||
}
|
||||
|
||||
size = buf.readInt();
|
||||
@@ -37,7 +37,7 @@ public class MessageProcessingPatternEncoderTransfer extends MessageHandlerPlaye
|
||||
this.outputs = new ArrayList<>(size);
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
this.outputs.add(ByteBufUtils.readItemStack(buf));
|
||||
this.outputs.add(RSUtils.readItemStack(buf));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,13 +46,13 @@ public class MessageProcessingPatternEncoderTransfer extends MessageHandlerPlaye
|
||||
buf.writeInt(inputs.size());
|
||||
|
||||
for (ItemStack stack : inputs) {
|
||||
ByteBufUtils.writeItemStack(buf, stack);
|
||||
RSUtils.writeItemStack(buf, stack);
|
||||
}
|
||||
|
||||
buf.writeInt(outputs.size());
|
||||
|
||||
for (ItemStack stack : outputs) {
|
||||
ByteBufUtils.writeItemStack(buf, stack);
|
||||
RSUtils.writeItemStack(buf, stack);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user