Skip to content

Commit

Permalink
Use fake level for JEI (#10304) + Fix porting errors
Browse files Browse the repository at this point in the history
Use fake level for JEI
  • Loading branch information
Raycoms committed Nov 27, 2024
1 parent 288d767 commit a925f92
Show file tree
Hide file tree
Showing 26 changed files with 205 additions and 61 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ minecraft_range=[1.21, 1.22)

dataGeneratorsVersion=1.20.4-0.1.57-ALPHA
blockUI_version=1.0.192-1.21.1-snapshot
structurize_version=1.0.754-1.21.1-snapshot
structurize_version=1.0.755-1.21.1-snapshot
domumOrnamentumVersion=1.0.204-1.21.1-snapshot
multiPistonVersion=1.2.51-1.21.1-snapshot

Expand Down
63 changes: 59 additions & 4 deletions src/datagen/generated/minecolonies/data/c/tags/item/foods.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,63 @@
{
"values": [
"minecolonies:milky_bread",
"minecolonies:sugary_bread",
"minecolonies:golden_bread",
"minecolonies:chorus_bread"
"minecolonies:cheddar_cheese",
"minecolonies:feta_cheese",
"minecolonies:cooked_rice",
"minecolonies:tofu",
"minecolonies:flatbread",
"minecolonies:cheese_ravioli",
"minecolonies:chicken_broth",
"minecolonies:meat_ravioli",
"minecolonies:mint_jelly",
"minecolonies:mint_tea",
"minecolonies:polenta",
"minecolonies:potato_soup",
"minecolonies:veggie_ravioli",
"minecolonies:yogurt",
"minecolonies:squash_soup",
"minecolonies:pea_soup",
"minecolonies:corn_chowder",
"minecolonies:tortillas",
"minecolonies:spicy_grilled_chicken",
"minecolonies:manchet_bread",
"minecolonies:lembas_scone",
"minecolonies:muffin",
"minecolonies:pottage",
"minecolonies:pasta_plain",
"minecolonies:apple_pie",
"minecolonies:plain_cheesecake",
"minecolonies:baked_salmon",
"minecolonies:eggdrop_soup",
"minecolonies:fish_n_chips",
"minecolonies:pierogi",
"minecolonies:veggie_soup",
"minecolonies:yogurt_with_berries",
"minecolonies:cabochis",
"minecolonies:veggie_quiche",
"minecolonies:rice_ball",
"minecolonies:mutton_dinner",
"minecolonies:pasta_tomato",
"minecolonies:cheese_pizza",
"minecolonies:pepper_hummus",
"minecolonies:kebab",
"minecolonies:congee",
"minecolonies:kimchi",
"minecolonies:hand_pie",
"minecolonies:mintchoco_cheesecake",
"minecolonies:borscht",
"minecolonies:schnitzel",
"minecolonies:steak_dinner",
"minecolonies:lamb_stew",
"minecolonies:fish_dinner",
"minecolonies:sushi_roll",
"minecolonies:ramen",
"minecolonies:eggplant_dolma",
"minecolonies:stuffed_pita",
"minecolonies:mushroom_pizza",
"minecolonies:pita_hummus",
"minecolonies:spicy_eggplant",
"minecolonies:stew_trencher",
"minecolonies:stuffed_pepper",
"minecolonies:tacos"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
"minecolonies:milky_bread",
"minecolonies:sugary_bread",
"minecolonies:golden_bread",
"minecolonies:chorus_bread"
"minecolonies:chorus_bread",
"minecolonies:flatbread",
"minecolonies:hand_pie",
"minecolonies:lembas_scone",
"minecolonies:manchet_bread",
"minecolonies:muffin",
"minecolonies:stew_trencher",
"minecolonies:stuffed_pita"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"values": [
"minecolonies:hand_pie",
"minecolonies:muffin"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values": [
"minecolonies:lamb_stew"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"values": [
"minecolonies:cabochis",
"minecolonies:lamb_stew",
"minecolonies:pottage"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"values": [
"minecolonies:cabochis",
"minecolonies:eggplant_dolma",
"minecolonies:pottage",
"minecolonies:stuffed_pepper",
"minecolonies:stuffed_pita"
]
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"type": "minecraft:block",
"pools": [
{
"bonus_rolls": 0.0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"type": "minecraft:block",
"pools": [
{
"bonus_rolls": 0.0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"type": "minecraft:block",
"pools": [
{
"bonus_rolls": 0.0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"type": "minecraft:block",
"pools": [
{
"bonus_rolls": 0.0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"type": "minecraft:block",
"pools": [
{
"bonus_rolls": 0.0,
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/com/minecolonies/api/crafting/GenericRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.CraftingContainer;
Expand Down Expand Up @@ -97,8 +97,8 @@ public static IGenericRecipe of(@Nullable final IToken<?> recipeToken)
private final Block intermediate;
private final @Nullable ResourceKey<LootTable> lootTable;
private final EquipmentTypeEntry requiredTool;
private final LivingEntity requiredEntity;
private final List<Component> restrictions;
private final EntityType<?> requiredEntity;
private final List<Component> restrictions;
private final int levelSort;

public GenericRecipe(@Nullable final ResourceLocation id,
Expand Down Expand Up @@ -133,7 +133,7 @@ public GenericRecipe(@Nullable final ResourceLocation id,
final int gridSize, @NotNull final Block intermediate,
@Nullable final ResourceKey<LootTable> lootTable,
@NotNull final EquipmentTypeEntry requiredTool,
@Nullable final LivingEntity requiredEntity,
@Nullable final EntityType<?> requiredEntity,
@NotNull final List<Component> restrictions,
final int levelSort)
{
Expand Down Expand Up @@ -250,8 +250,9 @@ public EquipmentTypeEntry getRequiredTool()
return this.requiredTool;
}

@Nullable
@Override
public @Nullable LivingEntity getRequiredEntity()
public EntityType<?> getRequiredEntity()
{
return this.requiredEntity;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.storage.loot.LootTable;
Expand Down Expand Up @@ -136,7 +136,7 @@ public interface IGenericRecipe
* @return The required creature.
*/
@Nullable
LivingEntity getRequiredEntity();
EntityType<?> getRequiredEntity();

/**
* Gets some human-readable restrictions on when this recipe is valid.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public List<IGenericRecipe> getRecipesForDisplayPurposesOnly(@NotNull final Anim
Blocks.AIR,
animal.getLootTable(),
ModEquipmentTypes.axe.get(),
animal,
animal.getType(),
Collections.emptyList(),
0));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,12 @@ public List<IGenericRecipe> getRecipesForDisplayPurposesOnly(@NotNull Animal ani

recipes.add(new GenericRecipe(null, new ItemStack(Items.HONEYCOMB),
Collections.emptyList(), Collections.emptyList(), Collections.emptyList(),
0, Blocks.AIR, null, ModEquipmentTypes.shears.get(), animal, Collections.emptyList(), 0));
0, Blocks.AIR, null, ModEquipmentTypes.shears.get(), animal.getType(), Collections.emptyList(), 0));

recipes.add(new GenericRecipe(null, new ItemStack(Items.HONEY_BOTTLE),
Collections.emptyList(), Collections.emptyList(),
Collections.singletonList(Collections.singletonList(new ItemStack(Items.GLASS_BOTTLE))),
0, Blocks.AIR, null, ModEquipmentTypes.none.get(), animal, Collections.emptyList(), 0));
0, Blocks.AIR, null, ModEquipmentTypes.none.get(), animal.getType(), Collections.emptyList(), 0));

return recipes;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public List<IGenericRecipe> getRecipesForDisplayPurposesOnly(@NotNull Animal ani
final List<IGenericRecipe> recipes = new ArrayList<>(super.getRecipesForDisplayPurposesOnly(animal));

recipes.add(new GenericRecipe(null, new ItemStack(Items.EGG), Collections.emptyList(), Collections.emptyList(),
Collections.emptyList(), 0, Blocks.AIR, null, ModEquipmentTypes.none.get(), animal, Collections.emptyList(), 0));
Collections.emptyList(), 0, Blocks.AIR, null, ModEquipmentTypes.none.get(), animal.getType(), Collections.emptyList(), 0));

return recipes;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public List<IGenericRecipe> getRecipesForDisplayPurposesOnly(@NotNull Animal ani
Collections.singletonList(new ItemStack(Items.SUSPICIOUS_STEW)), // alt output
Collections.emptyList(), // extra output
Collections.singletonList(Collections.singletonList(new ItemStack(Items.BOWL))), // input
1, Blocks.AIR, null, ModEquipmentTypes.none.get(), animal, Collections.emptyList(), 0));
1, Blocks.AIR, null, ModEquipmentTypes.none.get(), animal.getType(), Collections.emptyList(), 0));
}
else if (animal instanceof Cow)
{
Expand All @@ -199,13 +199,13 @@ else if (animal instanceof Cow)
Collections.emptyList(), // alt output
Collections.emptyList(), // extra output
Collections.singletonList(Collections.singletonList(new ItemStack(Items.BUCKET))), // input
1, Blocks.AIR, null, ModEquipmentTypes.none.get(), animal, Collections.emptyList(), 0));
1, Blocks.AIR, null, ModEquipmentTypes.none.get(), animal.getType(), Collections.emptyList(), 0));
recipes.add(new GenericRecipe(null,
new ItemStack(ModItems.large_milk_bottle), // output
Collections.emptyList(), // alt output
Collections.emptyList(), // extra output
Collections.singletonList(Collections.singletonList(new ItemStack(ModItems.large_empty_bottle))), // input
1, Blocks.AIR, null, ModEquipmentTypes.none.get(), animal, Collections.emptyList(), 0));
1, Blocks.AIR, null, ModEquipmentTypes.none.get(), animal.getType(), Collections.emptyList(), 0));
}

return recipes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public List<IGenericRecipe> getRecipesForDisplayPurposesOnly(@NotNull Animal ani
recipes.add(new GenericRecipe(null, ItemStack.EMPTY,
StreamSupport.stream(BuiltInRegistries.ITEM.getTagOrEmpty(ItemTags.WOOL).spliterator(), false).map(ItemStack::new).toList(),
Collections.emptyList(), Collections.emptyList(),
0, Blocks.AIR, null, ModEquipmentTypes.shears.get(), animal, Collections.emptyList(), 0));
0, Blocks.AIR, null, ModEquipmentTypes.shears.get(), animal.getType(), Collections.emptyList(), 0));

return recipes;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.minecolonies.core.compatibility.jei;

import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.ldtteam.blockui.UiRenderMacros;
import com.minecolonies.api.colony.buildings.modules.ICraftingBuildingModule;
import com.minecolonies.api.colony.buildings.registry.BuildingEntry;
import com.minecolonies.api.colony.jobs.IJob;
import com.minecolonies.api.crafting.IGenericRecipe;
import com.minecolonies.api.crafting.registry.CraftingType;
import com.minecolonies.api.util.Log;
import com.minecolonies.api.util.constant.TranslationConstants;
import com.minecolonies.core.colony.buildings.modules.AnimalHerdingModule;
import com.minecolonies.core.colony.crafting.CustomRecipeManager;
Expand All @@ -22,13 +25,15 @@
import mezz.jei.api.helpers.IModIdHelper;
import mezz.jei.api.recipe.IFocusGroup;
import mezz.jei.api.recipe.RecipeType;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.renderer.Rect2i;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.animal.Animal;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
Expand All @@ -39,6 +44,7 @@
import net.neoforged.api.distmarker.OnlyIn;
import org.jetbrains.annotations.NotNull;

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

Expand Down Expand Up @@ -69,6 +75,10 @@ public GenericRecipeCategory(@NotNull final BuildingEntry building,
@NotNull private final IModIdHelper modIdHelper;
@NotNull private final ITickTimer animalTimer;

private static final Cache<EntityType<?>, Entity> entityCache = CacheBuilder.newBuilder()
.expireAfterAccess(Duration.ofMinutes(2))
.build();

private static final int ANIMAL_W = (WIDTH - CITIZEN_W) / 2;
private static final int ANIMAL_H = CITIZEN_H - 10;
private static final int ANIMAL_X = CITIZEN_X + CITIZEN_W + (WIDTH - CITIZEN_X - CITIZEN_W - ANIMAL_W) / 2;
Expand Down Expand Up @@ -281,20 +291,29 @@ public void draw(@NotNull final IGenericRecipe recipe,
RenderHelper.renderBlock(stack, block, outputSlotX + 8, CITIZEN_Y + 6, 100, -30F, 30F, 16F);
}

final LivingEntity animal = recipe.getRequiredEntity();
if (animal != null)
final EntityType<?> entityType = recipe.getRequiredEntity();
if (entityType != null)
{
final float scale = ANIMAL_H / 2.4f;
final int animal_cx = ANIMAL_X + (ANIMAL_W / 2);
final int animal_cy = ANIMAL_Y + (ANIMAL_H / 2);
final int animal_by = ANIMAL_Y + ANIMAL_H;
final int offsetY = 16;
final float yaw = animalTimer.getValue();
final float headYaw = (float) Math.atan((animal_cx - mouseX) / 40.0F) * 40.0F + yaw;
final float pitch = (float) Math.atan((animal_cy - offsetY - mouseY) / 40.0F) * 20.0F;
Lighting.setupForFlatItems();
UiRenderMacros.drawEntity(stack.pose(), animal_cx, animal_by - offsetY, scale, headYaw, yaw, pitch, animal);
Lighting.setupFor3DItems();
try
{
final Entity entity = entityCache.get(entityType, () -> entityType.create(Minecraft.getInstance().level));

final float scale = ANIMAL_H / 2.4f;
final int animal_cx = ANIMAL_X + (ANIMAL_W / 2);
final int animal_cy = ANIMAL_Y + (ANIMAL_H / 2);
final int animal_by = ANIMAL_Y + ANIMAL_H;
final int offsetY = 16;
final float yaw = animalTimer.getValue();
final float headYaw = (float) Math.atan((animal_cx - mouseX) / 40.0F) * 40.0F + yaw;
final float pitch = (float) Math.atan((animal_cy - offsetY - mouseY) / 40.0F) * 20.0F;
Lighting.setupForFlatItems();
UiRenderMacros.drawEntity(stack.pose(), animal_cx, animal_by - offsetY, scale, headYaw, yaw, pitch, entity);
Lighting.setupFor3DItems();
}
catch (final Throwable e)
{
Log.getLogger().error("Error drawing {}", entityType.getDescriptionId(), e);
}
}
}

Expand Down
Loading

0 comments on commit a925f92

Please sign in to comment.