Skip to content

Commit

Permalink
Remove trade storage and recipe format reliance.
Browse files Browse the repository at this point in the history
  • Loading branch information
jb-aero committed Oct 18, 2018
1 parent 754381a commit b8996e9
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 232 deletions.
Expand Up @@ -624,13 +624,15 @@ public void run() {

@Override
public MCRecipe GetNewRecipe(String key, MCRecipeType type, MCItemStack result) {

ItemStack is = ((BukkitMCItemStack) result).asItemStack();
if(type == MCRecipeType.MERCHANT) {
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 MERCHANT:
return new BukkitMCMerchantRecipe(new MerchantRecipe(is, Integer.MAX_VALUE), key);
case SHAPED:
return new BukkitMCShapedRecipe(new ShapedRecipe(nskey, is));
case SHAPELESS:
Expand Down
Expand Up @@ -17,14 +17,9 @@ public class BukkitMCMerchant implements MCMerchant {

private String title;
private Merchant merchant;
private List<String> keys;
public BukkitMCMerchant(Merchant mer, String title) {
merchant = mer;
this.title = title;
keys = new ArrayList<>();
for(int i = 0; i < merchant.getRecipes().size(); i++) {
keys.add(null);
}
}

@Override
Expand Down Expand Up @@ -67,19 +62,17 @@ public MCHumanEntity getTrader() {
@Override
public List<MCMerchantRecipe> getRecipes() {
List<MCMerchantRecipe> ret = new ArrayList<>();
for(int i = 0; i < getHandle().getRecipes().size(); i++) {
ret.add(new BukkitMCMerchantRecipe(getHandle().getRecipe(i), keys.get(i)));
for(MerchantRecipe mr : getHandle().getRecipes()) {
ret.add(new BukkitMCMerchantRecipe(mr));
}
return ret;
}

@Override
public void setRecipes(List<MCMerchantRecipe> recipes) {
List<MerchantRecipe> ret = new ArrayList<>();
keys.clear();
for(MCMerchantRecipe mr : recipes) {
ret.add((MerchantRecipe) mr.getHandle());
keys.add(mr.getKey());
}
getHandle().setRecipes(ret);
}
Expand Down
Expand Up @@ -12,20 +12,14 @@
public class BukkitMCMerchantRecipe extends BukkitMCRecipe implements MCMerchantRecipe {

private MerchantRecipe handle;
private String key;
public BukkitMCMerchantRecipe(MerchantRecipe recipe) {
this(recipe, null);
}

public BukkitMCMerchantRecipe(MerchantRecipe recipe, String key) {
super(recipe);
handle = recipe;
this.key = key;
}

@Override
public String getKey() {
return key;
return null;
}

@Override
Expand Down
37 changes: 0 additions & 37 deletions src/main/java/com/laytonsmith/core/ObjectGenerator.java
Expand Up @@ -24,7 +24,6 @@
import com.laytonsmith.abstraction.MCLivingEntity;
import com.laytonsmith.abstraction.MCLocation;
import com.laytonsmith.abstraction.MCMapMeta;
import com.laytonsmith.abstraction.MCMerchantRecipe;
import com.laytonsmith.abstraction.MCMetadataValue;
import com.laytonsmith.abstraction.MCPattern;
import com.laytonsmith.abstraction.MCPlugin;
Expand Down Expand Up @@ -1455,16 +1454,6 @@ public Construct recipe(MCRecipe r, Target t) {
}
ret.set("shape", shape, t);
ret.set("ingredients", imap, t);
} else if(r instanceof MCMerchantRecipe) {
MCMerchantRecipe merchant = (MCMerchantRecipe) r;
CArray il = new CArray(t);
for(MCItemStack i : merchant.getIngredients()) {
il.push(item(i, t), t);
}
ret.set("ingredients", il, t);
ret.set("maxuses", new CInt(merchant.getMaxUses(), t), t);
ret.set("uses", new CInt(merchant.getUses(), t), t);
ret.set("hasxpreward", CBoolean.get(merchant.hasExperienceReward()), t);
}
return ret;
}
Expand Down Expand Up @@ -1591,32 +1580,6 @@ public MCRecipe recipe(Construct c, Target t) {
}
return ret;

case MERCHANT:
MCMerchantRecipe mer = (MCMerchantRecipe) ret;
if(recipe.containsKey("maxuses")) {
mer.setMaxUses(Static.getInt32(recipe.get("maxuses", t), t));
}
if(recipe.containsKey("uses")) {
mer.setUses(Static.getInt32(recipe.get("uses", t), t));
}
if(recipe.containsKey("hasxpreward")) {
mer.setHasExperienceReward(Static.getBoolean(recipe.get("hasxpreward", t), t));
}
ingredients = Static.getArray(recipe.get("ingredients", t), t);
if(ingredients.inAssociativeMode()) {
throw new CREFormatException("Ingredients array is invalid.", t);
}
if(ingredients.size() < 1 || ingredients.size() > 2) {
throw new CRERangeException("Ingredients for merchants must contain 1 or 2 items, found "
+ ingredients.size(), t);
}
List<MCItemStack> mcIngredients = new ArrayList<>();
for(Construct ingredient : ingredients.asList()) {
mcIngredients.add(item(ingredient, t));
}
mer.setIngredients(mcIngredients);
return ret;

default:
throw new CREFormatException("Could not find valid recipe type.", t);
}
Expand Down

0 comments on commit b8996e9

Please sign in to comment.