mirror of
https://github.com/Ellpeck/PrettyPipes.git
synced 2024-11-25 21:18:34 +01:00
JEI integration
This commit is contained in:
parent
27e25fbedf
commit
4e05fe660e
6 changed files with 106 additions and 45 deletions
|
@ -108,7 +108,7 @@ dependencies {
|
|||
minecraft 'net.minecraftforge:forge:1.19-41.0.45'
|
||||
embed 'org.jgrapht:jgrapht-core:1.5.1'
|
||||
|
||||
compileOnly fg.deobf("mezz.jei:jei-1.19-forge-api:11.0.0.206")
|
||||
compileOnly fg.deobf("mezz.jei:jei-1.19-common-api:11.0.0.206")
|
||||
runtimeOnly fg.deobf("mezz.jei:jei-1.19-forge:11.0.0.206")
|
||||
|
||||
// to test the rf requiring and crafting stuff
|
||||
|
|
|
@ -1,7 +1,26 @@
|
|||
package de.ellpeck.prettypipes.compat.jei;
|
||||
|
||||
// TODO JEI
|
||||
/*
|
||||
import de.ellpeck.prettypipes.Registry;
|
||||
import de.ellpeck.prettypipes.misc.ItemEquality;
|
||||
import de.ellpeck.prettypipes.packets.PacketCraftingModuleTransfer;
|
||||
import de.ellpeck.prettypipes.packets.PacketHandler;
|
||||
import de.ellpeck.prettypipes.pipe.modules.craft.CraftingModuleContainer;
|
||||
import mezz.jei.api.constants.RecipeTypes;
|
||||
import mezz.jei.api.constants.VanillaTypes;
|
||||
import mezz.jei.api.gui.ingredient.IRecipeSlotsView;
|
||||
import mezz.jei.api.recipe.RecipeIngredientRole;
|
||||
import mezz.jei.api.recipe.RecipeType;
|
||||
import mezz.jei.api.recipe.transfer.IRecipeTransferError;
|
||||
import mezz.jei.api.recipe.transfer.IRecipeTransferHandler;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.crafting.CraftingRecipe;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Optional;
|
||||
|
||||
public class CraftingModuleTransferHandler implements IRecipeTransferHandler<CraftingModuleContainer, CraftingRecipe> {
|
||||
|
||||
@Override
|
||||
|
@ -10,23 +29,27 @@ public class CraftingModuleTransferHandler implements IRecipeTransferHandler<Cra
|
|||
}
|
||||
|
||||
@Override
|
||||
public Class<CraftingRecipe> getRecipeClass() {
|
||||
return CraftingRecipe.class;
|
||||
public Optional<MenuType<CraftingModuleContainer>> getMenuType() {
|
||||
return Optional.of(Registry.craftingModuleContainer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRecipeTransferError transferRecipe(CraftingModuleContainer container, CraftingRecipe recipe, IRecipeLayout recipeLayout, Player player, boolean maxTransfer, boolean doTransfer) {
|
||||
public RecipeType<CraftingRecipe> getRecipeType() {
|
||||
return RecipeTypes.CRAFTING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable IRecipeTransferError transferRecipe(CraftingModuleContainer container, CraftingRecipe recipe, IRecipeSlotsView slots, Player player, boolean maxTransfer, boolean doTransfer) {
|
||||
if (!doTransfer)
|
||||
return null;
|
||||
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();
|
||||
for (var entry : slots.getSlotViews()) {
|
||||
var allIngredients = entry.getIngredients(VanillaTypes.ITEM_STACK).toList();
|
||||
if (allIngredients.isEmpty())
|
||||
continue;
|
||||
var remain = allIngredients.get(0).copy();
|
||||
var toAdd = entry.getValue().isInput() ? inputs : outputs;
|
||||
var toAdd = entry.getRole() == RecipeIngredientRole.INPUT ? inputs : outputs;
|
||||
for (var stack : toAdd) {
|
||||
if (ItemEquality.compareItems(stack, remain)) {
|
||||
var fits = Math.min(stack.getMaxStackSize() - stack.getCount(), remain.getCount());
|
||||
|
@ -43,4 +66,3 @@ public class CraftingModuleTransferHandler implements IRecipeTransferHandler<Cra
|
|||
return null;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
|
|
@ -1,7 +1,26 @@
|
|||
package de.ellpeck.prettypipes.compat.jei;
|
||||
|
||||
// TODO JEI
|
||||
/*
|
||||
import de.ellpeck.prettypipes.Registry;
|
||||
import de.ellpeck.prettypipes.packets.PacketGhostSlot;
|
||||
import de.ellpeck.prettypipes.packets.PacketHandler;
|
||||
import de.ellpeck.prettypipes.terminal.containers.CraftingTerminalContainer;
|
||||
import mezz.jei.api.constants.RecipeTypes;
|
||||
import mezz.jei.api.constants.VanillaTypes;
|
||||
import mezz.jei.api.gui.ingredient.IRecipeSlotsView;
|
||||
import mezz.jei.api.recipe.RecipeIngredientRole;
|
||||
import mezz.jei.api.recipe.RecipeType;
|
||||
import mezz.jei.api.recipe.transfer.IRecipeTransferError;
|
||||
import mezz.jei.api.recipe.transfer.IRecipeTransferHandler;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraft.world.item.crafting.CraftingRecipe;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CraftingTerminalTransferHandler implements IRecipeTransferHandler<CraftingTerminalContainer, CraftingRecipe> {
|
||||
|
||||
@Override
|
||||
|
@ -10,23 +29,24 @@ public class CraftingTerminalTransferHandler implements IRecipeTransferHandler<C
|
|||
}
|
||||
|
||||
@Override
|
||||
public Class<CraftingRecipe> getRecipeClass() {
|
||||
return CraftingRecipe.class;
|
||||
public Optional<MenuType<CraftingTerminalContainer>> getMenuType() {
|
||||
return Optional.of(Registry.craftingTerminalContainer);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IRecipeTransferError transferRecipe(CraftingTerminalContainer container, CraftingRecipe recipe, IRecipeLayout recipeLayout, Player player, boolean maxTransfer, boolean doTransfer) {
|
||||
public RecipeType<CraftingRecipe> getRecipeType() {
|
||||
return RecipeTypes.CRAFTING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable IRecipeTransferError transferRecipe(CraftingTerminalContainer container, CraftingRecipe recipe, IRecipeSlotsView slots, Player player, boolean maxTransfer, boolean doTransfer) {
|
||||
if (!doTransfer)
|
||||
return null;
|
||||
Map<Integer, PacketGhostSlot.Entry> stacks = new HashMap<>();
|
||||
var ingredients = recipeLayout.getItemStacks().getGuiIngredients();
|
||||
for (var entry : ingredients.entrySet()) {
|
||||
if (entry.getValue().isInput())
|
||||
stacks.put(entry.getKey() - 1, new PacketGhostSlot.Entry(entry.getValue().getAllIngredients()));
|
||||
}
|
||||
List<PacketGhostSlot.Entry> stacks = new ArrayList<>();
|
||||
var ingredients = slots.getSlotViews(RecipeIngredientRole.INPUT);
|
||||
for (var entry : ingredients)
|
||||
stacks.add(new PacketGhostSlot.Entry(entry.getIngredients(VanillaTypes.ITEM_STACK).collect(Collectors.toList())));
|
||||
PacketHandler.sendToServer(new PacketGhostSlot(container.getTile().getBlockPos(), stacks));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
|
|
@ -1,7 +1,30 @@
|
|||
package de.ellpeck.prettypipes.compat.jei;
|
||||
|
||||
// TODO JEI
|
||||
/*@JeiPlugin
|
||||
import de.ellpeck.prettypipes.PrettyPipes;
|
||||
import de.ellpeck.prettypipes.misc.PlayerPrefs;
|
||||
import de.ellpeck.prettypipes.terminal.containers.ItemTerminalGui;
|
||||
import mezz.jei.api.IModPlugin;
|
||||
import mezz.jei.api.JeiPlugin;
|
||||
import mezz.jei.api.constants.RecipeTypes;
|
||||
import mezz.jei.api.gui.handlers.IGuiContainerHandler;
|
||||
import mezz.jei.api.registration.IGuiHandlerRegistration;
|
||||
import mezz.jei.api.registration.IRecipeTransferRegistration;
|
||||
import mezz.jei.api.runtime.IJeiRuntime;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.components.Button;
|
||||
import net.minecraft.client.renderer.Rect2i;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraftforge.client.event.ScreenEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.TickEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@JeiPlugin
|
||||
public class JEIPrettyPipesPlugin implements IModPlugin {
|
||||
|
||||
private IJeiRuntime runtime;
|
||||
|
@ -25,7 +48,7 @@ public class JEIPrettyPipesPlugin implements IModPlugin {
|
|||
|
||||
@Override
|
||||
public void registerRecipeTransferHandlers(IRecipeTransferRegistration registration) {
|
||||
registration.addRecipeTransferHandler(new CraftingTerminalTransferHandler(), VanillaRecipeCategoryUid.CRAFTING);
|
||||
registration.addRecipeTransferHandler(new CraftingTerminalTransferHandler(), RecipeTypes.CRAFTING);
|
||||
registration.addUniversalRecipeTransferHandler(new CraftingModuleTransferHandler());
|
||||
}
|
||||
|
||||
|
@ -50,7 +73,7 @@ public class JEIPrettyPipesPlugin implements IModPlugin {
|
|||
var screen = event.getScreen();
|
||||
if (!(screen instanceof ItemTerminalGui terminal))
|
||||
return;
|
||||
terminal.addRenderableWidget(this.jeiSyncButton = new Button(terminal.getGuiLeft() - 22, terminal.getGuiTop() + 44, 20, 20, new TextComponent(""), button -> {
|
||||
terminal.addRenderableWidget(this.jeiSyncButton = new Button(terminal.getGuiLeft() - 22, terminal.getGuiTop() + 44, 20, 20, Component.literal(""), button -> {
|
||||
var preferences = PlayerPrefs.get();
|
||||
preferences.syncJei = !preferences.syncJei;
|
||||
preferences.save();
|
||||
|
@ -68,14 +91,14 @@ public class JEIPrettyPipesPlugin implements IModPlugin {
|
|||
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());
|
||||
terminal.renderTooltip(event.getPoseStack(), Component.translatable("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"));
|
||||
this.jeiSyncButton.setMessage(Component.literal((sync ? ChatFormatting.GREEN : ChatFormatting.RED) + "J"));
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onClientTick(ClientTickEvent event) {
|
||||
public void onClientTick(TickEvent.ClientTickEvent event) {
|
||||
if (!PlayerPrefs.get().syncJei)
|
||||
return;
|
||||
|
||||
|
@ -99,4 +122,4 @@ public class JEIPrettyPipesPlugin implements IModPlugin {
|
|||
filter.setFilterText(terminalText);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
|
|
@ -17,9 +17,7 @@ import net.minecraft.world.item.Items;
|
|||
import net.minecraftforge.network.NetworkEvent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -27,9 +25,9 @@ import java.util.stream.Collectors;
|
|||
public class PacketGhostSlot {
|
||||
|
||||
private BlockPos pos;
|
||||
private Map<Integer, Entry> stacks;
|
||||
private List<Entry> stacks;
|
||||
|
||||
public PacketGhostSlot(BlockPos pos, Map<Integer, Entry> stacks) {
|
||||
public PacketGhostSlot(BlockPos pos, List<Entry> stacks) {
|
||||
this.pos = pos;
|
||||
this.stacks = stacks;
|
||||
}
|
||||
|
@ -41,19 +39,17 @@ public class PacketGhostSlot {
|
|||
public static PacketGhostSlot fromBytes(FriendlyByteBuf buf) {
|
||||
var packet = new PacketGhostSlot();
|
||||
packet.pos = buf.readBlockPos();
|
||||
packet.stacks = new HashMap<>();
|
||||
packet.stacks = new ArrayList<>();
|
||||
for (var i = buf.readInt(); i > 0; i--)
|
||||
packet.stacks.put(buf.readInt(), new Entry(buf));
|
||||
packet.stacks.add(new Entry(buf));
|
||||
return packet;
|
||||
}
|
||||
|
||||
public static void toBytes(PacketGhostSlot packet, FriendlyByteBuf buf) {
|
||||
buf.writeBlockPos(packet.pos);
|
||||
buf.writeInt(packet.stacks.size());
|
||||
for (var entry : packet.stacks.entrySet()) {
|
||||
buf.writeInt(entry.getKey());
|
||||
entry.getValue().write(buf);
|
||||
}
|
||||
for (var entry : packet.stacks)
|
||||
entry.write(buf);
|
||||
}
|
||||
|
||||
@SuppressWarnings("Convert2Lambda")
|
||||
|
|
|
@ -58,7 +58,7 @@ public class CraftingTerminalBlockEntity extends ItemTerminalBlockEntity {
|
|||
return this.craftItems.getStackInSlot(slot).isEmpty() && !this.ghostItems.getStackInSlot(slot).isEmpty();
|
||||
}
|
||||
|
||||
public void setGhostItems(Map<Integer, PacketGhostSlot.Entry> stacks) {
|
||||
public void setGhostItems(List<PacketGhostSlot.Entry> stacks) {
|
||||
this.updateItems();
|
||||
for (var i = 0; i < this.ghostItems.getSlots(); i++) {
|
||||
var items = stacks.get(i).getStacks();
|
||||
|
@ -95,9 +95,9 @@ public class CraftingTerminalBlockEntity extends ItemTerminalBlockEntity {
|
|||
}
|
||||
|
||||
if (!this.level.isClientSide) {
|
||||
Map<Integer, PacketGhostSlot.Entry> clients = new HashMap<>();
|
||||
List<PacketGhostSlot.Entry> clients = new ArrayList<>();
|
||||
for (var i = 0; i < this.ghostItems.getSlots(); i++)
|
||||
clients.put(i, new PacketGhostSlot.Entry(Collections.singletonList(this.ghostItems.getStackInSlot(i))));
|
||||
clients.add(new PacketGhostSlot.Entry(Collections.singletonList(this.ghostItems.getStackInSlot(i))));
|
||||
PacketHandler.sendToAllLoaded(this.level, this.getBlockPos(), new PacketGhostSlot(this.getBlockPos(), clients));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue