mirror of
https://github.com/GTNewHorizons/AE2FluidCraft-Rework.git
synced 2026-11-23 05:19:49 +00:00
* gradle updateBuildScript * fix comments and commented-out code Code deletion, converting comments into javadocs, and refactoring code to not need comments. * remove redundant suppressions * replace C-style array declaration with Java-style * make private field final * remove unnecessary semicolon * extract a common part from an if * simplify boolean expression * simplify ternary if * remove unused imports * convert escaped characters for clarity * replace while with for * replace explicit types with diamond operators * replace anonymous type with lambda * enable modern Java syntax * migrate to enhanced switch * migrate to pattern variables for instanceof * remove empty javadoc * add Nonnull annotation to overrides of Nonnull methods * replace wailaStack with null When wailaStack is not null, the flow breaks out of the loop, so there's no need to confuse the reader with putting wailaStack both as the result and the parameter of the call - there's no recursion. * int cannot be bigger than its max value * suppress dataflow warning * remove redundant initializer The default value of int is 0. * null check is covered by instanceof * simplify some calls of addVertexWithUV * fix typos and add TODOs * make flipState more understandable
77 lines
3.4 KiB
Java
77 lines
3.4 KiB
Java
package com.glodblock.github.nei;
|
|
|
|
import java.io.IOException;
|
|
import java.util.LinkedList;
|
|
import java.util.List;
|
|
|
|
import net.minecraft.client.gui.inventory.GuiContainer;
|
|
import net.minecraft.inventory.Slot;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
import net.minecraft.nbt.NBTTagList;
|
|
|
|
import com.glodblock.github.client.gui.GuiFluidCraftingWireless;
|
|
|
|
import appeng.container.slot.SlotCraftingMatrix;
|
|
import appeng.container.slot.SlotFakeCraftingMatrix;
|
|
import appeng.core.sync.network.NetworkHandler;
|
|
import appeng.core.sync.packets.PacketNEIRecipe;
|
|
import appeng.util.Platform;
|
|
import codechicken.nei.PositionedStack;
|
|
import codechicken.nei.api.IOverlayHandler;
|
|
import codechicken.nei.recipe.IRecipeHandler;
|
|
|
|
public class FluidCraftingTransferHandler implements IOverlayHandler {
|
|
|
|
public static final FluidCraftingTransferHandler INSTANCE = new FluidCraftingTransferHandler();
|
|
|
|
@Override
|
|
public void overlayRecipe(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex, boolean shift) {
|
|
try {
|
|
final List<PositionedStack> ingredients = recipe.getIngredientStacks(recipeIndex);
|
|
if (firstGui instanceof GuiFluidCraftingWireless
|
|
&& FluidPatternTerminalRecipeTransferHandler.craftSet.contains(recipe.getOverlayIdentifier())) {
|
|
PacketNEIRecipe packet = new PacketNEIRecipe(packIngredients(firstGui, ingredients));
|
|
NetworkHandler.instance.sendToServer(packet);
|
|
}
|
|
} catch (final Exception | Error ignored) {
|
|
// NO-OP
|
|
}
|
|
}
|
|
|
|
private NBTTagCompound packIngredients(GuiContainer gui, List<PositionedStack> ingredients) throws IOException {
|
|
final NBTTagCompound recipe = new NBTTagCompound();
|
|
for (final PositionedStack positionedStack : ingredients) {
|
|
final int col = (positionedStack.relx - 25) / 18;
|
|
final int row = (positionedStack.rely - 6) / 18;
|
|
if (positionedStack.items != null && positionedStack.items.length > 0) {
|
|
for (final Object o : gui.inventorySlots.inventorySlots) {
|
|
if (o instanceof SlotCraftingMatrix || o instanceof SlotFakeCraftingMatrix) {
|
|
Slot slot = (Slot) o;
|
|
if (slot.getSlotIndex() == col + row * 3) {
|
|
final NBTTagList tags = new NBTTagList();
|
|
final List<ItemStack> list = new LinkedList<>();
|
|
// prefer pure crystals.
|
|
for (int x = 0; x < positionedStack.items.length; x++) {
|
|
if (Platform.isRecipePrioritized(positionedStack.items[x])) {
|
|
list.add(0, positionedStack.items[x]);
|
|
} else {
|
|
list.add(positionedStack.items[x]);
|
|
}
|
|
}
|
|
for (final ItemStack is : list) {
|
|
final NBTTagCompound tag = new NBTTagCompound();
|
|
is.writeToNBT(tag);
|
|
tags.appendTag(tag);
|
|
}
|
|
recipe.setTag("#" + slot.getSlotIndex(), tags);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return recipe;
|
|
}
|
|
}
|