-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Handle alloy smelting vanilla inheritance with recipe manager.
Intended to help with the Kube JS addon, but also simplifies the logic somewhat.
- Loading branch information
Showing
10 changed files
with
108 additions
and
156 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
94 changes: 0 additions & 94 deletions
94
...ain/java/com/enderio/machines/common/integrations/vanilla/VanillaAlloySmeltingRecipe.java
This file was deleted.
Oops, something went wrong.
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
20 changes: 20 additions & 0 deletions
20
enderio-machines/src/main/java/com/enderio/machines/mixin/AbstractCookingRecipeAccessor.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,20 @@ | ||
package com.enderio.machines.mixin; | ||
|
||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.item.crafting.AbstractCookingRecipe; | ||
import net.minecraft.world.item.crafting.Ingredient; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Accessor; | ||
|
||
@Mixin(AbstractCookingRecipe.class) | ||
public interface AbstractCookingRecipeAccessor { | ||
|
||
@Accessor | ||
Ingredient getIngredient(); | ||
|
||
@Accessor | ||
ItemStack getResult(); | ||
|
||
@Accessor | ||
float getExperience(); | ||
} |
49 changes: 49 additions & 0 deletions
49
enderio-machines/src/main/java/com/enderio/machines/mixin/RecipeManagerMixin.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,49 @@ | ||
package com.enderio.machines.mixin; | ||
|
||
import com.enderio.EnderIOBase; | ||
import com.enderio.machines.common.config.MachinesConfig; | ||
import com.enderio.machines.common.init.MachineRecipes; | ||
import com.enderio.machines.common.recipe.AlloySmeltingRecipe; | ||
import com.google.common.collect.ImmutableMap; | ||
import com.google.common.collect.ImmutableMultimap; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.item.crafting.Recipe; | ||
import net.minecraft.world.item.crafting.RecipeHolder; | ||
import net.minecraft.world.item.crafting.RecipeManager; | ||
import net.minecraft.world.item.crafting.RecipeType; | ||
import net.minecraft.world.item.crafting.SmeltingRecipe; | ||
import net.neoforged.neoforge.common.conditions.WithConditions; | ||
import net.neoforged.neoforge.common.crafting.SizedIngredient; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
import java.util.List; | ||
|
||
@Mixin(RecipeManager.class) | ||
public class RecipeManagerMixin { | ||
|
||
@Inject(method = "lambda$apply$0", at = @At("TAIL")) | ||
private static void collectRecipe(ResourceLocation recipeId, ImmutableMultimap.Builder<RecipeType<?>, RecipeHolder<?>> byType, | ||
ImmutableMap.Builder<ResourceLocation, RecipeHolder<?>> byName, WithConditions<Recipe<?>> recipeWithConditions, CallbackInfo ci) { | ||
if (recipeWithConditions.carrier() instanceof SmeltingRecipe smeltingRecipe) { | ||
RecipeHolder<AlloySmeltingRecipe> convertedHolder = enderio$convert(recipeId, smeltingRecipe); | ||
byType.put(MachineRecipes.ALLOY_SMELTING.type().get(), convertedHolder); | ||
byName.put(convertedHolder.id(), convertedHolder); | ||
} | ||
} | ||
|
||
@Unique | ||
private static RecipeHolder<AlloySmeltingRecipe> enderio$convert(ResourceLocation originalId, SmeltingRecipe smeltingRecipe) { | ||
AbstractCookingRecipeAccessor accessor = (AbstractCookingRecipeAccessor) smeltingRecipe; | ||
SizedIngredient input = new SizedIngredient(accessor.getIngredient(), 1); | ||
int energy = MachinesConfig.COMMON.ENERGY.ALLOY_SMELTER_VANILLA_ITEM_ENERGY.get(); | ||
AlloySmeltingRecipe recipe = new AlloySmeltingRecipe(List.of(input), accessor.getResult(), energy, accessor.getExperience(), true); | ||
|
||
String path = "smelting/" + originalId.getPath(); | ||
ResourceLocation id = EnderIOBase.loc(path); | ||
return new RecipeHolder<>(id, recipe); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...on/integrations/vanilla/package-info.java → .../enderio/machines/mixin/package-info.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
@javax.annotation.ParametersAreNonnullByDefault | ||
@net.minecraft.MethodsReturnNonnullByDefault | ||
|
||
package com.enderio.machines.common.integrations.vanilla; | ||
package com.enderio.machines.mixin; |
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
Oops, something went wrong.