-
Notifications
You must be signed in to change notification settings - Fork 423
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[1.21.1-1.21.4] Custom Ingredients sync fix (#4322)
* Fix customIngredients sync (#4225) * Add client side test for custom ingredients sync * Fixed styling issues and missing license header * Applied requested changes and styling fixes (cherry picked from commit 248df81) (cherry picked from commit 1572dc3)
- Loading branch information
Showing
9 changed files
with
132 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...i-v1/src/main/java/net/fabricmc/fabric/mixin/recipe/ingredient/ClientConnectionMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package net.fabricmc.fabric.mixin.recipe.ingredient; | ||
|
||
import java.util.Set; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Unique; | ||
|
||
import net.minecraft.network.ClientConnection; | ||
import net.minecraft.util.Identifier; | ||
|
||
import net.fabricmc.fabric.impl.recipe.ingredient.SupportedIngredientsClientConnection; | ||
|
||
@Mixin(ClientConnection.class) | ||
public abstract class ClientConnectionMixin implements SupportedIngredientsClientConnection { | ||
@Unique | ||
private Set<Identifier> fabric_supportedCustomIngredients = Set.of(); | ||
|
||
@Override | ||
public void fabric_setSupportedCustomIngredients(Set<Identifier> supportedCustomIngredients) { | ||
fabric_supportedCustomIngredients = supportedCustomIngredients; | ||
} | ||
|
||
@Override | ||
public Set<Identifier> fabric_getSupportedCustomIngredients() { | ||
return fabric_supportedCustomIngredients; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...stmod/resources/data/fabric-recipe-api-v1-testmod/recipe/test_customingredients_sync.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"type": "minecraft:crafting_shapeless", | ||
"ingredients": [ | ||
{ | ||
"fabric:type": "fabric:components", | ||
"base": { | ||
"item": "minecraft:diamond_pickaxe" | ||
}, | ||
"components": { | ||
"minecraft:damage": 0 | ||
}, | ||
"strict": false | ||
} | ||
], | ||
"result": { | ||
"id": "minecraft:diamond_block" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...va/net/fabricmc/fabric/test/recipe/ingredient/client/ClientCustomIngredientSyncTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package net.fabricmc.fabric.test.recipe.ingredient.client; | ||
|
||
import net.minecraft.recipe.ShapelessRecipe; | ||
import net.minecraft.test.GameTestException; | ||
import net.minecraft.util.Identifier; | ||
|
||
import net.fabricmc.api.ClientModInitializer; | ||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; | ||
import net.fabricmc.fabric.impl.recipe.ingredient.CustomIngredientImpl; | ||
import net.fabricmc.fabric.impl.recipe.ingredient.builtin.ComponentsIngredient; | ||
|
||
public class ClientCustomIngredientSyncTests implements ClientModInitializer { | ||
/** | ||
* The recipe requires a custom ingredient. | ||
*/ | ||
@Override | ||
public void onInitializeClient() { | ||
ClientTickEvents.END_WORLD_TICK.register(world -> { | ||
Identifier recipeId = Identifier.of("fabric-recipe-api-v1-testmod", "test_customingredients_sync"); | ||
ShapelessRecipe recipe = (ShapelessRecipe) world.getRecipeManager().get(recipeId).get().value(); | ||
|
||
if (!(recipe.getIngredients().getFirst() instanceof CustomIngredientImpl customIngredient)) { | ||
throw new GameTestException("Expected the first ingredient to be a CustomIngredientImpl"); | ||
} | ||
|
||
if (!(customIngredient.getCustomIngredient() instanceof ComponentsIngredient)) { | ||
throw new GameTestException("Expected the custom ingredient to be a ComponentsIngredient"); | ||
} | ||
}); | ||
} | ||
} |