Skip to content

Commit

Permalink
update to 1.21
Browse files Browse the repository at this point in the history
Forge and NeoForge builds may be broken
  • Loading branch information
way2muchnoise committed Aug 25, 2024
1 parent 02732bb commit 210cee0
Show file tree
Hide file tree
Showing 52 changed files with 491 additions and 487 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
import net.minecraft.world.item.Items;
import net.minecraft.world.level.block.*;

import java.util.Map;

public class MinecraftCompat extends CompatBase {
@Override
public void init(boolean worldGen) {
Expand Down
1 change: 0 additions & 1 deletion Common/src/main/java/jeresources/config/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public static void reload() {
if (Services.PLATFORM.isClient()) {
DungeonCategory.reloadSettings();
}
EnchantmentRegistry.getInstance().removeAll(excludedEnchants);
JEIConfig.resetCategories();
JEIConfig.hideCategories(hiddenCategories);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;

public abstract class AbstractVillagerEntry<T extends AbstractVillager> {
private final List<TradeList> tradeList;
Expand Down Expand Up @@ -58,7 +57,7 @@ public List<ItemStack> getInputs() {
public List<ItemStack> getOutputs() {
List<ItemStack> list = new LinkedList<>();
for (List<TradeList.Trade> trades : this.tradeList) {
list.addAll(trades.stream().map(TradeList.Trade::getMinResult).collect(Collectors.toList()));
list.addAll(trades.stream().map(TradeList.Trade::getMinResult).toList());
}
return list;
}
Expand Down
30 changes: 21 additions & 9 deletions Common/src/main/java/jeresources/entry/DungeonEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
import net.minecraft.resources.ResourceKey;
import net.minecraft.util.Mth;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.storage.loot.LootPool;
import net.minecraft.world.level.storage.loot.LootTable;
import net.minecraft.world.level.storage.loot.entries.DynamicLoot;
import net.minecraft.world.level.storage.loot.entries.LootItem;
import net.minecraft.world.level.storage.loot.entries.LootPoolSingletonContainer;

import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;
Expand All @@ -42,23 +44,21 @@ public DungeonEntry(String name, LootTable lootTable) {

private void handleTable(LootTable lootTable, LootTableFetcher lootTables, float[] tmpMinStacks, float[] tmpMaxStacks) {
ILootTableHelper lootTableHelper = Services.PLATFORM.getLootTableHelper();
LootTableHelper.getPools(lootTable).forEach(
pool -> {
tmpMinStacks[0] += LootFunctionHelper.getMin(lootTableHelper.getRolls(pool));
tmpMaxStacks[0] += LootFunctionHelper.getMax(lootTableHelper.getRolls(pool)) + LootFunctionHelper.getMax(lootTableHelper.getBonusRolls(pool));
final float totalWeight = LootTableHelper.getLootEntries(pool).stream()
for (LootPool pool : LootTableHelper.getPools(lootTable)) {
tmpMinStacks[0] += LootFunctionHelper.getMin(lootTableHelper.getRolls(pool));
tmpMaxStacks[0] += LootFunctionHelper.getMax(lootTableHelper.getRolls(pool)) + LootFunctionHelper.getMax(lootTableHelper.getBonusRolls(pool));
final float totalWeight = LootTableHelper.getLootEntries(pool).stream()
.filter(entry -> entry instanceof LootPoolSingletonContainer).map(entry -> (LootPoolSingletonContainer) entry)
.mapToInt(entry -> entry.weight).sum();
LootTableHelper.getLootEntries(pool).stream()
LootTableHelper.getLootEntries(pool).stream()
.filter(entry -> entry instanceof LootItem).map(entry -> (LootItem) entry)
.map(entry -> new LootDrop(entry.item.value(), entry.weight / totalWeight, entry.functions)).forEach(drops::add);

LootTableHelper.getLootEntries(pool).stream()
LootTableHelper.getLootEntries(pool).stream()
.filter(entry -> entry instanceof DynamicLoot).map(entry -> (DynamicLoot) entry)
.map(entry -> lootTables.getLootTable(ResourceKey.create(Registries.LOOT_TABLE, entry.name)))
.forEach(table -> handleTable(table, lootTables, tmpMinStacks, tmpMaxStacks));
}
);
}
}

public boolean containsItem(ItemStack itemStack) {
Expand Down Expand Up @@ -92,4 +92,16 @@ public LootDrop getChestDrop(ItemStack ingredient) {
return drops.stream().filter(drop -> ItemStack.isSameItem(drop.item, ingredient)).findFirst().orElse(null);
}

public int amountOfItems(IFocus<ItemStack> focus) {
return getItemStacks(focus).size();
}

public List<ItemStack> getItems(IFocus<ItemStack> focus, int slot, int slots) {
List<ItemStack> list = getItemStacks(focus).subList(slot, slot + 1);
for (int n = 1; n < (amountOfItems(focus) / slots) + 1; n++)
list.add(this.amountOfItems(focus) <= slot + slots * n ? null : getItemStacks(focus).get(slot + slots * n));
list.removeIf(Objects::isNull);
return list;
}

}
21 changes: 16 additions & 5 deletions Common/src/main/java/jeresources/entry/EnchantmentEntry.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@
package jeresources.entry;

import jeresources.util.TranslationHelper;
import net.minecraft.core.Holder;
import net.minecraft.core.HolderSet;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.enchantment.Enchantment;

public class EnchantmentEntry {
private Enchantment enchantment;
private Holder<Enchantment> enchantment;

public EnchantmentEntry(Enchantment enchantment) {
public EnchantmentEntry(Holder<Enchantment> enchantment) {
this.enchantment = enchantment;
}

public String getTranslatedWithLevels() {
String s = this.enchantment.getFullname(1).getString();
if (this.enchantment.getMinLevel() != this.enchantment.getMaxLevel())
s += "-" + TranslationHelper.translateAndFormat("enchantment.level." + this.enchantment.getMaxLevel());
String s = Enchantment.getFullname(this.enchantment, 1).getString();
if (this.enchantment.value().getMinLevel() != this.enchantment.value().getMaxLevel())
s += "-" + TranslationHelper.translateAndFormat("enchantment.level." + this.enchantment.value().getMaxLevel());
return s;
}

public Enchantment getEnchantment() {
return enchantment.value();
}

public Holder<Enchantment> getEnchantmentHolder() {
return enchantment;
}

public HolderSet<Item> getSupportedItems() {
return enchantment.value().getSupportedItems();
}
}
8 changes: 8 additions & 0 deletions Common/src/main/java/jeresources/entry/MobEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,12 @@ public String getExp() {
}
return this.experience.getExpString();
}

public boolean hasSpawnEgg() {
return getSpawnEgg() != null;
}

public ItemStack getSpawnEgg() {
return getEntity().getPickResult();
}
}
9 changes: 9 additions & 0 deletions Common/src/main/java/jeresources/entry/WorldGenEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,13 @@ public void merge(WorldGenEntry entry) {
public boolean hasDeepSlateVariant() {
return this.deepSlateBlock != null && !this.deepSlateBlock.isEmpty();
}

public List<ItemStack> getBlocks() {
List<ItemStack> blocks = new LinkedList<>();
blocks.add(getBlock());
if (hasDeepSlateVariant()) {
blocks.add(getDeepSlateBlock());
}
return blocks;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class BackgroundDrawable implements IDrawable {
private static final int PADDING = 5;

public BackgroundDrawable(String resource, int width, int height) {
this.resource = new ResourceLocation(Reference.ID, resource);
this.resource = ResourceLocation.fromNamespaceAndPath(Reference.ID, resource);
this.width = width;
this.height = height;
}
Expand Down
10 changes: 6 additions & 4 deletions Common/src/main/java/jeresources/jei/BlankJEIRecipeCategory.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@

import java.util.List;

public abstract class BlankJEIRecipeCategory<T extends IRecipeCategoryExtension> implements IRecipeCategory<T> {
public abstract class BlankJEIRecipeCategory<T> implements IRecipeCategory<T> {
private final IDrawable icon;
protected final IRecipeCategoryExtension<T> recipeCategoryExtension;

protected BlankJEIRecipeCategory(IDrawable icon) {
protected BlankJEIRecipeCategory(IDrawable icon, IRecipeCategoryExtension<T> recipeCategoryExtension) {
this.icon = icon;
this.recipeCategoryExtension = recipeCategoryExtension;
}

@Override
Expand All @@ -24,11 +26,11 @@ protected BlankJEIRecipeCategory(IDrawable icon) {

@Override
public void draw(T recipe, @NotNull IRecipeSlotsView recipeSlotsView, @NotNull GuiGraphics guiGraphics, double mouseX, double mouseY) {
recipe.drawInfo(recipe, getBackground().getWidth(), getBackground().getHeight(), guiGraphics, mouseX, mouseY);
recipeCategoryExtension.drawInfo(recipe, getBackground().getWidth(), getBackground().getHeight(), guiGraphics, mouseX, mouseY);
}

@Override
public @NotNull List<Component> getTooltipStrings(T recipe, @NotNull IRecipeSlotsView recipeSlotsView, double mouseX, double mouseY) {
return recipe.getTooltipStrings(recipe, mouseX, mouseY);
return recipeCategoryExtension.getTooltipStrings(recipe, mouseX, mouseY);
}
}
50 changes: 19 additions & 31 deletions Common/src/main/java/jeresources/jei/JEIConfig.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
package jeresources.jei;

import jeresources.config.Settings;
import jeresources.entry.*;
import jeresources.jei.dungeon.DungeonCategory;
import jeresources.jei.dungeon.DungeonWrapper;
import jeresources.jei.enchantment.EnchantmentCategory;
import jeresources.jei.enchantment.EnchantmentMaker;
import jeresources.jei.enchantment.EnchantmentWrapper;
import jeresources.jei.mob.MobCategory;
import jeresources.jei.mob.MobWrapper;
import jeresources.jei.plant.PlantCategory;
import jeresources.jei.plant.PlantWrapper;
import jeresources.jei.villager.VillagerCategory;
import jeresources.jei.villager.VillagerWrapper;
import jeresources.jei.worldgen.WorldGenCategory;
import jeresources.jei.worldgen.WorldGenWrapper;
import jeresources.platform.Services;
import jeresources.reference.Reference;
import jeresources.registry.*;
Expand All @@ -28,28 +24,24 @@
import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.NotNull;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;


@JeiPlugin
public class JEIConfig implements IModPlugin {
public static final ResourceLocation MOB = new ResourceLocation(Reference.ID, "mob");
public static final RecipeType<MobWrapper> MOB_TYPE = new RecipeType<>(MOB, MobWrapper.class);
public static final ResourceLocation DUNGEON = new ResourceLocation(Reference.ID , "dungeon");
public static final RecipeType<DungeonWrapper> DUNGEON_TYPE = new RecipeType<>(DUNGEON, DungeonWrapper.class);
public static final ResourceLocation WORLD_GEN = new ResourceLocation(Reference.ID , "worldgen");
public static final RecipeType<WorldGenWrapper> WORLD_GEN_TYPE = new RecipeType<>(WORLD_GEN, WorldGenWrapper.class);
public static final ResourceLocation PLANT = new ResourceLocation(Reference.ID , "plant");
public static final RecipeType<PlantWrapper> PLANT_TYPE = new RecipeType<>(PLANT, PlantWrapper.class);
public static final ResourceLocation ENCHANTMENT = new ResourceLocation(Reference.ID , "enchantment");
public static final ResourceLocation MOB = ResourceLocation.fromNamespaceAndPath(Reference.ID, "mob");
public static final RecipeType<MobEntry> MOB_TYPE = new RecipeType<>(MOB, MobEntry.class);
public static final ResourceLocation DUNGEON = ResourceLocation.fromNamespaceAndPath(Reference.ID , "dungeon");
public static final RecipeType<DungeonEntry> DUNGEON_TYPE = new RecipeType<>(DUNGEON, DungeonEntry.class);
public static final ResourceLocation WORLD_GEN = ResourceLocation.fromNamespaceAndPath(Reference.ID , "worldgen");
public static final RecipeType<WorldGenEntry> WORLD_GEN_TYPE = new RecipeType<>(WORLD_GEN, WorldGenEntry.class);
public static final ResourceLocation PLANT = ResourceLocation.fromNamespaceAndPath(Reference.ID , "plant");
public static final RecipeType<PlantEntry> PLANT_TYPE = new RecipeType<>(PLANT, PlantEntry.class);
public static final ResourceLocation ENCHANTMENT = ResourceLocation.fromNamespaceAndPath(Reference.ID , "enchantment");
public static final RecipeType<EnchantmentWrapper> ENCHANTMENT_TYPE = new RecipeType<>(ENCHANTMENT, EnchantmentWrapper.class);
public static final ResourceLocation VILLAGER = new ResourceLocation(Reference.ID , "villager");
public static final RecipeType<VillagerWrapper> VILLAGER_TYPE = new RecipeType<>(VILLAGER, VillagerWrapper.class);
public static final ResourceLocation VILLAGER = ResourceLocation.fromNamespaceAndPath(Reference.ID , "villager");
public static final RecipeType<AbstractVillagerEntry> VILLAGER_TYPE = new RecipeType<>(VILLAGER, AbstractVillagerEntry.class);
public static final Map<ResourceLocation, RecipeType<?>> TYPES = new HashMap<>();
static {
TYPES.put(MOB, MOB_TYPE);
Expand All @@ -65,17 +57,17 @@ public class JEIConfig implements IModPlugin {

@Override
public @NotNull ResourceLocation getPluginUid() {
return new ResourceLocation(Reference.ID);
return ResourceLocation.fromNamespaceAndPath(Reference.ID, "minecraft");
}

@Override
public void registerRecipes(IRecipeRegistration registration) {
registration.addRecipes(DUNGEON_TYPE, asRecipes(DungeonRegistry.getInstance().getDungeons(), DungeonWrapper::new));
registration.addRecipes(DUNGEON_TYPE, DungeonRegistry.getInstance().getDungeons());
registration.addRecipes(ENCHANTMENT_TYPE, EnchantmentMaker.createRecipes(registration.getIngredientManager().getAllIngredients(VanillaTypes.ITEM_STACK)));
registration.addRecipes(MOB_TYPE, asRecipes(MobRegistry.getInstance().getMobs(), MobWrapper::new));
registration.addRecipes(PLANT_TYPE, asRecipes(PlantRegistry.getInstance().getAllPlants(), PlantWrapper::new));
registration.addRecipes(VILLAGER_TYPE, asRecipes(VillagerRegistry.getInstance().getVillagers(), VillagerWrapper::new));
registration.addRecipes(WORLD_GEN_TYPE, asRecipes(WorldGenRegistry.getInstance().getWorldGen(), WorldGenWrapper::new));
registration.addRecipes(MOB_TYPE, MobRegistry.getInstance().getMobs());
registration.addRecipes(PLANT_TYPE, PlantRegistry.getInstance().getAllPlants());
registration.addRecipes(VILLAGER_TYPE, VillagerRegistry.getInstance().getVillagers());
registration.addRecipes(WORLD_GEN_TYPE, WorldGenRegistry.getInstance().getWorldGen());
}

@Override
Expand Down Expand Up @@ -109,16 +101,12 @@ public static void resetCategories() {
public static void hideCategories(String[] categories) {
if (jeiRuntime != null) {
for (String category : categories) {
jeiRuntime.getRecipeManager().hideRecipeCategory(TYPES.get(new ResourceLocation(Reference.ID, category)));
jeiRuntime.getRecipeManager().hideRecipeCategory(TYPES.get(ResourceLocation.fromNamespaceAndPath(Reference.ID, category)));
}
}
}

public static IJeiHelpers getJeiHelpers() {
return JEIConfig.jeiHelpers;
}

private static <T, R> List<R> asRecipes(Collection<T> collection, Function<T, R> transformer) {
return collection.stream().map(transformer).collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package jeresources.jei.dungeon;

import jeresources.config.Settings;
import jeresources.entry.DungeonEntry;
import jeresources.jei.BlankJEIRecipeCategory;
import jeresources.jei.JEIConfig;
import jeresources.reference.Resources;
Expand All @@ -14,7 +15,7 @@
import org.jetbrains.annotations.NotNull;


public class DungeonCategory extends BlankJEIRecipeCategory<DungeonWrapper> {
public class DungeonCategory extends BlankJEIRecipeCategory<DungeonEntry> {
protected static final int Y_FIRST_ITEM = 44;
protected static final int X_FIRST_ITEM = 6;
protected static int SPACING_Y;
Expand All @@ -28,7 +29,7 @@ public static void reloadSettings() {
}

public DungeonCategory() {
super(JEIConfig.getJeiHelpers().getGuiHelper().createDrawable(Resources.Gui.Jei.TABS, 16, 0, 16, 16));
super(JEIConfig.getJeiHelpers().getGuiHelper().createDrawable(Resources.Gui.Jei.TABS, 16, 0, 16, 16), new DungeonWrapper());
reloadSettings();
}

Expand All @@ -44,26 +45,26 @@ public DungeonCategory() {
}

@Override
public @NotNull RecipeType<DungeonWrapper> getRecipeType() {
public @NotNull RecipeType<DungeonEntry> getRecipeType() {
return JEIConfig.DUNGEON_TYPE;
}

@Override
public void setRecipe(@NotNull IRecipeLayoutBuilder builder, @NotNull DungeonWrapper recipeWrapper, @NotNull IFocusGroup focuses) {
public void setRecipe(@NotNull IRecipeLayoutBuilder builder, @NotNull DungeonEntry recipe, @NotNull IFocusGroup focuses) {
int x = X_FIRST_ITEM;
int y = Y_FIRST_ITEM;
int slots = Math.min(recipeWrapper.amountOfItems(focuses.getFocuses(VanillaTypes.ITEM_STACK).findFirst().orElse(null)), ITEMS_PER_PAGE);
int slots = Math.min(recipe.amountOfItems(focuses.getFocuses(VanillaTypes.ITEM_STACK).findFirst().orElse(null)), ITEMS_PER_PAGE);
for (int i = 0; i < slots; i++) {
builder.addSlot(RecipeIngredientRole.OUTPUT, x, y)
.addTooltipCallback(recipeWrapper)
.addItemStacks(recipeWrapper.getItems(focuses.getFocuses(VanillaTypes.ITEM_STACK).findFirst().orElse(null), i, slots));
.addTooltipCallback(new DungeonTooltip(recipe))
.addItemStacks(recipe.getItems(focuses.getFocuses(VanillaTypes.ITEM_STACK).findFirst().orElse(null), i, slots));
x += SPACING_X;

if (x >= X_FIRST_ITEM + SPACING_X * Settings.ITEMS_PER_ROW * 2) {
x = X_FIRST_ITEM;
y += SPACING_Y;
}
}
recipeWrapper.resetLid();
((DungeonWrapper)recipeCategoryExtension).resetLid();
}
}
22 changes: 22 additions & 0 deletions Common/src/main/java/jeresources/jei/dungeon/DungeonTooltip.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package jeresources.jei.dungeon;

import jeresources.entry.DungeonEntry;
import mezz.jei.api.gui.ingredient.IRecipeSlotTooltipCallback;
import mezz.jei.api.gui.ingredient.IRecipeSlotView;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.ItemStack;

import java.util.List;

public class DungeonTooltip implements IRecipeSlotTooltipCallback {
private final DungeonEntry entry;

public DungeonTooltip(DungeonEntry entry) {
this.entry = entry;
}

@Override
public void onTooltip(IRecipeSlotView recipeSlotView, List<Component> tooltip) {
tooltip.add(entry.getChestDrop((ItemStack) recipeSlotView.getDisplayedIngredient().get().getIngredient()).toStringTextComponent());
}
}
Loading

0 comments on commit 210cee0

Please sign in to comment.