Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Recipe API #1395

Closed
wants to merge 1 commit into from
Closed

Implement Recipe API #1395

wants to merge 1 commit into from

Conversation

Faithcaio
Copy link
Contributor

@Faithcaio Faithcaio commented Jun 15, 2017

SpongeAPI|SpongeCommon|SpongeForge

Continuation of #1119 of SpongePowered/SpongeAPI#1098
Updated for MC 1.12


InventoryUtil: CraftingInventory <-> InventoryCrafting Util
ItemStackUtil: List <-> native Ingredient[]

AbstractSpongeCraftingRecipe/DelegateSpongeCraftingRecipe: for custom CraftingRecipe Impls.
CustomIngredient: For Ingredients using Predicates instead of Items.
DelegateIngredient: For custom Ingredient Impls.
IngredientUtil: Ingredient <-> native Ingredient
SpongeCraftingRecipeRegistry: delegates registration to the CraftingManager
SpongeIngredientBuilder: Builder for Ingredients
SpongeShapedCraftingRecipeBuilder: Builder for shaped CraftingRecipes
SpongeShapelessCraftingRecipeBuilder: Builder for shapeless CraftingRecipes

MatchSmeltingVanillaItemStack:
SpongeSmeltingRecipe:
SpongeSmeltingRecipeBuilder

MixinContainerCrafting:
MixinIRecipe: make IRecipe implement CraftingRecipe
MixinIngredient: make native Ingredient implement Ingredient
MixinShapedRecipes: make ShapedRecipes implement ShapedCraftingRecipe
MixinShapelessRecipes: make ShapelessRecipes implement ShapelessCraftingRecipe
MixinFurnaceRecipes: make FurnaceRecipes implement SmeltingRecipeRegistry

CommonModuleRegistry: register Builders: Ingredient, ShapedCraftingRecipe, ShapelessCraftingRecipe, SmeltingRecipe


Ideas for Further enhancement:

  • Pass the crafter to the recipe to allow for more customization. Possible?

@Faithcaio Faithcaio added status: wip Work in progress version: 1.12 (u) API: 7 (unsupported since May 21st 2021) labels Jun 15, 2017
@Faithcaio Faithcaio mentioned this pull request Jun 15, 2017
11 tasks
public boolean apply(@Nullable net.minecraft.item.ItemStack p_apply_1_) {

// first check for matching predicates
if (predicates.stream().anyMatch(p -> p.test(ItemStackUtil.fromNative(p_apply_1_)))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.

}

@Override
public boolean apply(@Nullable net.minecraft.item.ItemStack p_apply_1_) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parameter could use a better name.

}

@Override
public boolean apply(@Nullable ItemStack p_apply_1_) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parameter could use a better name


@Override
public boolean apply(@Nullable ItemStack p_apply_1_) {
return delegate.test(ItemStackUtil.fromNative(p_apply_1_));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.

@Override
public Collection<CraftingRecipe> getRecipes() {
// TODO Unmodifiable?
return Streams.stream(CraftingManager.REGISTRY.iterator()).map(CraftingRecipe.class::cast).collect(Collectors.toList());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.collect(ImmutableList.toImmutableList())


@Override
public ShapedCraftingRecipe.Builder group(@Nullable String name) {
this.groupName = name == null ? "" : name;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Strings.nullToEmpty

@@ -82,6 +83,11 @@
@Shadow
public abstract Slot getSlot(int slotId);

@Shadow
public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, EntityPlayer player) {
throw new IllegalStateException("Shadowed.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not making this abstract?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MixinContainerCrafting extends this and calls super.slotClick

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, one of the rare cases!

public RecipeRegistry getRecipeRegistry() {
throw new UnsupportedOperationException(); // TODO
public CraftingRecipeRegistry getCraftingRecipeRegistry() {
return new SpongeCraftingRecipeRegistry(); // TODO cache it somewhere
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cache it in SpongeCraftingRecipeRegistry?



public net.minecraft.entity.passive.EntityVillager field_175561_bA # DEFAULT_TRADE_LIST_MAP
public net.minecraft.entity.EntityList func_191303_a(ILjava/lang/String;Ljava/lang/Class;Ljava/lang/String;)V # register
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

must have happened when rebasing stuff

@@ -28,6 +28,7 @@

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Streams;
import com.google.inject.Singleton;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want this annotation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nobody can know!

@kashike kashike mentioned this pull request Jun 17, 2017
@Faithcaio Faithcaio removed the status: wip Work in progress label Jun 17, 2017
@Faithcaio Faithcaio force-pushed the feature/recipe branch 3 times, most recently from b44fa86 to d5aad0a Compare June 17, 2017 22:19
}

@Inject(method = "getSmeltingResult", at = @At("RETURN"), cancellable = true)
public void onGetSmeltingResult(ItemStack stack, CallbackInfoReturnable<ItemStack> cir) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need to have this public

}

@Inject(method = "getSmeltingExperience", at = @At("RETURN"), cancellable = true)
public void onGetSmeltingExperience(ItemStack stack, CallbackInfoReturnable<Float> cir) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need to have this public

@Faithcaio Faithcaio force-pushed the feature/recipe branch 3 times, most recently from 68e8a4c to 96ebeb6 Compare June 18, 2017 12:11
@Faithcaio
Copy link
Contributor Author

2a7a366

@Faithcaio Faithcaio closed this Jun 18, 2017
@Faithcaio Faithcaio deleted the feature/recipe branch June 18, 2017 19:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
system: inventory version: 1.12 (u) API: 7 (unsupported since May 21st 2021)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants