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)
minecraft {
mappings channel: 'official', version: '1.18'
mappings channel: 'official', version: '1.18.1'
runs {
client {
@ -105,12 +105,11 @@ configurations {
}
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'
// TODO JEI? it's not updated to 1.18 yet :(
/* compileOnly fg.deobf("mezz.jei:jei-1.16.2:7.3.2.25:api")
runtimeOnly fg.deobf("mezz.jei:jei-1.16.2:7.3.2.25")*/
compileOnly fg.deobf("mezz.jei:jei-1.18.1:9.1.0.47:api")
runtimeOnly fg.deobf("mezz.jei:jei-1.18.1:9.1.0.47")
// to test the rf requiring and crafting stuff
/* runtimeOnly fg.deobf("curse.maven:powah-352656:3057732")

View file

@ -1,4 +1,3 @@
/*
package de.ellpeck.prettypipes.compat.jei;
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.pipe.modules.craft.CraftingModuleContainer;
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 net.minecraft.entity.player.PlayerEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.CraftingRecipe;
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
public Class<CraftingModuleContainer> getContainerClass() {
return CraftingModuleContainer.class;
}
@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)
return null;
Map<Integer, ? extends IGuiIngredient<ItemStack>> ings = recipeLayout.getItemStacks().getGuiIngredients();
List<ItemStack> inputs = new ArrayList<>();
List<ItemStack> outputs = new ArrayList<>();
for (Map.Entry<Integer, ? extends IGuiIngredient<ItemStack>> entry : ings.entrySet()) {
List<ItemStack> allIngredients = entry.getValue().getAllIngredients();
var ingredients = recipeLayout.getItemStacks().getGuiIngredients();
var inputs = new ArrayList<ItemStack>();
var outputs = new ArrayList<ItemStack>();
for (var entry : ingredients.entrySet()) {
var allIngredients = entry.getValue().getAllIngredients();
if (allIngredients.isEmpty())
continue;
ItemStack remain = allIngredients.get(0).copy();
List<ItemStack> toAdd = entry.getValue().isInput() ? inputs : outputs;
for (ItemStack stack : toAdd) {
var remain = allIngredients.get(0).copy();
var toAdd = entry.getValue().isInput() ? inputs : outputs;
for (var stack : toAdd) {
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);
remain.shrink(fits);
if (remain.isEmpty())
@ -51,4 +54,3 @@ public class CraftingModuleTransferHandler implements IRecipeTransferHandler<Cra
return null;
}
}
*/

View file

@ -1,43 +1,43 @@
/*
package de.ellpeck.prettypipes.compat.jei;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ListMultimap;
import de.ellpeck.prettypipes.packets.PacketGhostSlot;
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 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 net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.container.Slot;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.CraftingRecipe;
import javax.annotation.Nullable;
import java.util.Map;
public class CraftingTerminalTransferHandler implements IRecipeTransferHandler<CraftingTerminalContainer> {
public class CraftingTerminalTransferHandler implements IRecipeTransferHandler<CraftingTerminalContainer, CraftingRecipe> {
@Override
public Class<CraftingTerminalContainer> getContainerClass() {
return CraftingTerminalContainer.class;
}
@Override
public Class<CraftingRecipe> getRecipeClass() {
return CraftingRecipe.class;
}
@Nullable
@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)
return null;
ListMultimap<Integer, ItemStack> stacks = ArrayListMultimap.create();
Map<Integer, ? extends IGuiIngredient<ItemStack>> ings = recipeLayout.getItemStacks().getGuiIngredients();
for (Map.Entry<Integer, ? extends IGuiIngredient<ItemStack>> entry : ings.entrySet()) {
var ingredients = recipeLayout.getItemStacks().getGuiIngredients();
for (var entry : ingredients.entrySet()) {
if (entry.getValue().isInput())
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;
}
}
*/

View file

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