bring back JEI compat

This commit is contained in:
Ell 2021-12-19 17:27:21 +01:00
parent 5dfeb8ad48
commit b34e6d2418
5 changed files with 79 additions and 79 deletions

View file

@ -24,7 +24,7 @@ if (System.getenv('BUILD_NUMBER') != null) {
java.toolchain.languageVersion = JavaLanguageVersion.of(17) java.toolchain.languageVersion = JavaLanguageVersion.of(17)
minecraft { minecraft {
mappings channel: 'official', version: '1.18' mappings channel: 'official', version: '1.18.1'
runs { runs {
client { client {
@ -105,12 +105,11 @@ configurations {
} }
dependencies { dependencies {
minecraft 'net.minecraftforge:forge:1.18-38.0.8' minecraft 'net.minecraftforge:forge:1.18.1-39.0.5'
embed 'org.jgrapht:jgrapht-core:1.5.1' embed 'org.jgrapht:jgrapht-core:1.5.1'
// TODO JEI? it's not updated to 1.18 yet :( compileOnly fg.deobf("mezz.jei:jei-1.18.1:9.1.0.47:api")
/* compileOnly fg.deobf("mezz.jei:jei-1.16.2:7.3.2.25:api") runtimeOnly fg.deobf("mezz.jei:jei-1.18.1:9.1.0.47")
runtimeOnly fg.deobf("mezz.jei:jei-1.16.2:7.3.2.25")*/
// to test the rf requiring and crafting stuff // to test the rf requiring and crafting stuff
/* runtimeOnly fg.deobf("curse.maven:powah-352656:3057732") /* runtimeOnly fg.deobf("curse.maven:powah-352656:3057732")

View file

@ -1,4 +1,3 @@
/*
package de.ellpeck.prettypipes.compat.jei; package de.ellpeck.prettypipes.compat.jei;
import de.ellpeck.prettypipes.misc.ItemEquality; import de.ellpeck.prettypipes.misc.ItemEquality;
@ -6,38 +5,42 @@ import de.ellpeck.prettypipes.packets.PacketCraftingModuleTransfer;
import de.ellpeck.prettypipes.packets.PacketHandler; import de.ellpeck.prettypipes.packets.PacketHandler;
import de.ellpeck.prettypipes.pipe.modules.craft.CraftingModuleContainer; import de.ellpeck.prettypipes.pipe.modules.craft.CraftingModuleContainer;
import mezz.jei.api.gui.IRecipeLayout; 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.IRecipeTransferError;
import mezz.jei.api.recipe.transfer.IRecipeTransferHandler; import mezz.jei.api.recipe.transfer.IRecipeTransferHandler;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.CraftingRecipe;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class CraftingModuleTransferHandler implements IRecipeTransferHandler<CraftingModuleContainer> { public class CraftingModuleTransferHandler implements IRecipeTransferHandler<CraftingModuleContainer, CraftingRecipe> {
@Override @Override
public Class<CraftingModuleContainer> getContainerClass() { public Class<CraftingModuleContainer> getContainerClass() {
return CraftingModuleContainer.class; return CraftingModuleContainer.class;
} }
@Override @Override
public IRecipeTransferError transferRecipe(CraftingModuleContainer container, Object recipe, IRecipeLayout recipeLayout, PlayerEntity player, boolean maxTransfer, boolean doTransfer) { public Class<CraftingRecipe> getRecipeClass() {
return CraftingRecipe.class;
}
@Override
public IRecipeTransferError transferRecipe(CraftingModuleContainer container, CraftingRecipe recipe, IRecipeLayout recipeLayout, Player player, boolean maxTransfer, boolean doTransfer) {
if (!doTransfer) if (!doTransfer)
return null; return null;
Map<Integer, ? extends IGuiIngredient<ItemStack>> ings = recipeLayout.getItemStacks().getGuiIngredients(); var ingredients = recipeLayout.getItemStacks().getGuiIngredients();
List<ItemStack> inputs = new ArrayList<>(); var inputs = new ArrayList<ItemStack>();
List<ItemStack> outputs = new ArrayList<>(); var outputs = new ArrayList<ItemStack>();
for (Map.Entry<Integer, ? extends IGuiIngredient<ItemStack>> entry : ings.entrySet()) { for (var entry : ingredients.entrySet()) {
List<ItemStack> allIngredients = entry.getValue().getAllIngredients(); var allIngredients = entry.getValue().getAllIngredients();
if (allIngredients.isEmpty()) if (allIngredients.isEmpty())
continue; continue;
ItemStack remain = allIngredients.get(0).copy(); var remain = allIngredients.get(0).copy();
List<ItemStack> toAdd = entry.getValue().isInput() ? inputs : outputs; var toAdd = entry.getValue().isInput() ? inputs : outputs;
for (ItemStack stack : toAdd) { for (var stack : toAdd) {
if (ItemEquality.compareItems(stack, remain)) { if (ItemEquality.compareItems(stack, remain)) {
int fits = Math.min(stack.getMaxStackSize() - stack.getCount(), remain.getCount()); var fits = Math.min(stack.getMaxStackSize() - stack.getCount(), remain.getCount());
stack.grow(fits); stack.grow(fits);
remain.shrink(fits); remain.shrink(fits);
if (remain.isEmpty()) if (remain.isEmpty())
@ -51,4 +54,3 @@ public class CraftingModuleTransferHandler implements IRecipeTransferHandler<Cra
return null; return null;
} }
} }
*/

View file

@ -1,43 +1,43 @@
/*
package de.ellpeck.prettypipes.compat.jei; package de.ellpeck.prettypipes.compat.jei;
import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ListMultimap; import com.google.common.collect.ListMultimap;
import de.ellpeck.prettypipes.packets.PacketGhostSlot; import de.ellpeck.prettypipes.packets.PacketGhostSlot;
import de.ellpeck.prettypipes.packets.PacketHandler; import de.ellpeck.prettypipes.packets.PacketHandler;
import de.ellpeck.prettypipes.terminal.CraftingTerminalTileEntity;
import de.ellpeck.prettypipes.terminal.ItemTerminalTileEntity;
import de.ellpeck.prettypipes.terminal.containers.CraftingTerminalContainer; import de.ellpeck.prettypipes.terminal.containers.CraftingTerminalContainer;
import mezz.jei.api.gui.IRecipeLayout; 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.IRecipeTransferError;
import mezz.jei.api.recipe.transfer.IRecipeTransferHandler; import mezz.jei.api.recipe.transfer.IRecipeTransferHandler;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.world.entity.player.Player;
import net.minecraft.inventory.container.Slot;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.CraftingRecipe;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.Map;
public class CraftingTerminalTransferHandler implements IRecipeTransferHandler<CraftingTerminalContainer> { public class CraftingTerminalTransferHandler implements IRecipeTransferHandler<CraftingTerminalContainer, CraftingRecipe> {
@Override @Override
public Class<CraftingTerminalContainer> getContainerClass() { public Class<CraftingTerminalContainer> getContainerClass() {
return CraftingTerminalContainer.class; return CraftingTerminalContainer.class;
} }
@Override
public Class<CraftingRecipe> getRecipeClass() {
return CraftingRecipe.class;
}
@Nullable @Nullable
@Override @Override
public IRecipeTransferError transferRecipe(CraftingTerminalContainer container, IRecipeLayout recipeLayout, PlayerEntity player, boolean maxTransfer, boolean doTransfer) { public IRecipeTransferError transferRecipe(CraftingTerminalContainer container, CraftingRecipe recipe, IRecipeLayout recipeLayout, Player player, boolean maxTransfer, boolean doTransfer) {
if (!doTransfer) if (!doTransfer)
return null; return null;
ListMultimap<Integer, ItemStack> stacks = ArrayListMultimap.create(); ListMultimap<Integer, ItemStack> stacks = ArrayListMultimap.create();
Map<Integer, ? extends IGuiIngredient<ItemStack>> ings = recipeLayout.getItemStacks().getGuiIngredients(); var ingredients = recipeLayout.getItemStacks().getGuiIngredients();
for (Map.Entry<Integer, ? extends IGuiIngredient<ItemStack>> entry : ings.entrySet()) { for (var entry : ingredients.entrySet()) {
if (entry.getValue().isInput()) if (entry.getValue().isInput())
stacks.putAll(entry.getKey() - 1, entry.getValue().getAllIngredients()); stacks.putAll(entry.getKey() - 1, entry.getValue().getAllIngredients());
} }
PacketHandler.sendToServer(new PacketGhostSlot(container.getTile().getPos(), stacks)); PacketHandler.sendToServer(new PacketGhostSlot(container.getTile().getBlockPos(), stacks));
return null; return null;
} }
} }
*/

View file

@ -1,4 +1,3 @@
/*
package de.ellpeck.prettypipes.compat.jei; package de.ellpeck.prettypipes.compat.jei;
import de.ellpeck.prettypipes.PrettyPipes; import de.ellpeck.prettypipes.PrettyPipes;
@ -10,20 +9,15 @@ import mezz.jei.api.constants.VanillaRecipeCategoryUid;
import mezz.jei.api.gui.handlers.IGuiContainerHandler; import mezz.jei.api.gui.handlers.IGuiContainerHandler;
import mezz.jei.api.registration.IGuiHandlerRegistration; import mezz.jei.api.registration.IGuiHandlerRegistration;
import mezz.jei.api.registration.IRecipeTransferRegistration; import mezz.jei.api.registration.IRecipeTransferRegistration;
import mezz.jei.api.runtime.IIngredientFilter;
import mezz.jei.api.runtime.IJeiRuntime; import mezz.jei.api.runtime.IJeiRuntime;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.widget.button.Button; import net.minecraft.client.renderer.Rect2i;
import net.minecraft.client.renderer.Rectangle2d; import net.minecraft.network.chat.TextComponent;
import net.minecraft.client.resources.I18n; import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.text.StringTextComponent; import net.minecraftforge.client.event.ScreenEvent;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraftforge.client.event.GuiScreenEvent;
import net.minecraftforge.client.event.GuiScreenEvent.DrawScreenEvent;
import net.minecraftforge.client.event.GuiScreenEvent.InitGuiEvent;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.TickEvent.ClientTickEvent; import net.minecraftforge.event.TickEvent.ClientTickEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
@ -61,48 +55,46 @@ public class JEIPrettyPipesPlugin implements IModPlugin {
@Override @Override
public void registerGuiHandlers(IGuiHandlerRegistration registration) { public void registerGuiHandlers(IGuiHandlerRegistration registration) {
registration.addGuiContainerHandler(ItemTerminalGui.class, new IGuiContainerHandler<ItemTerminalGui>() { registration.addGuiContainerHandler(ItemTerminalGui.class, new IGuiContainerHandler<>() {
@Override @Override
public List<Rectangle2d> getGuiExtraAreas(ItemTerminalGui containerScreen) { public List<Rect2i> getGuiExtraAreas(ItemTerminalGui containerScreen) {
List<Rectangle2d> ret = new ArrayList<>(); List<Rect2i> ret = new ArrayList<>();
// sorting buttons // sorting buttons
ret.add(new Rectangle2d(containerScreen.getGuiLeft() - 22, containerScreen.getGuiTop(), 22, 64)); ret.add(new Rect2i(containerScreen.getGuiLeft() - 22, containerScreen.getGuiTop(), 22, 64));
// crafting hud // crafting hud
if (containerScreen.currentlyCrafting != null && !containerScreen.currentlyCrafting.isEmpty()) if (containerScreen.currentlyCrafting != null && !containerScreen.currentlyCrafting.isEmpty())
ret.add(new Rectangle2d(containerScreen.getGuiLeft() + containerScreen.getXSize(), containerScreen.getGuiTop() + 4, 65, 89)); ret.add(new Rect2i(containerScreen.getGuiLeft() + containerScreen.getXSize(), containerScreen.getGuiTop() + 4, 65, 89));
return ret; return ret;
} }
}); });
} }
@SubscribeEvent @SubscribeEvent
public void onInitGui(InitGuiEvent.Post event) { public void onInitGui(ScreenEvent.InitScreenEvent.Post event) {
Screen screen = event.getGui(); var screen = event.getScreen();
if (!(screen instanceof ItemTerminalGui)) if (!(screen instanceof ItemTerminalGui terminal))
return; return;
ItemTerminalGui terminal = (ItemTerminalGui) screen; terminal.addRenderableWidget(this.jeiSyncButton = new Button(terminal.getGuiLeft() - 22, terminal.getGuiTop() + 44, 20, 20, new TextComponent(""), button -> {
event.addWidget(this.jeiSyncButton = new Button(terminal.getGuiLeft() - 22, terminal.getGuiTop() + 44, 20, 20, new StringTextComponent(""), button -> { var preferences = PlayerPrefs.get();
PlayerPrefs prefs = PlayerPrefs.get(); preferences.syncJei = !preferences.syncJei;
prefs.syncJei = !prefs.syncJei; preferences.save();
prefs.save();
terminal.updateWidgets(); terminal.updateWidgets();
})); }));
if (PlayerPrefs.get().syncJei) if (PlayerPrefs.get().syncJei)
terminal.search.setText(this.runtime.getIngredientFilter().getFilterText()); terminal.search.setValue(this.runtime.getIngredientFilter().getFilterText());
} }
@SubscribeEvent @SubscribeEvent
public void onRenderGui(DrawScreenEvent event) { public void onRenderGui(ScreenEvent.DrawScreenEvent event) {
Screen screen = event.getGui(); var screen = event.getScreen();
if (!(screen instanceof ItemTerminalGui)) if (!(screen instanceof ItemTerminalGui terminal))
return; return;
ItemTerminalGui terminal = (ItemTerminalGui) screen; var sync = PlayerPrefs.get().syncJei;
boolean sync = PlayerPrefs.get().syncJei; if (event instanceof ScreenEvent.DrawScreenEvent.Post) {
if (event instanceof DrawScreenEvent.Post) { if (this.jeiSyncButton.isHoveredOrFocused())
if (this.jeiSyncButton.isHovered()) terminal.renderTooltip(event.getPoseStack(), new TranslatableComponent("info." + PrettyPipes.ID + ".sync_jei." + (sync ? "on" : "off")), event.getMouseX(), event.getMouseY());
terminal.renderTooltip(event.getMatrixStack(), new TranslationTextComponent("info." + PrettyPipes.ID + ".sync_jei." + (sync ? "on" : "off")), event.getMouseX(), event.getMouseY()); } else if (event instanceof ScreenEvent.DrawScreenEvent.Pre) {
} else if (event instanceof DrawScreenEvent.Pre) { this.jeiSyncButton.setMessage(new TextComponent((sync ? ChatFormatting.GREEN : ChatFormatting.RED) + "J"));
this.jeiSyncButton.setMessage(new StringTextComponent((sync ? TextFormatting.GREEN : TextFormatting.RED) + "J"));
} }
} }
@ -111,21 +103,20 @@ public class JEIPrettyPipesPlugin implements IModPlugin {
if (!PlayerPrefs.get().syncJei) if (!PlayerPrefs.get().syncJei)
return; return;
Screen screen = Minecraft.getInstance().currentScreen; var screen = Minecraft.getInstance().screen;
if (!(screen instanceof ItemTerminalGui)) { if (!(screen instanceof ItemTerminalGui terminal)) {
this.lastTerminalText = null; this.lastTerminalText = null;
this.lastJeiText = null; this.lastJeiText = null;
return; return;
} }
ItemTerminalGui terminal = (ItemTerminalGui) screen; var filter = this.runtime.getIngredientFilter();
IIngredientFilter filter = this.runtime.getIngredientFilter(); var terminalText = terminal.search.getValue();
String terminalText = terminal.search.getText(); var jeiText = filter.getFilterText();
String jeiText = filter.getFilterText();
if (!jeiText.equals(this.lastJeiText)) { if (!jeiText.equals(this.lastJeiText)) {
this.lastTerminalText = jeiText; this.lastTerminalText = jeiText;
this.lastJeiText = jeiText; this.lastJeiText = jeiText;
terminal.search.setText(jeiText); terminal.search.setValue(jeiText);
} else if (!terminalText.equals(this.lastTerminalText)) { } else if (!terminalText.equals(this.lastTerminalText)) {
this.lastTerminalText = terminalText; this.lastTerminalText = terminalText;
this.lastJeiText = terminalText; this.lastJeiText = terminalText;
@ -133,4 +124,3 @@ public class JEIPrettyPipesPlugin implements IModPlugin {
} }
} }
} }
*/

View file

@ -12,6 +12,9 @@ import de.ellpeck.prettypipes.packets.PacketRequest;
import joptsimple.internal.Strings; import joptsimple.internal.Strings;
import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.components.EditBox; import net.minecraft.client.gui.components.EditBox;
import net.minecraft.client.gui.components.Widget;
import net.minecraft.client.gui.components.events.GuiEventListener;
import net.minecraft.client.gui.narration.NarratableEntry;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.client.renderer.GameRenderer; import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.resources.language.I18n; import net.minecraft.client.resources.language.I18n;
@ -362,6 +365,12 @@ public class ItemTerminalGui extends AbstractContainerScreen<ItemTerminalContain
return true; return true;
} }
@Override
public <T extends GuiEventListener & Widget & NarratableEntry> T addRenderableWidget(T p_169406_) {
// overriding to public for JEIPrettyPipesPlugin
return super.addRenderableWidget(p_169406_);
}
public Stream<ItemTerminalWidget> streamWidgets() { public Stream<ItemTerminalWidget> streamWidgets() {
return this.renderables.stream() return this.renderables.stream()
.filter(w -> w instanceof ItemTerminalWidget) .filter(w -> w instanceof ItemTerminalWidget)