-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: emi transfer handler not working on servers
Closes #1223
- Loading branch information
1 parent
6c18c4a
commit 395ff34
Showing
3 changed files
with
45 additions
and
32 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
src/main/java/com/klikli_dev/occultism/integration/emi/impl/EmiHelper.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,42 @@ | ||
package com.klikli_dev.occultism.integration.emi.impl; | ||
|
||
import com.google.common.base.Preconditions; | ||
import net.minecraft.core.NonNullList; | ||
import net.minecraft.world.item.crafting.Ingredient; | ||
import net.minecraft.world.item.crafting.Recipe; | ||
import net.minecraft.world.item.crafting.ShapedRecipe; | ||
|
||
public class EmiHelper { | ||
public static NonNullList<Ingredient> ensure3by3CraftingMatrix(Recipe<?> recipe) { | ||
var ingredients = recipe.getIngredients(); | ||
var expandedIngredients = NonNullList.withSize(9, Ingredient.EMPTY); | ||
|
||
Preconditions.checkArgument(ingredients.size() <= 9); | ||
|
||
// shaped recipes can be smaller than 3x3, expand to 3x3 to match the crafting | ||
// matrix | ||
if (recipe instanceof ShapedRecipe shapedRecipe) { | ||
var width = shapedRecipe.getWidth(); | ||
var height = shapedRecipe.getHeight(); | ||
Preconditions.checkArgument(width <= 3 && height <= 3); | ||
|
||
for (var h = 0; h < height; h++) { | ||
for (var w = 0; w < width; w++) { | ||
var source = w + h * width; | ||
var target = w + h * 3; | ||
var i = ingredients.get(source); | ||
expandedIngredients.set(target, i); | ||
} | ||
} | ||
} | ||
// Anything else should be a flat list | ||
else { | ||
for (var i = 0; i < ingredients.size(); i++) { | ||
expandedIngredients.set(i, ingredients.get(i)); | ||
} | ||
} | ||
|
||
return expandedIngredients; | ||
} | ||
|
||
} |
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