Rebuilt the recipe transfer after upstream changes.
This commit is contained in:
@@ -28,18 +28,18 @@ import com.mojang.datafixers.util.Pair;
|
||||
import io.netty.buffer.Unpooled;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.item.crafting.IRecipeSerializer;
|
||||
import net.minecraft.item.crafting.Ingredient;
|
||||
import net.minecraft.item.crafting.ShapedRecipe;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.common.crafting.IShapedRecipe;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.recipe.Ingredient;
|
||||
import net.minecraft.recipe.Recipe;
|
||||
import net.minecraft.recipe.RecipeSerializer;
|
||||
import net.minecraft.recipe.ShapedRecipe;
|
||||
import net.minecraft.screen.ScreenHandler;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.collection.DefaultedList;
|
||||
|
||||
import alexiil.mc.lib.attributes.item.FixedItemInv;
|
||||
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.SecurityPermissions;
|
||||
@@ -59,9 +59,10 @@ import appeng.core.sync.BasePacketHandler;
|
||||
import appeng.core.sync.network.INetworkInfo;
|
||||
import appeng.helpers.IContainerCraftingPacket;
|
||||
import appeng.items.storage.ViewCellItem;
|
||||
import appeng.mixins.IngredientAccessor;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.helpers.ItemHandlerUtil;
|
||||
import appeng.util.inv.AdaptorItemHandler;
|
||||
import appeng.util.inv.AdaptorFixedInv;
|
||||
import appeng.util.inv.WrapperInvItemHandler;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import appeng.util.prioritylist.IPartitionList;
|
||||
@@ -79,26 +80,26 @@ public class JEIRecipePacket extends BasePacket {
|
||||
*/
|
||||
private static final int INLINE_RECIPE_SHAPED = 2;
|
||||
|
||||
private ResourceLocation recipeId;
|
||||
private Identifier recipeId;
|
||||
/**
|
||||
* This is optional, in case the client already knows it could not resolve the
|
||||
* recipe id.
|
||||
*/
|
||||
@Nullable
|
||||
private IRecipe<?> recipe;
|
||||
private Recipe<?> recipe;
|
||||
private boolean crafting;
|
||||
|
||||
public JEIRecipePacket(final PacketBuffer stream) {
|
||||
public JEIRecipePacket(final PacketByteBuf stream) {
|
||||
this.crafting = stream.readBoolean();
|
||||
final String id = stream.readString(Short.MAX_VALUE);
|
||||
this.recipeId = new ResourceLocation(id);
|
||||
this.recipeId = new Identifier(id);
|
||||
|
||||
int inlineRecipeType = stream.readVarInt();
|
||||
switch (inlineRecipeType) {
|
||||
case INLINE_RECIPE_NONE:
|
||||
break;
|
||||
case INLINE_RECIPE_SHAPED:
|
||||
recipe = IRecipeSerializer.CRAFTING_SHAPED.read(this.recipeId, stream);
|
||||
recipe = RecipeSerializer.SHAPED.read(this.recipeId, stream);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid inline recipe type.");
|
||||
@@ -109,8 +110,8 @@ public class JEIRecipePacket extends BasePacket {
|
||||
* Sends a recipe identified by the given recipe ID to the server for either
|
||||
* filling a crafting grid or a pattern.
|
||||
*/
|
||||
public JEIRecipePacket(final ResourceLocation recipeId, final boolean crafting) {
|
||||
PacketBuffer data = createCommonHeader(recipeId, crafting, INLINE_RECIPE_NONE);
|
||||
public JEIRecipePacket(final Identifier recipeId, final boolean crafting) {
|
||||
PacketByteBuf data = createCommonHeader(recipeId, crafting, INLINE_RECIPE_NONE);
|
||||
this.configureWrite(data);
|
||||
}
|
||||
|
||||
@@ -120,17 +121,17 @@ public class JEIRecipePacket extends BasePacket {
|
||||
* Prefer the id-based constructor above whereever possible.
|
||||
*/
|
||||
public JEIRecipePacket(final ShapedRecipe recipe, final boolean crafting) {
|
||||
PacketBuffer data = createCommonHeader(recipe.getId(), crafting, INLINE_RECIPE_SHAPED);
|
||||
IRecipeSerializer.CRAFTING_SHAPED.write(data, recipe);
|
||||
PacketByteBuf data = createCommonHeader(recipe.getId(), crafting, INLINE_RECIPE_SHAPED);
|
||||
RecipeSerializer.SHAPED.write(data, recipe);
|
||||
this.configureWrite(data);
|
||||
}
|
||||
|
||||
private PacketBuffer createCommonHeader(ResourceLocation recipeId, boolean crafting, int inlineRecipeType) {
|
||||
final PacketBuffer data = new PacketBuffer(Unpooled.buffer());
|
||||
private PacketByteBuf createCommonHeader(Identifier recipeId, boolean crafting, int inlineRecipeType) {
|
||||
final PacketByteBuf data = new PacketByteBuf(Unpooled.buffer());
|
||||
|
||||
data.writeInt(this.getPacketID());
|
||||
data.writeBoolean(crafting);
|
||||
data.writeResourceLocation(recipeId);
|
||||
data.writeIdentifier(recipeId);
|
||||
data.writeVarInt(inlineRecipeType);
|
||||
|
||||
return data;
|
||||
@@ -147,10 +148,10 @@ public class JEIRecipePacket extends BasePacket {
|
||||
public void serverPacketData(final INetworkInfo manager, final PlayerEntity player) {
|
||||
// Setup and verification
|
||||
final ServerPlayerEntity pmp = (ServerPlayerEntity) player;
|
||||
final Container con = pmp.openContainer;
|
||||
final ScreenHandler con = pmp.currentScreenHandler;
|
||||
Preconditions.checkArgument(con instanceof IContainerCraftingPacket);
|
||||
|
||||
IRecipe<?> recipe = player.getEntityWorld().getRecipeManager().getRecipe(this.recipeId).orElse(null);
|
||||
Recipe<?> recipe = player.getEntityWorld().getRecipeManager().get(this.recipeId).orElse(null);
|
||||
if (recipe == null && this.recipe != null) {
|
||||
// Certain recipes (i.e. AE2 facades) are represented in JEI as ShapedRecipe's,
|
||||
// while in reality they
|
||||
@@ -175,17 +176,17 @@ public class JEIRecipePacket extends BasePacket {
|
||||
|
||||
final IEnergyGrid energy = grid.getCache(IEnergyGrid.class);
|
||||
final ICraftingGrid crafting = grid.getCache(ICraftingGrid.class);
|
||||
final IItemHandler craftMatrix = cct.getInventoryByName("crafting");
|
||||
final IItemHandler playerInventory = cct.getInventoryByName("player");
|
||||
final FixedItemInv craftMatrix = cct.getInventoryByName("crafting");
|
||||
final FixedItemInv playerInventory = cct.getInventoryByName("player");
|
||||
|
||||
final IMEMonitor<IAEItemStack> storage = inv
|
||||
.getInventory(Api.instance().storage().getStorageChannel(IItemStorageChannel.class));
|
||||
final IPartitionList<IAEItemStack> filter = ViewCellItem.createFilter(cct.getViewCells());
|
||||
final NonNullList<Ingredient> ingredients = this.ensure3by3CraftingMatrix(recipe);
|
||||
final DefaultedList<Ingredient> ingredients = this.ensure3by3CraftingMatrix(recipe);
|
||||
|
||||
// Handle each slot
|
||||
for (int x = 0; x < craftMatrix.getSlots(); x++) {
|
||||
ItemStack currentItem = craftMatrix.getStackInSlot(x);
|
||||
for (int x = 0; x < craftMatrix.getSlotCount(); x++) {
|
||||
ItemStack currentItem = craftMatrix.getInvStack(x);
|
||||
Ingredient ingredient = ingredients.get(x);
|
||||
|
||||
// prepare slots
|
||||
@@ -222,8 +223,8 @@ public class JEIRecipePacket extends BasePacket {
|
||||
if (out == null) {
|
||||
out = findBestMatchingItemStack(ingredient, filter, storage, cct);
|
||||
}
|
||||
if (out == null && ingredient.getMatchingStacks().length > 0) {
|
||||
out = AEItemStack.fromItemStack(ingredient.getMatchingStacks()[0]);
|
||||
if (out == null && getMatchingStacks(ingredient).length > 0) {
|
||||
out = AEItemStack.fromItemStack(getMatchingStacks(ingredient)[0]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -234,10 +235,10 @@ public class JEIRecipePacket extends BasePacket {
|
||||
|
||||
// If still nothing, search the player inventory.
|
||||
if (currentItem.isEmpty()) {
|
||||
ItemStack[] matchingStacks = ingredient.getMatchingStacks();
|
||||
ItemStack[] matchingStacks = getMatchingStacks(ingredient);
|
||||
for (ItemStack matchingStack : matchingStacks) {
|
||||
if (currentItem.isEmpty()) {
|
||||
AdaptorItemHandler ad = new AdaptorItemHandler(playerInventory);
|
||||
AdaptorFixedInv ad = new AdaptorFixedInv(playerInventory);
|
||||
|
||||
if (cct.useRealItems()) {
|
||||
currentItem = ad.removeItems(1, matchingStack, null);
|
||||
@@ -254,7 +255,21 @@ public class JEIRecipePacket extends BasePacket {
|
||||
this.handleProcessing(con, cct, recipe);
|
||||
}
|
||||
|
||||
con.onCraftMatrixChanged(new WrapperInvItemHandler(craftMatrix));
|
||||
con.onContentChanged(new WrapperInvItemHandler(craftMatrix));
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
private static ItemStack[] getMatchingStacks(Ingredient ingredient) {
|
||||
IngredientAccessor accessor = (IngredientAccessor) (Object) ingredient;
|
||||
// accessor.callCacheMatchingStacks();
|
||||
if (ingredient.isEmpty()) {
|
||||
return new ItemStack[0];
|
||||
}
|
||||
ItemStack[] stacks = accessor.getMatchingStacks();
|
||||
if (stacks.length == 1 && stacks[0].isEmpty()) {
|
||||
return new ItemStack[0];
|
||||
}
|
||||
return stacks;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -263,18 +278,18 @@ public class JEIRecipePacket extends BasePacket {
|
||||
* Will throw an {@link IllegalArgumentException} in case it has more than 9 or
|
||||
* a shaped recipe is either wider or higher than 3. ingredients.
|
||||
*/
|
||||
private NonNullList<Ingredient> ensure3by3CraftingMatrix(IRecipe<?> recipe) {
|
||||
NonNullList<Ingredient> ingredients = recipe.getIngredients();
|
||||
NonNullList<Ingredient> expandedIngredients = NonNullList.withSize(9, Ingredient.EMPTY);
|
||||
private DefaultedList<Ingredient> ensure3by3CraftingMatrix(Recipe<?> recipe) {
|
||||
DefaultedList<Ingredient> ingredients = recipe.getPreviewInputs();
|
||||
DefaultedList<Ingredient> expandedIngredients = DefaultedList.ofSize(9, Ingredient.EMPTY);
|
||||
|
||||
Preconditions.checkArgument(ingredients.size() <= 9);
|
||||
|
||||
// shaped recipes can be smaller than 3x3, expand to 3x3 to match the crafting
|
||||
// matrix
|
||||
if (recipe instanceof IShapedRecipe) {
|
||||
IShapedRecipe<?> shapedRecipe = (IShapedRecipe<?>) recipe;
|
||||
int width = shapedRecipe.getRecipeWidth();
|
||||
int height = shapedRecipe.getRecipeHeight();
|
||||
if (recipe instanceof ShapedRecipe) {
|
||||
ShapedRecipe shapedRecipe = (ShapedRecipe) recipe;
|
||||
int width = shapedRecipe.getWidth();
|
||||
int height = shapedRecipe.getHeight();
|
||||
Preconditions.checkArgument(width <= 3 && height <= 3);
|
||||
|
||||
for (int h = 0; h < height; h++) {
|
||||
@@ -301,7 +316,7 @@ public class JEIRecipePacket extends BasePacket {
|
||||
* @return is if it can be used, else EMPTY
|
||||
*/
|
||||
private ItemStack canUseInSlot(Ingredient ingredient, ItemStack is) {
|
||||
return Arrays.stream(ingredient.getMatchingStacks()).filter(p -> p.isItemEqual(is)).findFirst()
|
||||
return Arrays.stream(getMatchingStacks(ingredient)).filter(p -> p.isItemEqual(is)).findFirst()
|
||||
.orElse(ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
@@ -310,7 +325,7 @@ public class JEIRecipePacket extends BasePacket {
|
||||
*/
|
||||
private IAEItemStack findBestMatchingItemStack(Ingredient ingredients, IPartitionList<IAEItemStack> filter,
|
||||
IMEMonitor<IAEItemStack> storage, IContainerCraftingPacket cct) {
|
||||
return Arrays.stream(ingredients.getMatchingStacks()).map(AEItemStack::fromItemStack) //
|
||||
return Arrays.stream(getMatchingStacks(ingredients)).map(AEItemStack::fromItemStack) //
|
||||
.filter(r -> r != null && (filter == null || filter.isListed(r))) //
|
||||
.map(s -> {
|
||||
// Determine the stored count
|
||||
@@ -329,7 +344,7 @@ public class JEIRecipePacket extends BasePacket {
|
||||
*/
|
||||
private IAEItemStack findBestMatchingPattern(Ingredient ingredients, IPartitionList<IAEItemStack> filter,
|
||||
ICraftingGrid crafting, IMEMonitor<IAEItemStack> storage, IContainerCraftingPacket cct) {
|
||||
return Arrays.stream(ingredients.getMatchingStacks()).map(AEItemStack::fromItemStack)
|
||||
return Arrays.stream(getMatchingStacks(ingredients)).map(AEItemStack::fromItemStack)
|
||||
.filter(r -> r != null && (filter == null || filter.isListed(r)))
|
||||
.map(s -> s.setCraftable(!crafting.getCraftingFor(s, null, 0, null).isEmpty()))
|
||||
.filter(IAEItemStack::isCraftable).map(s -> {
|
||||
@@ -341,12 +356,12 @@ public class JEIRecipePacket extends BasePacket {
|
||||
}).orElse(null);
|
||||
}
|
||||
|
||||
private void handleProcessing(Container con, IContainerCraftingPacket cct, IRecipe<?> recipe) {
|
||||
private void handleProcessing(ScreenHandler con, IContainerCraftingPacket cct, Recipe<?> recipe) {
|
||||
if (con instanceof PatternTermContainer) {
|
||||
PatternTermContainer patternTerm = (PatternTermContainer) con;
|
||||
if (!patternTerm.craftingMode) {
|
||||
final IItemHandler output = cct.getInventoryByName("output");
|
||||
ItemHandlerUtil.setStackInSlot(output, 0, recipe.getRecipeOutput());
|
||||
final FixedItemInv output = cct.getInventoryByName("output");
|
||||
ItemHandlerUtil.setStackInSlot(output, 0, recipe.getOutput());
|
||||
ItemHandlerUtil.setStackInSlot(output, 1, ItemStack.EMPTY);
|
||||
ItemHandlerUtil.setStackInSlot(output, 2, ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
@@ -18,8 +18,6 @@
|
||||
|
||||
package appeng.integration.abstraction;
|
||||
|
||||
import mezz.jei.api.runtime.IJeiRuntime;
|
||||
|
||||
import appeng.integration.IIntegrationModule;
|
||||
|
||||
/**
|
||||
@@ -27,10 +25,6 @@ import appeng.integration.IIntegrationModule;
|
||||
*/
|
||||
public interface IRei extends IIntegrationModule {
|
||||
|
||||
default IJeiRuntime getRuntime() {
|
||||
return null;
|
||||
}
|
||||
|
||||
default String getSearchText() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -18,24 +18,21 @@
|
||||
|
||||
package appeng.integration.modules.jei;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
|
||||
import mezz.jei.api.gui.IRecipeLayout;
|
||||
import mezz.jei.api.recipe.transfer.IRecipeTransferError;
|
||||
import mezz.jei.api.recipe.transfer.IRecipeTransferHandlerHelper;
|
||||
import me.shedaniel.rei.api.AutoTransferHandler;
|
||||
import me.shedaniel.rei.api.RecipeDisplay;
|
||||
import me.shedaniel.rei.api.TransferRecipeDisplay;
|
||||
|
||||
import appeng.container.implementations.CraftingTermContainer;
|
||||
|
||||
public class CraftingRecipeTransferHandler extends RecipeTransferHandler<CraftingTermContainer> {
|
||||
|
||||
CraftingRecipeTransferHandler(Class<CraftingTermContainer> containerClass, IRecipeTransferHandlerHelper helper) {
|
||||
super(containerClass, helper);
|
||||
public CraftingRecipeTransferHandler(Class<CraftingTermContainer> containerClass) {
|
||||
super(containerClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IRecipeTransferError doTransferRecipe(CraftingTermContainer container, IRecipe<?> recipe,
|
||||
IRecipeLayout recipeLayout, PlayerEntity player, boolean maxTransfer) {
|
||||
protected AutoTransferHandler.Result doTransferRecipe(CraftingTermContainer container, RecipeDisplay recipe,
|
||||
AutoTransferHandler.Context context) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -108,6 +108,8 @@ class FacadeRegistryGenerator implements LiveRecipeGenerator<DefaultShapedDispla
|
||||
ingredients.set(7, Ingredient.ofStacks(cableAnchor));
|
||||
ingredients.set(4, Ingredient.ofStacks(textureItem));
|
||||
|
||||
result.setCount(4);
|
||||
|
||||
return new DefaultShapedDisplay(new ShapedRecipe(id, "", 3, 3, ingredients, result));
|
||||
}
|
||||
|
||||
|
||||
@@ -18,33 +18,28 @@
|
||||
|
||||
package appeng.integration.modules.jei;
|
||||
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
|
||||
import mezz.jei.api.constants.VanillaRecipeCategoryUid;
|
||||
import mezz.jei.api.gui.IRecipeLayout;
|
||||
import mezz.jei.api.recipe.transfer.IRecipeTransferError;
|
||||
import mezz.jei.api.recipe.transfer.IRecipeTransferHandlerHelper;
|
||||
import me.shedaniel.rei.api.AutoTransferHandler;
|
||||
import me.shedaniel.rei.api.RecipeDisplay;
|
||||
import me.shedaniel.rei.api.TransferRecipeDisplay;
|
||||
import me.shedaniel.rei.plugin.DefaultPlugin;
|
||||
|
||||
import appeng.container.implementations.PatternTermContainer;
|
||||
|
||||
public class PatternRecipeTransferHandler extends RecipeTransferHandler<PatternTermContainer> {
|
||||
|
||||
PatternRecipeTransferHandler(Class<PatternTermContainer> containerClass, IRecipeTransferHandlerHelper helper) {
|
||||
super(containerClass, helper);
|
||||
PatternRecipeTransferHandler(Class<PatternTermContainer> containerClass) {
|
||||
super(containerClass);
|
||||
}
|
||||
|
||||
protected IRecipeTransferError doTransferRecipe(PatternTermContainer container, IRecipe<?> recipe,
|
||||
IRecipeLayout recipeLayout, PlayerEntity player, boolean maxTransfer) {
|
||||
if (container.isCraftingMode()
|
||||
&& recipeLayout.getRecipeCategory().getUid() != VanillaRecipeCategoryUid.CRAFTING) {
|
||||
return this.helper
|
||||
.createUserErrorWithTooltip(I18n.format("jei.appliedenergistics2.requires_processing_mode"));
|
||||
protected AutoTransferHandler.Result doTransferRecipe(PatternTermContainer container, RecipeDisplay recipe,
|
||||
AutoTransferHandler.Context context) {
|
||||
|
||||
if (container.isCraftingMode() && recipe.getRecipeCategory() != DefaultPlugin.CRAFTING) {
|
||||
return AutoTransferHandler.Result.createFailed("jei.appliedenergistics2.requires_processing_mode");
|
||||
}
|
||||
|
||||
if (recipe.getRecipeOutput().isEmpty()) {
|
||||
return this.helper.createUserErrorWithTooltip(I18n.format("jei.appliedenergistics2.no_output"));
|
||||
if (recipe.getResultingEntries().isEmpty()) {
|
||||
return AutoTransferHandler.Result.createFailed("jei.appliedenergistics2.no_output");
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -18,82 +18,70 @@
|
||||
|
||||
package appeng.integration.modules.jei;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.item.crafting.Ingredient;
|
||||
import net.minecraft.item.crafting.ShapedRecipe;
|
||||
import net.minecraft.item.crafting.ShapelessRecipe;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.recipe.Ingredient;
|
||||
import net.minecraft.recipe.ShapedRecipe;
|
||||
import net.minecraft.screen.ScreenHandler;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.collection.DefaultedList;
|
||||
|
||||
import mezz.jei.api.gui.IRecipeLayout;
|
||||
import mezz.jei.api.gui.ingredient.IGuiIngredient;
|
||||
import mezz.jei.api.recipe.transfer.IRecipeTransferError;
|
||||
import mezz.jei.api.recipe.transfer.IRecipeTransferHandler;
|
||||
import mezz.jei.api.recipe.transfer.IRecipeTransferHandlerHelper;
|
||||
import me.shedaniel.rei.api.AutoTransferHandler;
|
||||
import me.shedaniel.rei.api.EntryStack;
|
||||
import me.shedaniel.rei.api.RecipeDisplay;
|
||||
import me.shedaniel.rei.api.TransferRecipeDisplay;
|
||||
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.JEIRecipePacket;
|
||||
import appeng.helpers.IContainerCraftingPacket;
|
||||
|
||||
abstract class RecipeTransferHandler<T extends Container & IContainerCraftingPacket>
|
||||
implements IRecipeTransferHandler<T> {
|
||||
abstract class RecipeTransferHandler<T extends ScreenHandler & IContainerCraftingPacket>
|
||||
implements AutoTransferHandler {
|
||||
|
||||
private final Class<T> containerClass;
|
||||
protected final IRecipeTransferHandlerHelper helper;
|
||||
|
||||
RecipeTransferHandler(Class<T> containerClass, IRecipeTransferHandlerHelper helper) {
|
||||
RecipeTransferHandler(Class<T> containerClass) {
|
||||
this.containerClass = containerClass;
|
||||
this.helper = helper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Class<T> getContainerClass() {
|
||||
return this.containerClass;
|
||||
}
|
||||
public AutoTransferHandler.Result handle(AutoTransferHandler.Context context) {
|
||||
RecipeDisplay recipe = context.getRecipe();
|
||||
|
||||
@Override
|
||||
public final IRecipeTransferError transferRecipe(T container, Object recipe, IRecipeLayout recipeLayout,
|
||||
PlayerEntity player, boolean maxTransfer, boolean doTransfer) {
|
||||
if (!(recipe instanceof IRecipe)) {
|
||||
return this.helper.createInternalError();
|
||||
if (!containerClass.isInstance(context.getContainerScreen().getScreenHandler())) {
|
||||
return AutoTransferHandler.Result.createNotApplicable();
|
||||
}
|
||||
final IRecipe<?> irecipe = (IRecipe<?>) recipe;
|
||||
final ResourceLocation recipeId = irecipe.getId();
|
||||
|
||||
if (recipeId == null) {
|
||||
return this.helper.createUserErrorWithTooltip(I18n.format("jei.appliedenergistics2.missing_id"));
|
||||
}
|
||||
T container = containerClass.cast(context.getContainerScreen().getScreenHandler());
|
||||
|
||||
final Identifier recipeId = recipe.getRecipeLocation().orElse(null);
|
||||
|
||||
// Check that the recipe can actually be looked up via the manager, i.e. our
|
||||
// facade recipes
|
||||
// have an ID, but are never registered with the recipe manager.
|
||||
boolean canSendReference = true;
|
||||
if (!player.getEntityWorld().getRecipeManager().getRecipe(recipeId).isPresent()) {
|
||||
// Validate that the recipe is a shapeless or shapedrecipe, since we can
|
||||
// serialize those
|
||||
if (!(recipe instanceof ShapedRecipe) && !(recipe instanceof ShapelessRecipe)) {
|
||||
return this.helper.createUserErrorWithTooltip(I18n.format("jei.appliedenergistics2.missing_id"));
|
||||
}
|
||||
if (recipeId == null || !context.getMinecraft().world.getRecipeManager().get(recipeId).isPresent()) {
|
||||
canSendReference = false;
|
||||
}
|
||||
|
||||
if (!irecipe.canFit(3, 3)) {
|
||||
return this.helper.createUserErrorWithTooltip(I18n.format("jei.appliedenergistics2.recipe_too_large"));
|
||||
if (recipe instanceof TransferRecipeDisplay) {
|
||||
TransferRecipeDisplay trd = (TransferRecipeDisplay) recipe;
|
||||
if (trd.getWidth() > 3 || trd.getHeight() > 3) {
|
||||
return AutoTransferHandler.Result.createFailed("jei.appliedenergistics2.recipe_too_large");
|
||||
}
|
||||
} else if (recipe.getInputEntries().size() > 9) {
|
||||
return AutoTransferHandler.Result.createFailed("jei.appliedenergistics2.recipe_too_large");
|
||||
}
|
||||
|
||||
final IRecipeTransferError error = doTransferRecipe(container, irecipe, recipeLayout, player, maxTransfer);
|
||||
final AutoTransferHandler.Result error = doTransferRecipe(container, recipe, context);
|
||||
|
||||
if (error != null) {
|
||||
return error;
|
||||
}
|
||||
|
||||
if (doTransfer) {
|
||||
if (context.isActuallyCrafting()) {
|
||||
if (canSendReference) {
|
||||
NetworkHandler.instance().sendToServer(new JEIRecipePacket(recipeId, isCrafting()));
|
||||
} else {
|
||||
@@ -102,31 +90,29 @@ abstract class RecipeTransferHandler<T extends Container & IContainerCraftingPac
|
||||
// as a fallback when the recipe ID could not be resolved, we'll just send the
|
||||
// displayed
|
||||
// items.
|
||||
NonNullList<Ingredient> flatIngredients = NonNullList.withSize(9, Ingredient.EMPTY);
|
||||
ItemStack output = ItemStack.EMPTY;
|
||||
|
||||
// Determine the first JEI slot that has an actual input, we'll use this to
|
||||
// offset the
|
||||
// crafting grid target slot
|
||||
int firstInputSlot = recipeLayout.getItemStacks().getGuiIngredients().entrySet().stream()
|
||||
.filter(e -> e.getValue().isInput()).mapToInt(Map.Entry::getKey).min().orElse(0);
|
||||
DefaultedList<Ingredient> flatIngredients = DefaultedList.ofSize(9, Ingredient.EMPTY);
|
||||
ItemStack output = null;
|
||||
for (EntryStack entryStack : recipe.getResultingEntries().get(0)) {
|
||||
if (entryStack.getType() == EntryStack.Type.ITEM) {
|
||||
output = entryStack.getItemStack();
|
||||
}
|
||||
}
|
||||
if (output == null || output.isEmpty()) {
|
||||
return AutoTransferHandler.Result.createFailed("jei.appliedenergistics2.no_output");
|
||||
}
|
||||
|
||||
// Now map the actual ingredients into the output/input
|
||||
for (Map.Entry<Integer, ? extends IGuiIngredient<ItemStack>> entry : recipeLayout.getItemStacks()
|
||||
.getGuiIngredients().entrySet()) {
|
||||
IGuiIngredient<ItemStack> item = entry.getValue();
|
||||
if (item.getDisplayedIngredient() == null) {
|
||||
for (int i = 0; i < recipe.getInputEntries().size(); i++) {
|
||||
List<EntryStack> inputEntry = recipe.getInputEntries().get(i);
|
||||
if (inputEntry.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int inputIndex = entry.getKey() - firstInputSlot;
|
||||
if (item.isInput() && inputIndex < flatIngredients.size()) {
|
||||
ItemStack displayedIngredient = item.getDisplayedIngredient();
|
||||
EntryStack first = inputEntry.get(0);
|
||||
if (i < flatIngredients.size()) {
|
||||
ItemStack displayedIngredient = first.getItemStack();
|
||||
if (displayedIngredient != null) {
|
||||
flatIngredients.set(inputIndex, Ingredient.fromStacks(displayedIngredient));
|
||||
flatIngredients.set(i, Ingredient.method_26964(Stream.of(displayedIngredient)));
|
||||
}
|
||||
} else if (!item.isInput() && output.isEmpty()) {
|
||||
output = item.getDisplayedIngredient();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,11 +121,11 @@ abstract class RecipeTransferHandler<T extends Container & IContainerCraftingPac
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return Result.createSuccessful().blocksFurtherHandling();
|
||||
}
|
||||
|
||||
protected abstract IRecipeTransferError doTransferRecipe(T container, IRecipe<?> recipe, IRecipeLayout recipeLayout,
|
||||
PlayerEntity player, boolean maxTransfer);
|
||||
protected abstract AutoTransferHandler.Result doTransferRecipe(T container, RecipeDisplay recipe,
|
||||
AutoTransferHandler.Context context);
|
||||
|
||||
protected abstract boolean isCrafting();
|
||||
}
|
||||
|
||||
@@ -32,7 +32,6 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import me.shedaniel.math.Rectangle;
|
||||
import me.shedaniel.rei.api.BaseBoundsHandler;
|
||||
import me.shedaniel.rei.api.DisplayHelper;
|
||||
import me.shedaniel.rei.api.EntryRegistry;
|
||||
@@ -124,8 +123,8 @@ public class ReiPlugin implements REIPluginV0 {
|
||||
@Override
|
||||
public void registerOthers(RecipeHelper recipeHelper) {
|
||||
// Allow recipe transfer from JEI to crafting and pattern terminal
|
||||
recipeHelper.registerAutoCraftingHandler(new RecipeTransferHandler<>(CraftingTermContainer.class));
|
||||
recipeHelper.registerAutoCraftingHandler(new RecipeTransferHandler<>(PatternTermContainer.class));
|
||||
recipeHelper.registerAutoCraftingHandler(new CraftingRecipeTransferHandler(CraftingTermContainer.class));
|
||||
recipeHelper.registerAutoCraftingHandler(new PatternRecipeTransferHandler(PatternTermContainer.class));
|
||||
|
||||
recipeHelper.removeAutoCraftButton(GrinderRecipeCategory.UID);
|
||||
recipeHelper.removeAutoCraftButton(InscriberRecipeCategory.UID);
|
||||
@@ -227,7 +226,7 @@ public class ReiPlugin implements REIPluginV0 {
|
||||
ItemStack stack = entryStack.getItemStack();
|
||||
|
||||
if (items.dummyFluidItem().isSameAs(stack) || items.facade().isSameAs(stack) // REI will add a broken facade
|
||||
// with no NBT
|
||||
// with no NBT
|
||||
|| blocks.multiPart().isSameAs(stack) || blocks.matrixFrame().isSameAs(stack)
|
||||
|| blocks.paint().isSameAs(stack)) {
|
||||
return true;
|
||||
|
||||
@@ -39,10 +39,6 @@ class ReiRuntimeAdapter implements IRei {
|
||||
return true;
|
||||
}
|
||||
|
||||
public IJeiRuntime getRuntime() {
|
||||
return runtime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSearchText() {
|
||||
TextFieldWidget searchField = this.runtime.getSearchTextField();
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package appeng.mixins;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
import org.spongepowered.asm.mixin.gen.Invoker;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.recipe.Ingredient;
|
||||
|
||||
@Mixin(Ingredient.class)
|
||||
public interface IngredientAccessor {
|
||||
|
||||
@Invoker
|
||||
void callCacheMatchingStacks();
|
||||
|
||||
@Accessor
|
||||
ItemStack[] getMatchingStacks();
|
||||
|
||||
}
|
||||
@@ -291,7 +291,7 @@ public class FormationPlanePart extends AbstractFormationPlanePart<IAEItemStack>
|
||||
|
||||
// Replace it if there is a custom entity
|
||||
if (is.getItem() instanceof AECustomEntityItem) {
|
||||
Entity result = ((AECustomEntityItem) is.getItem()).replaceItemEntity(w, entity, is);
|
||||
Entity result = ((AECustomEntityItem) is.getItem()).replaceItemEntity(w, (ItemEntity) entity, is);
|
||||
// Destroy the old one, in case it's spawned somehow and replace with the new
|
||||
// one.
|
||||
if (result != entity) {
|
||||
@@ -300,16 +300,6 @@ public class FormationPlanePart extends AbstractFormationPlanePart<IAEItemStack>
|
||||
}
|
||||
}
|
||||
|
||||
if (is.getItem().hasCustomEntity(is)) {
|
||||
Entity result = is.getItem().createEntity(w, entity, is);
|
||||
// Destroy the old one, in case it's spawned somehow and replace with the new
|
||||
// one.
|
||||
if (result != null) {
|
||||
entity.remove();
|
||||
entity = result;
|
||||
}
|
||||
}
|
||||
|
||||
// When spawning downwards, we have to take into account that it spawns it at
|
||||
// their "feet" and not center like x or z. So we move it up to be flush with
|
||||
// the plane
|
||||
@@ -340,7 +330,7 @@ public class FormationPlanePart extends AbstractFormationPlanePart<IAEItemStack>
|
||||
final double absoluteZ = centerZ + offsetZ;
|
||||
|
||||
// Set to correct position and slow the motion down a bit
|
||||
entity.setPosition(absoluteX, absoluteY, absoluteZ);
|
||||
entity.setPos(absoluteX, absoluteY, absoluteZ);
|
||||
entity.setVelocity(side.xOffset * .1, side.yOffset * 0.1, side.zOffset * 0.1);
|
||||
|
||||
// Try to spawn it and destroy it in case it's not possible
|
||||
|
||||
Reference in New Issue
Block a user