Skip to content

Commit

Permalink
fix TradeTag#duplicate and usages of it
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Sep 15, 2021
1 parent a23a162 commit 5b0fac3
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 7 deletions.
Expand Up @@ -81,7 +81,7 @@ public ObjectTag getContext(String name) {
return new EntityTag(event.getVillager());
}
else if (name.equals("trade")) {
return new TradeTag(event.getTrade());
return new TradeTag(event.getTrade()).duplicate();
}
return super.getContext(name);
}
Expand Down
Expand Up @@ -74,7 +74,7 @@ public ObjectTag getContext(String name) {
return entity;
}
else if (name.equals("trade")) {
return new TradeTag(event.getRecipe());
return new TradeTag(event.getRecipe()).duplicate();
}
return super.getContext(name);
}
Expand Down
Expand Up @@ -81,7 +81,7 @@ public ObjectTag getContext(String name) {
case "entity":
return entity;
case "trade":
return new TradeTag(event.getRecipe());
return new TradeTag(event.getRecipe()).duplicate();
case "bonus":
return new ElementTag(event.getBonus());
}
Expand Down
Expand Up @@ -1500,7 +1500,7 @@ else if (obj instanceof EntityTag) {
registerOnlineOnlyTag("selected_trade", (attribute, object) -> {
Inventory playerInventory = object.getPlayerEntity().getOpenInventory().getTopInventory();
if (playerInventory instanceof MerchantInventory && ((MerchantInventory) playerInventory).getSelectedRecipe() != null) {
return new TradeTag(((MerchantInventory) playerInventory).getSelectedRecipe());
return new TradeTag(((MerchantInventory) playerInventory).getSelectedRecipe()).duplicate();
}
return null;
});
Expand Down
Expand Up @@ -73,7 +73,9 @@ public TradeTag(MerchantRecipe recipe) {

@Override
public TradeTag duplicate() {
return new TradeTag(new MerchantRecipe(recipe.getResult(), recipe.getUses(), recipe.getMaxUses(), recipe.hasExperienceReward(), recipe.getVillagerExperience(), recipe.getPriceMultiplier()));
MerchantRecipe result = new MerchantRecipe(recipe.getResult(), recipe.getUses(), recipe.getMaxUses(), recipe.hasExperienceReward(), recipe.getVillagerExperience(), recipe.getPriceMultiplier());
result.setIngredients(recipe.getIngredients());
return new TradeTag(result);
}

@Override
Expand Down
Expand Up @@ -37,7 +37,7 @@ public static EntityTrades getFrom(ObjectTag entity) {
public ListTag getTradeRecipes() {
ArrayList<TradeTag> recipes = new ArrayList<>();
for (MerchantRecipe recipe : ((Merchant) entity.getBukkitEntity()).getRecipes()) {
recipes.add(new TradeTag(recipe));
recipes.add(new TradeTag(recipe).duplicate());
}
return new ListTag(recipes);
}
Expand Down
Expand Up @@ -37,7 +37,7 @@ public InventoryTrades(InventoryTag inventory) {
public ListTag getTradeRecipes() {
ArrayList<TradeTag> recipes = new ArrayList<>();
for (MerchantRecipe recipe : ((MerchantInventory) inventory.getInventory()).getMerchant().getRecipes()) {
recipes.add(new TradeTag(recipe));
recipes.add(new TradeTag(recipe).duplicate());
}
return new ListTag(recipes);
}
Expand Down

0 comments on commit 5b0fac3

Please sign in to comment.