Skip to content

Commit

Permalink
Merge pull request #336 from WolfyScript/cooking-recipe-fixes
Browse files Browse the repository at this point in the history
Fix Vanilla Cooking Recipe Placeholders using Result item as source
  • Loading branch information
WolfyScript authored Nov 19, 2023
2 parents 5d99bba + b99119e commit adc0d00
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 27 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ dependencies {
compileOnly("io.netty:netty-all:4.1.85.Final")
compileOnly("me.clip:placeholderapi:2.10.4")
compileOnly("com.github.oraxen:oraxen:1.156.0")
compileOnly("com.wolfyscript.wolfyutils.spigot:wolfyutils-spigot:4.16.15-beta.1-SNAPSHOT")
compileOnly("com.wolfyscript.wolfyutils.spigot:wolfyutils-spigot:4.16.15-beta.2")
}

group = "com.wolfyscript.customcrafting"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.inventory.BlastingRecipe;
import org.bukkit.inventory.RecipeChoice;

public class CustomRecipeBlasting extends CustomRecipeCooking<CustomRecipeBlasting, BlastingRecipe> {

Expand Down Expand Up @@ -65,9 +64,9 @@ private CustomRecipeBlasting(CustomRecipeBlasting customRecipeBlasting) {
@Override
public BlastingRecipe getVanillaRecipe() {
if (!getSource().isEmpty()) {
BlastingRecipe placeholderRecipe = new BlastingRecipe(ICustomVanillaRecipe.toPlaceholder(getNamespacedKey()).bukkit(), getResult().getItemStack(), new RecipeChoice.MaterialChoice(getResult().getItemStack().getType()), getExp(), getCookingTime());
BlastingRecipe placeholderRecipe = new BlastingRecipe(ICustomVanillaRecipe.toPlaceholder(getNamespacedKey()).bukkit(), getResult().getItemStack(), getMaterialSourceChoice(), getExp(), getCookingTime());
Bukkit.addRecipe(placeholderRecipe);
return new BlastingRecipe(ICustomVanillaRecipe.toDisplayKey(getNamespacedKey()).bukkit(), getResult().getItemStack(), getRecipeChoice(), getExp(), getCookingTime());
return new BlastingRecipe(ICustomVanillaRecipe.toDisplayKey(getNamespacedKey()).bukkit(), getResult().getItemStack(), getSourceChoice(), getExp(), getCookingTime());
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,13 @@

import com.google.common.base.Preconditions;

import com.wolfyscript.utilities.bukkit.world.items.reference.ItemCreateContext;
import com.wolfyscript.utilities.bukkit.world.items.reference.StackReference;
import me.wolfyscript.customcrafting.CustomCrafting;
import me.wolfyscript.customcrafting.data.CCCache;
import me.wolfyscript.customcrafting.data.CCPlayerData;
import me.wolfyscript.customcrafting.gui.recipebook.ButtonContainerIngredient;
import me.wolfyscript.customcrafting.gui.recipebook.ClusterRecipeBook;
import me.wolfyscript.customcrafting.recipes.conditions.Condition;
import me.wolfyscript.customcrafting.recipes.conditions.Conditions;
import me.wolfyscript.customcrafting.recipes.items.Ingredient;
import me.wolfyscript.customcrafting.recipes.items.Result;
import com.wolfyscript.utilities.validator.Validator;
Expand All @@ -47,12 +45,9 @@
import me.wolfyscript.utilities.api.inventory.gui.GuiHandler;
import me.wolfyscript.utilities.api.inventory.gui.GuiUpdate;
import me.wolfyscript.utilities.api.inventory.gui.GuiWindow;
import com.wolfyscript.utilities.bukkit.nms.item.crafting.FunctionalRecipeBuilderCooking;
import me.wolfyscript.utilities.api.nms.network.MCByteBuf;
import me.wolfyscript.utilities.util.NamespacedKey;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.CookingRecipe;
import org.bukkit.inventory.RecipeChoice;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -147,22 +142,13 @@ public void setExp(float exp) {
this.exp = exp;
}

protected RecipeChoice getRecipeChoice() {
protected RecipeChoice getSourceChoice() {
return isCheckNBT() ? new RecipeChoice.ExactChoice(getSource().choices().stream().map(StackReference::referencedStack).toList()) :
new RecipeChoice.MaterialChoice(getSource().choices().stream().map(i -> i.referencedStack().getType()).toList());
}

protected void registerRecipeIntoMinecraft(FunctionalRecipeBuilderCooking builder) {
builder.setGroup(group);
builder.setExperience(getExp());
builder.setCookingTime(getCookingTime());
builder.setRecipeMatcher((inventory, world) -> {
Location location = inventory.getLocation();
if (location != null && !checkConditions(Conditions.Data.of(null, location.getBlock(), null))) return false;
return getSource().test(inventory.getItem(0), isCheckNBT());
});
builder.setRecipeAssembler(inventory -> java.util.Optional.ofNullable(getResult().getItemStack()));
builder.createAndRegister();
protected RecipeChoice getMaterialSourceChoice() {
return new RecipeChoice.MaterialChoice(getSource().choices().stream().map(i -> i.referencedStack().getType()).toList());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.inventory.FurnaceRecipe;
import org.bukkit.inventory.RecipeChoice;

public class CustomRecipeFurnace extends CustomRecipeCooking<CustomRecipeFurnace, FurnaceRecipe> {

Expand Down Expand Up @@ -66,10 +65,10 @@ public CustomRecipeFurnace(CustomRecipeFurnace customRecipeFurnace) {
@Override
public FurnaceRecipe getVanillaRecipe() {
if (!getSource().isEmpty()) {
FurnaceRecipe placeholderRecipe = new FurnaceRecipe(ICustomVanillaRecipe.toPlaceholder(getNamespacedKey()).bukkit(), getResult().getItemStack(), new RecipeChoice.MaterialChoice(getResult().getItemStack().getType()), getExp(), getCookingTime());
FurnaceRecipe placeholderRecipe = new FurnaceRecipe(ICustomVanillaRecipe.toPlaceholder(getNamespacedKey()).bukkit(), getResult().getItemStack(), getMaterialSourceChoice(), getExp(), getCookingTime());
Bukkit.addRecipe(placeholderRecipe);
//registerRecipeIntoMinecraft(new FunctionalRecipeBuilderSmelting(getNamespacedKey(), getResult().getItemStack(), getRecipeChoice()));
return new FurnaceRecipe(ICustomVanillaRecipe.toDisplayKey(getNamespacedKey()).bukkit(), getResult().getItemStack(), getRecipeChoice(), getExp(), getCookingTime());
return new FurnaceRecipe(ICustomVanillaRecipe.toDisplayKey(getNamespacedKey()).bukkit(), getResult().getItemStack(), getSourceChoice(), getExp(), getCookingTime());
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import me.wolfyscript.utilities.util.NamespacedKey;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.inventory.RecipeChoice;
import org.bukkit.inventory.SmokingRecipe;

public class CustomRecipeSmoking extends CustomRecipeCooking<CustomRecipeSmoking, SmokingRecipe> {
Expand Down Expand Up @@ -75,9 +74,9 @@ public boolean validType(Material material) {
@Override
public SmokingRecipe getVanillaRecipe() {
if (!getSource().isEmpty()) {
SmokingRecipe placeholderRecipe = new SmokingRecipe(ICustomVanillaRecipe.toPlaceholder(getNamespacedKey()).bukkit(), getResult().getItemStack(), new RecipeChoice.MaterialChoice(getResult().getItemStack().getType()), getExp(), getCookingTime());
SmokingRecipe placeholderRecipe = new SmokingRecipe(ICustomVanillaRecipe.toPlaceholder(getNamespacedKey()).bukkit(), getResult().getItemStack(), getMaterialSourceChoice(), getExp(), getCookingTime());
Bukkit.addRecipe(placeholderRecipe);
return new SmokingRecipe(ICustomVanillaRecipe.toDisplayKey(getNamespacedKey()).bukkit(), getResult().getItemStack(), getRecipeChoice(), getExp(), getCookingTime());
return new SmokingRecipe(ICustomVanillaRecipe.toDisplayKey(getNamespacedKey()).bukkit(), getResult().getItemStack(), getSourceChoice(), getExp(), getCookingTime());
}
return null;
}
Expand Down

0 comments on commit adc0d00

Please sign in to comment.