Skip to content

Commit

Permalink
Merge branch '1.21.x' into AttributeTemplatePublicity
Browse files Browse the repository at this point in the history
  • Loading branch information
marchermans authored Nov 27, 2024
2 parents 6161212 + cf6cc71 commit da40a62
Show file tree
Hide file tree
Showing 12 changed files with 186 additions and 7 deletions.
23 changes: 16 additions & 7 deletions patches/net/minecraft/world/item/crafting/RecipeManager.java.patch
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
--- a/net/minecraft/world/item/crafting/RecipeManager.java
+++ b/net/minecraft/world/item/crafting/RecipeManager.java
@@ -260,6 +_,11 @@
@@ -69,7 +_,7 @@
protected RecipeMap prepare(ResourceManager p_379845_, ProfilerFiller p_380058_) {
SortedMap<ResourceLocation, Recipe<?>> sortedmap = new TreeMap<>();
SimpleJsonResourceReloadListener.scanDirectory(
- p_379845_, Registries.elementsDirPath(Registries.RECIPE), this.registries.createSerializationContext(JsonOps.INSTANCE), Recipe.CODEC, sortedmap
+ p_379845_, Registries.elementsDirPath(Registries.RECIPE), new net.neoforged.neoforge.common.conditions.ConditionalOps<>(this.registries.createSerializationContext(JsonOps.INSTANCE), getContext()), Recipe.CODEC, sortedmap // Neo: add condition context
);
List<RecipeHolder<?>> list = new ArrayList<>(sortedmap.size());
sortedmap.forEach((p_379232_, p_379233_) -> {
@@ -258,6 +_,11 @@
return p_380850_ -> p_380850_.getType() == p_381108_ && p_380850_ instanceof SingleItemRecipe singleitemrecipe
? Optional.of(singleitemrecipe.input())
: Optional.empty();
}
+ }
+
+ // Neo: expose recipe map
+ public RecipeMap recipeMap() {
+ return this.recipes;
+ }
+
public interface CachedCheck<I extends RecipeInput, T extends Recipe<I>> {
Optional<RecipeHolder<T>> getRecipeFor(I p_344938_, ServerLevel p_379487_);
}

public interface CachedCheck<I extends RecipeInput, T extends Recipe<I>> {
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values": [
"#neoforge:needs_netherite_tool"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values": [
"#neoforge:needs_netherite_tool"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values": [
"#neoforge:needs_netherite_tool"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values": [
"#neoforge:needs_netherite_tool"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values": [
"#neoforge:needs_netherite_tool"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"values": []
}
20 changes: 20 additions & 0 deletions src/main/java/net/neoforged/neoforge/common/Tags.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,28 @@ public static class Blocks {
* This is patched into the following method: {@link net.minecraft.world.entity.monster.EnderMan.EndermanLeaveBlockGoal#canPlaceBlock(Level, BlockPos, BlockState, BlockState, BlockState, BlockPos)}
*/
public static final TagKey<Block> ENDERMAN_PLACE_ON_BLACKLIST = neoforgeTag("enderman_place_on_blacklist");

/**
* For denoting blocks that need tools that are Wood or higher to mine.
* By default, this is not added to any Minecraft tag since Wood is in the lowest "tier".
*/
public static final TagKey<Block> NEEDS_WOOD_TOOL = neoforgeTag("needs_wood_tool");

/**
* For denoting blocks that need tools that are Gold or higher to mine.
* By default, this is not added to any Minecraft tag since Gold is in the lowest "tier".
*/
public static final TagKey<Block> NEEDS_GOLD_TOOL = neoforgeTag("needs_gold_tool");

/**
* For denoting blocks that need tools that are Netherite or higher to mine.
* Blocks in this tag gets added to the following Minecraft tags:
* {@link BlockTags#INCORRECT_FOR_WOODEN_TOOL}
* {@link BlockTags#INCORRECT_FOR_STONE_TOOL}
* {@link BlockTags#INCORRECT_FOR_IRON_TOOL}
* {@link BlockTags#INCORRECT_FOR_GOLD_TOOL}
* {@link BlockTags#INCORRECT_FOR_DIAMOND_TOOL}
*/
public static final TagKey<Block> NEEDS_NETHERITE_TOOL = neoforgeTag("needs_netherite_tool");

// `c` tags for common conventions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,14 @@ public void addTags(HolderLookup.Provider p_256380_) {

tag(Tags.Blocks.VILLAGER_FARMLANDS).add(Blocks.FARMLAND);

// Make our Needs Netherite Tool tag be functional.
tag(Tags.Blocks.NEEDS_NETHERITE_TOOL);
tag(BlockTags.INCORRECT_FOR_WOODEN_TOOL).addTag(Tags.Blocks.NEEDS_NETHERITE_TOOL);
tag(BlockTags.INCORRECT_FOR_STONE_TOOL).addTag(Tags.Blocks.NEEDS_NETHERITE_TOOL);
tag(BlockTags.INCORRECT_FOR_IRON_TOOL).addTag(Tags.Blocks.NEEDS_NETHERITE_TOOL);
tag(BlockTags.INCORRECT_FOR_GOLD_TOOL).addTag(Tags.Blocks.NEEDS_NETHERITE_TOOL);
tag(BlockTags.INCORRECT_FOR_DIAMOND_TOOL).addTag(Tags.Blocks.NEEDS_NETHERITE_TOOL);

// Backwards compat with pre-1.21 tags. Done after so optional tag is last for better readability.
// TODO: Remove backwards compat tag entries in 1.22
tagWithOptionalLegacy(Tags.Blocks.BARRELS);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"neoforge:conditions": [
{
"type": "neoforge:false"
}
],
"parent": "minecraft:recipes/root",
"criteria": {
"has_stone": {
"conditions": {
"items": [
{
"items": "minecraft:stone"
}
]
},
"trigger": "minecraft:inventory_changed"
},
"has_the_recipe": {
"conditions": {
"recipe": "neotests_test_conditional_recipe:always_disabled_recipe"
},
"trigger": "minecraft:recipe_unlocked"
}
},
"requirements": [
[
"has_the_recipe",
"has_stone"
]
],
"rewards": {
"recipes": [
"neotests_test_conditional_recipe:always_disabled_recipe"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"neoforge:conditions": [
{
"type": "neoforge:false"
}
],
"type": "minecraft:crafting_shapeless",
"category": "misc",
"ingredients": [
"minecraft:stone"
],
"result": {
"count": 1,
"id": "minecraft:bedrock"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright (c) NeoForged and contributors
* SPDX-License-Identifier: LGPL-2.1-only
*/

package net.neoforged.neoforge.debug;

import net.minecraft.core.HolderLookup;
import net.minecraft.core.registries.Registries;
import net.minecraft.data.recipes.RecipeCategory;
import net.minecraft.data.recipes.RecipeOutput;
import net.minecraft.data.recipes.RecipeProvider;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Items;
import net.neoforged.neoforge.common.conditions.FalseCondition;
import net.neoforged.neoforge.event.server.ServerStartedEvent;
import net.neoforged.testframework.DynamicTest;
import net.neoforged.testframework.annotation.ForEachTest;
import net.neoforged.testframework.annotation.TestHolder;
import net.neoforged.testframework.registration.RegistrationHelper;

@ForEachTest(groups = "conditional_recipes")
public interface ConditionalRecipeTest {
@TestHolder(description = "Validates that recipes support conditionals by generating a new recipe disabled by the FALSE condition", enabledByDefault = true)
static void testConditionalRecipe(DynamicTest test, RegistrationHelper reg) {
// name pointing to recipe which should never be enabled
var recipeName = ResourceKey.create(Registries.RECIPE, ResourceLocation.fromNamespaceAndPath(reg.modId(), "always_disabled_recipe"));

reg.addProvider(event -> new RecipeProvider.Runner(event.getGenerator().getPackOutput(), event.getLookupProvider()) {
@Override
protected RecipeProvider createRecipeProvider(HolderLookup.Provider registries, RecipeOutput output) {
return new RecipeProvider(registries, output) {
@Override
protected void buildRecipes() {
// generic stone -> bedrock recipe
shapeless(RecipeCategory.MISC, Items.BEDROCK)
.requires(Items.STONE)
.unlockedBy("has_stone", has(Items.STONE))
// false condition to have this recipe always disabled
.save(output.withConditions(FalseCondition.INSTANCE), recipeName);
}
};
}

@Override
public String getName() {
return "always_disabled_recipe_provider";
}
});

test.eventListeners().forge().addListener((ServerStartedEvent event) -> {
var recipe = event.getServer().getRecipeManager().recipeMap().byKey(recipeName);

if (recipe == null)
test.pass();
else
test.fail("Found recipe: '" + recipeName.location() + "', This should always be disabled due to 'FALSE' condition!");
});
}
}

0 comments on commit da40a62

Please sign in to comment.