Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

Commit

Permalink
properly duplicate items
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed May 21, 2018
1 parent 01f9c8e commit 0449406
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
Expand Up @@ -67,7 +67,7 @@ public void execute(CommandQueue queue, CommandEntry entry) {
queue.outGood("Giving " + ColorSet.emphasis + player.debug() + ColorSet.good
+ ": " + ColorSet.emphasis + item.debug());
}
InventoryTransactionResult itr = player.getInternal().getInventory().offer(item.getInternal());
InventoryTransactionResult itr = player.getInternal().getInventory().offer(item.getInternal().copy());
for (ItemStackSnapshot iss : itr.getReplacedItems()) {
if (queue.shouldShowGood()) {
queue.outGood("Gave: " + new ItemTag(iss.createStack()).debug());
Expand Down
Expand Up @@ -104,7 +104,7 @@ public boolean init() {

public ItemStack getItemCopy(CommandQueue queue) {
if (staticItem != null) {
return staticItem;
return staticItem.copy();
}
return generateItem(queue);
}
Expand Down
Expand Up @@ -41,7 +41,8 @@ public class ItemTag extends AbstractTagObject {
private ItemStack internal;

public ItemTag(ItemStack itm) {
internal = itm;
// TODO: option to get ItemTag that doesn't auto-copy?
internal = itm.copy();
}

public ItemStack getInternal() {
Expand Down Expand Up @@ -300,7 +301,7 @@ public ItemScript getSourceScript() {
}
MapTag toApply = MapTag.getFor(dat.error, dat.getNextModifier());
flags.getInternal().putAll(toApply.getInternal());
ItemStack its = ((ItemTag) obj).internal.createSnapshot().createStack();
ItemStack its = ((ItemTag) obj).internal.copy();
its.offer(new FlagMapDataImpl(new FlagMap(flags)));
return new ItemTag(its);
});
Expand All @@ -313,7 +314,7 @@ public ItemScript getSourceScript() {
// @Returns a copy of the item, with the specified quantity.
// -->
handlers.put("with_quantity", (dat, obj) -> {
ItemStack its = ((ItemTag) obj).internal.createSnapshot().createStack();
ItemStack its = ((ItemTag) obj).internal.copy();
its.setQuantity((int) IntegerTag.getFor(dat.error, dat.getNextModifier()).getInternal());
return new ItemTag(its);
});
Expand All @@ -327,7 +328,7 @@ public ItemScript getSourceScript() {
// TODO: Create and reference an explanation of basic item keys.
// -->
handlers.put("with", (dat, obj) -> {
ItemStack its = ((ItemTag) obj).internal.createSnapshot().createStack();
ItemStack its = ((ItemTag) obj).internal.copy();
MapTag toApply = MapTag.getFor(dat.error, dat.getNextModifier());
for (Map.Entry<String, AbstractTagObject> a : toApply.getInternal().entrySet()) {
Key k = DataKeys.getKeyForName(a.getKey());
Expand Down Expand Up @@ -360,7 +361,7 @@ public ItemScript getSourceScript() {
for (AbstractTagObject k : toRemove.getInternal()) {
flags.getInternal().remove(k.toString());
}
ItemStack its = ((ItemTag) obj).internal.createSnapshot().createStack();
ItemStack its = ((ItemTag) obj).internal.copy();
its.offer(new FlagMapDataImpl(new FlagMap(flags)));
return new ItemTag(its);
});
Expand Down

0 comments on commit 0449406

Please sign in to comment.