Skip to content

Commit

Permalink
Add dedicated REI support, Closes CyclopsMC/IntegratedDynamics#1348
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensworks committed Dec 6, 2024
1 parent 3f554b1 commit 6e2df56
Show file tree
Hide file tree
Showing 21 changed files with 973 additions and 65 deletions.
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ dependencies {
exclude group: 'org.cyclops.cyclopscore', module: 'cyclopscore'
}

implementation(fg.deobf("mezz.jei:jei-${project.jei_version}")) { // https://dvs1.progwml6.com/files/maven/mezz/jei/
compileOnly(fg.deobf("mezz.jei:jei-${project.jei_version}")) { // https://dvs1.progwml6.com/files/maven/mezz/jei/
transitive = false
}
compileOnly "mcjty.theoneprobe:theoneprobe:${project.theoneprobe_version}" // https://maven.k-4u.nl/mcjty/theoneprobe/theoneprobe/
Expand All @@ -154,9 +154,9 @@ dependencies {

implementation fg.deobf("com.github.glitchfiend:TerraBlender-forge:${project.terrablender_version}")

compileOnly fg.deobf("me.shedaniel:RoughlyEnoughItems-forge:${rei_version}") // https://maven.shedaniel.me/me/shedaniel/RoughlyEnoughItems-forge/
compileOnly fg.deobf("me.shedaniel.cloth:cloth-config-forge:$cloth_config_version");
compileOnly fg.deobf("dev.architectury:architectury-forge:$architectury_version");
implementation fg.deobf("me.shedaniel:RoughlyEnoughItems-forge:${rei_version}") // https://maven.shedaniel.me/me/shedaniel/RoughlyEnoughItems-forge/
implementation fg.deobf("me.shedaniel.cloth:cloth-config-forge:$cloth_config_version");
implementation fg.deobf("dev.architectury:architectury-forge:$architectury_version");

implementation fg.deobf("curse.maven:jade-324717:${jade_version}")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public class GeneralConfig extends DummyConfig {
@ConfigurableProperty(category = "core", comment = "If JEI recipe filling should heuristically try to determine item tags from recipes.", requiresMcRestart = true)
public static boolean jeiHeuristicTags = true;

@ConfigurableProperty(category = "core", comment = "If REI recipe filling should heuristically try to determine item tags from recipes.", requiresMcRestart = true)
public static boolean reiHeuristicTags = true;

/**
* Create a new instance.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package org.cyclops.integrateddynamicscompat.modcompat.common;

import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.registries.ForgeRegistries;
import org.cyclops.cyclopscore.helper.MinecraftHelpers;
import org.cyclops.integrateddynamics.client.gui.container.ContainerScreenLogicProgrammerBase;
import org.cyclops.integrateddynamics.core.helper.L10NValues;
import org.cyclops.integrateddynamics.inventory.container.ContainerLogicProgrammerBase;
import org.cyclops.integrateddynamicscompat.IntegratedDynamicsCompat;
import org.cyclops.integrateddynamicscompat.network.packet.CPacketSetSlot;

import java.text.DecimalFormat;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
* @author rubensworks
*/
public class JeiReiHelpers {

public static ResourceLocation itemsToTag(List<Item> items) {
return ForgeRegistries.ITEMS.tags().stream()
.map(tag -> {
if (tag.stream().collect(Collectors.toList()).equals(items)) {
return Optional.of(tag.getKey().location());
}
return Optional.<ResourceLocation>empty();
})
.filter(Optional::isPresent)
.map(Optional::get)
.findFirst()
.orElse(null);
}

public static void setStackInSlot(ContainerScreenLogicProgrammerBase<?> screen, int slot, ItemStack itemStack) {
ContainerLogicProgrammerBase container = screen.getMenu();
int slotPositionsCount = container.slots.size() - 36 - 4; /* subtract player inv, and 4 fixed slots in LP */
int slotId = container.slots.size() - 36 - slotPositionsCount + slot;
container.setItem(slotId, 0, itemStack.copy());
IntegratedDynamicsCompat._instance.getPacketHandler().sendToServer(
new CPacketSetSlot(container.containerId, slotId, itemStack));
}

public static MutableComponent getDurationSecondsTextComponent(int durationTicks) {
String seconds = new DecimalFormat("#.##").format((double) durationTicks / MinecraftHelpers.SECOND_IN_TICKS);
return Component.translatable("gui.integrateddynamics.jei.category.time.seconds", seconds);
}

public static MutableComponent getEnergyTextComponent(int durationTicks, int energyPerTick) {
return Component.literal(String.format("%,d", durationTicks * energyPerTick))
.append(Component.translatable(L10NValues.GENERAL_ENERGY_UNIT));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,12 @@

import mezz.jei.api.IModPlugin;
import mezz.jei.api.JeiPlugin;
import mezz.jei.api.registration.IGuiHandlerRegistration;
import mezz.jei.api.registration.IRecipeCatalystRegistration;
import mezz.jei.api.registration.IRecipeCategoryRegistration;
import mezz.jei.api.registration.IRecipeRegistration;
import mezz.jei.api.registration.IRecipeTransferRegistration;
import mezz.jei.api.registration.*;
import mezz.jei.api.runtime.IJeiRuntime;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import org.cyclops.cyclopscore.helper.MinecraftHelpers;
import org.cyclops.integrateddynamics.RegistryEntries;
import org.cyclops.integrateddynamics.client.gui.container.ContainerScreenLogicProgrammer;
import org.cyclops.integrateddynamics.client.gui.container.ContainerScreenLogicProgrammerPortable;
import org.cyclops.integrateddynamics.client.gui.container.ContainerScreenMechanicalDryingBasin;
import org.cyclops.integrateddynamics.client.gui.container.ContainerScreenMechanicalSqueezer;
import org.cyclops.integrateddynamics.client.gui.container.ContainerScreenOnTheDynamicsOfIntegration;
import org.cyclops.integrateddynamics.core.helper.L10NValues;
import org.cyclops.integrateddynamics.client.gui.container.*;
import org.cyclops.integrateddynamics.inventory.container.ContainerLogicProgrammer;
import org.cyclops.integrateddynamics.inventory.container.ContainerLogicProgrammerPortable;
import org.cyclops.integrateddynamics.inventory.container.ContainerMechanicalDryingBasin;
Expand All @@ -36,8 +24,6 @@
import org.cyclops.integrateddynamicscompat.modcompat.jei.squeezer.SqueezerRecipeCategory;
import org.cyclops.integrateddynamicscompat.modcompat.jei.squeezer.SqueezerRecipeJEI;

import java.text.DecimalFormat;

/**
* Helper for registering JEI manager.
* @author rubensworks
Expand Down Expand Up @@ -98,14 +84,4 @@ public ResourceLocation getPluginUid() {
public void onRuntimeAvailable(IJeiRuntime jeiRuntime) {
this.jeiRuntime = jeiRuntime;
}

public static MutableComponent getDurationSecondsTextComponent(int durationTicks) {
String seconds = new DecimalFormat("#.##").format((double) durationTicks / MinecraftHelpers.SECOND_IN_TICKS);
return Component.translatable("gui.jei.category.smelting.time.seconds", seconds);
}

public static MutableComponent getEnergyTextComponent(int durationTicks, int energyPerTick) {
return Component.literal(String.format("%,d", durationTicks * energyPerTick))
.append(Component.translatable(L10NValues.GENERAL_ENERGY_UNIT));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import net.minecraft.world.item.ItemStack;
import org.cyclops.integrateddynamics.RegistryEntries;
import org.cyclops.integrateddynamicscompat.Reference;
import org.cyclops.integrateddynamicscompat.modcompat.jei.JEIIntegratedDynamicsConfig;
import org.cyclops.integrateddynamicscompat.modcompat.common.JeiReiHelpers;

import javax.annotation.Nonnull;

Expand Down Expand Up @@ -90,7 +90,7 @@ public void draw(DryingBasinRecipeJEI recipe, IRecipeSlotsView recipeSlotsView,

// Draw duration
Font fontRenderer = Minecraft.getInstance().font;
MutableComponent duration = JEIIntegratedDynamicsConfig.getDurationSecondsTextComponent(recipe.getDuration());
MutableComponent duration = JeiReiHelpers.getDurationSecondsTextComponent(recipe.getDuration());
fontRenderer.draw(matrixStack, duration,
(background.getWidth() - fontRenderer.width(duration)) / 2 + 3, 42, 0xFF808080);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraftforge.common.capabilities.ForgeCapabilities;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.fluids.capability.IFluidHandlerItem;
import org.apache.commons.compress.utils.Lists;
import org.cyclops.cyclopscore.helper.GuiHelpers;
import org.cyclops.integrateddynamics.api.logicprogrammer.ILogicProgrammerElement;
import org.cyclops.integrateddynamics.client.gui.container.ContainerScreenLogicProgrammerBase;
import org.cyclops.integrateddynamics.inventory.container.ContainerLogicProgrammerBase;
import org.cyclops.integrateddynamicscompat.IntegratedDynamicsCompat;
import org.cyclops.integrateddynamicscompat.network.packet.CPacketSetSlot;
import org.cyclops.integrateddynamicscompat.modcompat.common.JeiReiHelpers;

import java.util.List;

Expand All @@ -38,7 +37,7 @@ public <I> List<Target<I>> getTargets(T screen, I ingredient, boolean doStart) {
} else if (ingredient instanceof FluidStack) {
itemStack = new ItemStack(Items.BUCKET);
IFluidHandlerItem fluidHandler = itemStack
.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY)
.getCapability(ForgeCapabilities.FLUID_HANDLER_ITEM)
.orElseThrow(() -> new IllegalStateException("Could not find a fluid handler on the bucket item, some mod must be messing with things."));
fluidHandler.fill((FluidStack) ingredient, IFluidHandler.FluidAction.EXECUTE);
itemStack = fluidHandler.getContainer();
Expand Down Expand Up @@ -68,7 +67,7 @@ public Rect2i getArea() {

@Override
public void accept(I ingredient) {
setStackInSlot(screen, finalSlot, finalItemStack);
JeiReiHelpers.setStackInSlot(screen, finalSlot, finalItemStack);
}
});
}
Expand All @@ -88,13 +87,4 @@ public void onComplete() {
public boolean shouldHighlightTargets() {
return true;
}

protected void setStackInSlot(T screen, int slot, ItemStack itemStack) {
ContainerLogicProgrammerBase container = screen.getMenu();
int slotPositionsCount = container.slots.size() - 36 - 4; /* subtract player inv, and 4 fixed slots in LP */
int slotId = container.slots.size() - 36 - slotPositionsCount + slot;
container.setItem(slotId, 0, itemStack.copy());
IntegratedDynamicsCompat._instance.getPacketHandler().sendToServer(
new CPacketSetSlot(container.containerId, slotId, itemStack));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.registries.ForgeRegistries;
import org.cyclops.integrateddynamics.api.logicprogrammer.ILogicProgrammerElement;
import org.cyclops.integrateddynamics.core.ingredient.ItemMatchProperties;
import org.cyclops.integrateddynamics.core.logicprogrammer.ValueTypeRecipeLPElement;
import org.cyclops.integrateddynamics.inventory.container.ContainerLogicProgrammerBase;
import org.cyclops.integrateddynamicscompat.GeneralConfig;
import org.cyclops.integrateddynamicscompat.IntegratedDynamicsCompat;
import org.cyclops.integrateddynamicscompat.modcompat.common.JeiReiHelpers;
import org.cyclops.integrateddynamicscompat.network.packet.CPacketValueTypeRecipeLPElementSetRecipe;

import javax.annotation.Nullable;
Expand Down Expand Up @@ -87,17 +87,7 @@ protected ResourceLocation getHeuristicItemsTag(IRecipeSlotView jeiIngredient) {
.map(ItemStack::getItem)
.collect(Collectors.toList());
if (items.size() > 1) {
return ForgeRegistries.ITEMS.tags().stream()
.map(tag -> {
if (tag.stream().collect(Collectors.toList()).equals(items)) {
return Optional.of(tag.getKey().location());
}
return Optional.<ResourceLocation>empty();
})
.filter(Optional::isPresent)
.map(Optional::get)
.findFirst()
.orElse(null);
return JeiReiHelpers.itemsToTag(items);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.cyclops.integrateddynamics.RegistryEntries;
import org.cyclops.integrateddynamics.block.BlockMechanicalDryingBasinConfig;
import org.cyclops.integrateddynamicscompat.Reference;
import org.cyclops.integrateddynamicscompat.modcompat.jei.JEIIntegratedDynamicsConfig;
import org.cyclops.integrateddynamicscompat.modcompat.common.JeiReiHelpers;

import javax.annotation.Nonnull;

Expand Down Expand Up @@ -91,10 +91,10 @@ public void draw(MechanicalDryingBasinRecipeJEI recipe, IRecipeSlotsView recipeS

// Draw energy and duration
Font fontRenderer = Minecraft.getInstance().font;
MutableComponent energy = JEIIntegratedDynamicsConfig.getEnergyTextComponent(recipe.getDuration(), BlockMechanicalDryingBasinConfig.consumptionRate);
MutableComponent energy = JeiReiHelpers.getEnergyTextComponent(recipe.getDuration(), BlockMechanicalDryingBasinConfig.consumptionRate);
fontRenderer.draw(matrixStack, energy,
(background.getWidth() - fontRenderer.width(energy)) / 2 + 3, 0, 0xFF808080);
MutableComponent duration = JEIIntegratedDynamicsConfig.getDurationSecondsTextComponent(recipe.getDuration());
MutableComponent duration = JeiReiHelpers.getDurationSecondsTextComponent(recipe.getDuration());
fontRenderer.draw(matrixStack, duration,
(background.getWidth() - fontRenderer.width(duration)) / 2 + 3, 42, 0xFF808080);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import org.cyclops.integrateddynamics.RegistryEntries;
import org.cyclops.integrateddynamics.block.BlockMechanicalDryingBasinConfig;
import org.cyclops.integrateddynamics.block.BlockMechanicalSqueezerConfig;
import org.cyclops.integrateddynamics.core.recipe.type.RecipeSqueezer;
import org.cyclops.integrateddynamicscompat.Reference;
import org.cyclops.integrateddynamicscompat.modcompat.jei.JEIIntegratedDynamicsConfig;
import org.cyclops.integrateddynamicscompat.modcompat.common.JeiReiHelpers;

import javax.annotation.Nonnull;

Expand Down Expand Up @@ -95,10 +95,10 @@ public void draw(MechanicalSqueezerRecipeJEI recipe, IRecipeSlotsView recipeSlot

// Draw energy and duration
Font fontRenderer = Minecraft.getInstance().font;
MutableComponent energy = JEIIntegratedDynamicsConfig.getEnergyTextComponent(recipe.getDuration(), BlockMechanicalDryingBasinConfig.consumptionRate);
MutableComponent energy = JeiReiHelpers.getEnergyTextComponent(recipe.getDuration(), BlockMechanicalSqueezerConfig.consumptionRate);
fontRenderer.draw(matrixStack, energy,
(background.getWidth() - fontRenderer.width(energy)) / 2 - 10, 0, 0xFF808080);
MutableComponent duration = JEIIntegratedDynamicsConfig.getDurationSecondsTextComponent(recipe.getDuration());
MutableComponent duration = JeiReiHelpers.getDurationSecondsTextComponent(recipe.getDuration());
fontRenderer.draw(matrixStack, duration,
(background.getWidth() - fontRenderer.width(duration)) / 2 - 10, 42, 0xFF808080);
}
Expand Down
Loading

0 comments on commit 6e2df56

Please sign in to comment.