Skip to content
Permalink
Browse files

Update recipes to support 1.14 recipe types, input choices, recipe bo…

…ok 'group', cooking 'experience', and 'cookingtime'.

This also finally removes legacy support for '0:0' format.
  • Loading branch information...
PseudoKnight committed Aug 14, 2019
1 parent 9c6095c commit c61d93109a209ed8ca8f32a3995d5b0f33156bf9
@@ -0,0 +1,14 @@
package com.laytonsmith.abstraction;

import com.laytonsmith.abstraction.blocks.MCMaterial;

public interface MCCookingRecipe extends MCRecipe {
MCMaterial[] getInput();
void setInput(MCItemStack input);
void setInput(MCMaterial mat);
void setInput(MCMaterial... mats);
int getCookingTime();
void setCookingTime(int ticks);
float getExperience();
void setExperience(float exp);
}
@@ -3,10 +3,9 @@
import com.laytonsmith.abstraction.enums.MCRecipeType;

public interface MCRecipe extends AbstractionObject {

MCItemStack getResult();

MCRecipeType getRecipeType();

String getKey();
String getGroup();
void setGroup(String group);
}
@@ -5,14 +5,10 @@
import java.util.Map;

public interface MCShapedRecipe extends MCRecipe {

Map<Character, MCItemStack> getIngredientMap();

Map<Character, MCMaterial[]> getIngredientMap();
String[] getShape();

void setIngredient(char key, MCItemStack ingredient);

void setIngredient(char key, MCMaterial mat);

void setIngredient(char key, MCMaterial ingredient);
void setIngredient(char key, MCMaterial... ingredients);
void setShape(String[] shape);
}
@@ -5,10 +5,8 @@
import java.util.List;

public interface MCShapelessRecipe extends MCRecipe {

MCShapelessRecipe addIngredient(MCItemStack ingredient);

MCShapelessRecipe addIngredient(MCMaterial ingredient);

List<MCItemStack> getIngredients();
void addIngredient(MCItemStack ingredient);
void addIngredient(MCMaterial ingredient);
void addIngredient(MCMaterial... ingredients);
List<MCMaterial[]> getIngredients();
}
@@ -2,11 +2,9 @@

import com.laytonsmith.abstraction.blocks.MCMaterial;

public interface MCFurnaceRecipe extends MCRecipe {

MCItemStack getInput();

public interface MCStonecuttingRecipe extends MCRecipe {
MCMaterial[] getInput();
void setInput(MCItemStack input);

void setInput(MCMaterial mat);
void setInput(MCMaterial... mats);
}
@@ -117,13 +117,17 @@
import org.bukkit.entity.Tameable;
import org.bukkit.entity.Vehicle;
import org.bukkit.entity.minecart.CommandMinecart;
import org.bukkit.inventory.BlastingRecipe;
import org.bukkit.inventory.CampfireRecipe;
import org.bukkit.inventory.FurnaceRecipe;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.MerchantRecipe;
import org.bukkit.inventory.Recipe;
import org.bukkit.inventory.ShapedRecipe;
import org.bukkit.inventory.ShapelessRecipe;
import org.bukkit.inventory.SmokingRecipe;
import org.bukkit.inventory.StonecuttingRecipe;
import org.bukkit.inventory.meta.BannerMeta;
import org.bukkit.inventory.meta.BlockStateMeta;
import org.bukkit.inventory.meta.BookMeta;
@@ -641,24 +645,48 @@ public MCRecipe GetNewRecipe(String key, MCRecipeType type, MCItemStack result)
return new BukkitMCMerchantRecipe(new MerchantRecipe(is, Integer.MAX_VALUE));
}
NamespacedKey nskey = new NamespacedKey(CommandHelperPlugin.self, key);
switch(type) {
case FURNACE:
return new BukkitMCFurnaceRecipe(new FurnaceRecipe(nskey, is, Material.AIR, 0.0F, 200));
case SHAPED:
return new BukkitMCShapedRecipe(new ShapedRecipe(nskey, is));
case SHAPELESS:
return new BukkitMCShapelessRecipe(new ShapelessRecipe(nskey, is));
try {
switch(type) {
case BLASTING:
return new BukkitMCCookingRecipe(new BlastingRecipe(nskey, is, Material.AIR, 0.0F, 100), type);
case CAMPFIRE:
return new BukkitMCCookingRecipe(new CampfireRecipe(nskey, is, Material.AIR, 0.0F, 100), type);
case FURNACE:
return new BukkitMCFurnaceRecipe(new FurnaceRecipe(nskey, is, Material.AIR, 0.0F, 200));
case SHAPED:
return new BukkitMCShapedRecipe(new ShapedRecipe(nskey, is));
case SHAPELESS:
return new BukkitMCShapelessRecipe(new ShapelessRecipe(nskey, is));
case SMOKING:
return new BukkitMCCookingRecipe(new SmokingRecipe(nskey, is, Material.AIR, 0.0F, 200), type);
case STONECUTTING:
return new BukkitMCStonecuttingRecipe(new StonecuttingRecipe(nskey, is, Material.AIR));
}
} catch (NoClassDefFoundError ex) {
// doesn't exist on this version.
// eg. 1.14 recipe type on 1.13
}
return null;
throw new IllegalArgumentException("Server version does not support this recipe type: " + type.name());
}

