Skip to content

Commit

Permalink
fix: Fix more JEI support
Browse files Browse the repository at this point in the history
  • Loading branch information
BlayTheNinth committed Jul 2, 2024
1 parent 70cac85 commit 11cb0d7
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,40 @@
import net.blay09.mods.excompressum.loot.MergedLootTableEntry;
import net.blay09.mods.excompressum.registry.sievemesh.SieveMeshRegistry;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;

import java.util.*;
import java.util.stream.Collectors;

public class ExpandedHeavySieveRecipe {

private final HeavySieveRecipe recipe;
private final List<List<ItemStack>> inputs;
private final Ingredient ingredient;
private final List<ItemStack> meshItems;
private final List<MergedLootTableEntry> outputs;
private final List<ItemStack> outputItems;
private final boolean waterlogged;

public ExpandedHeavySieveRecipe(HeavySieveRecipe recipe) {
this.recipe = recipe;
inputs = new ArrayList<>();
meshItems = new ArrayList<>();
if (recipe.getMinimumMesh() != null) {
SieveMeshRegistryEntry minimumMesh = SieveMeshRegistry.getEntry(recipe.getMinimumMesh());
List<ItemStack> meshItems = new ArrayList<>();
for (SieveMeshRegistryEntry mesh : SieveMeshRegistry.getEntries().values()) {
if (mesh.getMeshLevel() >= minimumMesh.getMeshLevel()) {
meshItems.add(mesh.getItemStack());
}
}
inputs.add(meshItems);
} else if (recipe.getMeshes() != null) {
List<ItemStack> meshItems = new ArrayList<>();
for (CommonMeshType meshType : recipe.getMeshes()) {
for (SieveMeshRegistryEntry mesh : SieveMeshRegistry.getEntries().values()) {
if (mesh.getMeshType() == meshType) {
meshItems.add(mesh.getItemStack());
}
}
}
inputs.add(meshItems);
} else {
inputs.add(Collections.emptyList());
}
inputs.add(Arrays.asList(recipe.getIngredient().getItems()));
ingredient = recipe.getIngredient();
List<LootTableEntry> entries = LootTableUtils.getLootTableEntries(recipe.getLootTable());
outputs = LootTableUtils.mergeLootTableEntries(entries);
outputItems = outputs.stream().map(MergedLootTableEntry::getItemStack).collect(Collectors.toList());
Expand All @@ -56,8 +52,12 @@ public HeavySieveRecipe getRecipe() {
return recipe;
}

public List<List<ItemStack>> getInputs() {
return inputs;
public Ingredient getIngredient() {
return ingredient;
}

public List<ItemStack> getMeshItems() {
return meshItems;
}

public List<MergedLootTableEntry> getOutputs() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import net.minecraft.world.item.ItemStack;

import javax.annotation.Nonnull;
import java.util.List;

public class HeavySieveJeiRecipeCategory implements IRecipeCategory<ExpandedHeavySieveRecipe> {

Expand Down Expand Up @@ -56,12 +57,13 @@ public IDrawable getIcon() {

@Override
public void setRecipe(IRecipeLayoutBuilder recipeLayoutBuilder, ExpandedHeavySieveRecipe recipe, IFocusGroup focusGroup) {
recipeLayoutBuilder.addSlot(RecipeIngredientRole.INPUT, 62, 10);
recipeLayoutBuilder.addSlot(RecipeIngredientRole.INPUT, 88, 10);
for (int i = 0; i < recipe.getOutputItems().size(); i++) {
final int slotX = 3 + i * 18;
final int slotY = 37;
recipeLayoutBuilder.addSlot(RecipeIngredientRole.OUTPUT, slotX, slotY);
recipeLayoutBuilder.addSlot(RecipeIngredientRole.INPUT, 62, 10).addIngredients(recipe.getIngredient());
recipeLayoutBuilder.addSlot(RecipeIngredientRole.INPUT, 88, 10).addItemStacks(recipe.getMeshItems());
final var outputItems = recipe.getOutputItems();
for (int i = 0; i < outputItems.size(); i++) {
final int slotX = 3 + (i % 9 * 18);
final int slotY = 37 + (i / 9 * 18);
recipeLayoutBuilder.addSlot(RecipeIngredientRole.OUTPUT, slotX, slotY).addItemStack(outputItems.get(i));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ private void loadGeneratedHeavySieveRecipe(Level level, boolean waterlogged, Gen

@Override
public void registerRecipeCatalysts(IRecipeCatalystRegistration registry) {
registry.addRecipeCatalyst(new ItemStack(ModBlocks.autoHeavySieve), HeavySieveJeiRecipeCategory.TYPE);
for (final var heavySieve : ModBlocks.heavySieves) {
registry.addRecipeCatalyst(new ItemStack(heavySieve), HeavySieveJeiRecipeCategory.TYPE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ private static String formatChance(LootTableEntry entry) {

private static Component getCountTextComponent(LootTableEntry entry) {
if (entry.getCountRange() instanceof UniformGeneratorAccessor uniform) {
int min = LootTableUtils.getMinCount(uniform.getMin());
int max = LootTableUtils.getMaxCount(uniform.getMax());
int min = (int) LootTableUtils.getMinCount(uniform.getMin());
int max = (int) LootTableUtils.getMaxCount(uniform.getMax());
return Component.translatable("tooltip.jei.drop_count.random_range", min, max);
} else if (entry.getCountRange() instanceof BinomialDistributionGeneratorAccessor binomial) {
int n = LootTableUtils.getMinCount(binomial.getN());
int p = LootTableUtils.getMinCount(binomial.getP());
int n = (int) LootTableUtils.getMinCount(binomial.getN());
int p = (int) LootTableUtils.getMinCount(binomial.getP());
return Component.translatable("tooltip.jei.drop_count.binomial_range", n * p);
} else if (entry.getCountRange() instanceof ConstantValueAccessor constant) {
return Component.translatable("tooltip.jei.drop_count.constant", (int) constant.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import net.minecraft.world.item.ItemStack;

import javax.annotation.Nonnull;
import java.util.List;

public class WoodenCrucibleJeiRecipeCategory implements IRecipeCategory<ExpandedWoodenCrucibleRecipe> {

Expand Down Expand Up @@ -57,12 +58,11 @@ public IDrawable getIcon() {
public void setRecipe(IRecipeLayoutBuilder recipeLayoutBuilder, ExpandedWoodenCrucibleRecipe recipe, IFocusGroup focusGroup) {
recipeLayoutBuilder.addSlot(RecipeIngredientRole.OUTPUT, 75, 10).addFluidStack(recipe.getFluid(), recipe.getFluidStack().getAmount());

int slotNumber = 0;
for (final var itemStack : recipe.getInputs()) {
final int slotX = 3 + (slotNumber % 9 * 18);
final int slotY = 37 + (slotNumber / 9 * 18);
recipeLayoutBuilder.addSlot(RecipeIngredientRole.INPUT, slotX, slotY).addItemStack(itemStack);
slotNumber++;
final var inputs = recipe.getInputs();
for (int i = 0; i < inputs.size(); i++) {
final int slotX = 3 + (i % 9 * 18);
final int slotY = 37 + (i / 9 * 18);
recipeLayoutBuilder.addSlot(RecipeIngredientRole.INPUT, slotX, slotY).addItemStack(inputs.get(i));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ public static List<LootTableEntry> getLootTableEntries(@Nullable LootTable lootT
NumberProvider countRange = getCountRange(entry);
if (entry instanceof LootItemAccessor lootItem) {
ItemStack itemStack = new ItemStack(lootItem.getItem());
itemStack.setCount(getMaxCount(countRange));
itemStack.setCount(Math.max(1, (int) getMaxCount(countRange)));
result.add(new LootTableEntry(itemStack, countRange, baseChance));
} else if (entry instanceof TagEntryAccessor tagEntry) {
TagKey<Item> tag = tagEntry.getTag();
BuiltInRegistries.ITEM.getOrCreateTag(tag).forEach(itemHolder -> {
ItemStack itemStack = new ItemStack(itemHolder.value());
itemStack.setCount(getMaxCount(countRange));
itemStack.setCount(Math.max(1, (int) getMaxCount(countRange)));
result.add(new LootTableEntry(itemStack, countRange, baseChance));
});
}
Expand Down Expand Up @@ -100,25 +100,25 @@ private static NumberProvider getCountRange(LootPoolEntryContainer entry) {
return ConstantValue.exactly(1);
}

public static int getMinCount(NumberProvider range) {
public static float getMinCount(NumberProvider range) {
if (range instanceof UniformGeneratorAccessor uniform) {
return getMinCount(uniform.getMin());
} else if (range instanceof BinomialDistributionGeneratorAccessor binomial) {
return getMinCount(binomial.getN()) * getMaxCount(binomial.getP());
} else if (range instanceof ConstantValueAccessor constant) {
return (int) constant.getValue();
return constant.getValue();
}

return 1;
}

public static int getMaxCount(NumberProvider range) {
public static float getMaxCount(NumberProvider range) {
if (range instanceof UniformGeneratorAccessor uniform) {
return getMaxCount(uniform.getMax());
} else if (range instanceof BinomialDistributionGeneratorAccessor binomial) {
return getMaxCount(binomial.getN()) * getMaxCount(binomial.getP());
} else if (range instanceof ConstantValueAccessor constant) {
return (int) constant.getValue();
return constant.getValue();
}

return 1;
Expand Down

0 comments on commit 11cb0d7

Please sign in to comment.