@Override
public MCRecipe GetRecipe(MCRecipe unspecific) {
Recipe r = ((BukkitMCRecipe) unspecific).r;
Recipe r = (Recipe) unspecific.getHandle();
return BukkitGetRecipe(r);
}

public static MCRecipe BukkitGetRecipe(Recipe r) {
if(Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_14)) {
if(r instanceof BlastingRecipe) {
return new BukkitMCCookingRecipe(r, MCRecipeType.BLASTING);
} else if(r instanceof CampfireRecipe) {
return new BukkitMCCookingRecipe(r, MCRecipeType.CAMPFIRE);
} else if(r instanceof SmokingRecipe) {
return new BukkitMCCookingRecipe(r, MCRecipeType.SMOKING);
} else if(r instanceof StonecuttingRecipe) {
return new BukkitMCStonecuttingRecipe((StonecuttingRecipe) r);
}
}
if(r instanceof ShapelessRecipe) {
return new BukkitMCShapelessRecipe((ShapelessRecipe) r);
} else if(r instanceof ShapedRecipe) {
@@ -0,0 +1,103 @@
package com.laytonsmith.abstraction.bukkit;

import com.laytonsmith.abstraction.MCCookingRecipe;
import com.laytonsmith.abstraction.MCItemStack;
import com.laytonsmith.abstraction.blocks.MCMaterial;
import com.laytonsmith.abstraction.bukkit.blocks.BukkitMCMaterial;
import com.laytonsmith.abstraction.enums.MCRecipeType;
import org.bukkit.Material;
import org.bukkit.inventory.CookingRecipe;
import org.bukkit.inventory.Recipe;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.RecipeChoice;

import java.util.List;

public class BukkitMCCookingRecipe extends BukkitMCRecipe implements MCCookingRecipe {

private MCRecipeType type;

public BukkitMCCookingRecipe(Recipe recipe, MCRecipeType type) {
super(recipe);
this.type = type;
}

@Override
public String getKey() {
return getHandle().getKey().getKey();
}

@Override
public MCRecipeType getRecipeType() {
return type;
}

@Override
public String getGroup() {
return getHandle().getGroup();
}

@Override
public void setGroup(String group) {
getHandle().setGroup(group);
}

@Override
public MCItemStack getResult() {
return new BukkitMCItemStack(getHandle().getResult());
}

@Override
public CookingRecipe getHandle() {
return (CookingRecipe) super.getHandle();
}

@Override
public MCMaterial[] getInput() {
List<Material> choices = ((RecipeChoice.MaterialChoice) getHandle().getInputChoice()).getChoices();
MCMaterial[] ret = new MCMaterial[choices.size()];
for(int i = 0; i < choices.size(); i++) {
ret[i] = new BukkitMCMaterial(choices.get(i));
}
return ret;
}

@Override
public void setInput(MCItemStack input) {
getHandle().setInput(((ItemStack) input.getHandle()).getType());
}

@Override
public void setInput(MCMaterial mat) {
getHandle().setInput((Material) mat.getHandle());
}

@Override
public void setInput(MCMaterial... mats) {
Material[] concrete = new Material[mats.length];
for(int i = 0; i < mats.length; i++) {
concrete[i] = (Material) mats[i].getHandle();
}
getHandle().setInputChoice(new RecipeChoice.MaterialChoice(concrete));
}

@Override
public int getCookingTime() {
return getHandle().getCookingTime();
}

@Override
public void setCookingTime(int ticks) {
getHandle().setCookingTime(ticks);
}

@Override
public float getExperience() {
return getHandle().getExperience();
}

@Override
public void setExperience(float exp) {
getHandle().setExperience(exp);
}
}
@@ -1,54 +1,102 @@
package com.laytonsmith.abstraction.bukkit;

import com.laytonsmith.abstraction.MCFurnaceRecipe;
import com.laytonsmith.abstraction.MCCookingRecipe;
import com.laytonsmith.abstraction.MCItemStack;
import com.laytonsmith.abstraction.blocks.MCMaterial;
import com.laytonsmith.abstraction.bukkit.blocks.BukkitMCMaterial;
import com.laytonsmith.abstraction.enums.MCRecipeType;
import org.bukkit.Material;
import org.bukkit.inventory.FurnaceRecipe;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.RecipeChoice;

public class BukkitMCFurnaceRecipe extends BukkitMCRecipe implements MCFurnaceRecipe {
import java.util.List;

FurnaceRecipe fr;
public class BukkitMCFurnaceRecipe extends BukkitMCRecipe implements MCCookingRecipe {

private FurnaceRecipe recipe;

public BukkitMCFurnaceRecipe(FurnaceRecipe recipe) {
super(recipe);
fr = recipe;
this.recipe = recipe;
}

@Override
public String getKey() {
return fr.getKey().getKey();
return recipe.getKey().getKey();
}

@Override
public MCRecipeType getRecipeType() {
return MCRecipeType.FURNACE;
}

@Override
public String getGroup() {
return recipe.getGroup();
}

@Override
public void setGroup(String group) {
recipe.setGroup(group);
}

@Override
public MCItemStack getResult() {
return new BukkitMCItemStack(fr.getResult());
return new BukkitMCItemStack(recipe.getResult());
}

@Override
public Object getHandle() {
return fr;
return recipe;
}

@Override
public MCItemStack getInput() {
return new BukkitMCItemStack(fr.getInput());
public MCMaterial[] getInput() {
List<Material> choices = ((RecipeChoice.MaterialChoice) recipe.getInputChoice()).getChoices();
MCMaterial[] ret = new MCMaterial[choices.size()];
for(int i = 0; i < choices.size(); i++) {
ret[i] = new BukkitMCMaterial(choices.get(i));
}
return ret;
}

@Override
public void setInput(MCItemStack input) {
fr.setInput(((ItemStack) input.getHandle()).getType());
recipe.setInput(((ItemStack) input.getHandle()).getType());
}

@Override
public void setInput(MCMaterial mat) {
fr.setInput((Material) mat.getHandle());
recipe.setInput((Material) mat.getHandle());
}

@Override
public void setInput(MCMaterial... mats) {
Material[] concrete = new Material[mats.length];
for(int i = 0; i < mats.length; i++) {
concrete[i] = (Material) mats[i].getHandle();
}
recipe.setInputChoice(new RecipeChoice.MaterialChoice(concrete));
}

@Override
public int getCookingTime() {
return recipe.getCookingTime();
}

@Override
public void setCookingTime(int ticks) {
recipe.setCookingTime(ticks);
}

@Override
public float getExperience() {
return recipe.getExperience();
}

@Override
public void setExperience(float exp) {
recipe.setExperience(exp);
}
}
@@ -100,4 +100,12 @@ public void setIngredients(List<MCItemStack> ingredients) {
public MCRecipeType getRecipeType() {
return MCRecipeType.MERCHANT;
}

@Override
public String getGroup() {
return "";
}

@Override
public void setGroup(String group) {}
}

0 comments on commit c61d931

Please sign in to comment.
You can’t perform that action at this time.