lists and maps copy by reference. use copy to get a copy.

This commit is contained in:
gnembon committed 2019-11-21 21:21:58 -04:00
1 parent 848f95cd30
commit 24c1ee8d3d
3 files changed
+10 -5

No files matched your search

@@ -2343,7 +2343,7 @@ public class CarpetExpression
cz = (int)((NumericValue) lv.get(2).evalValue(c)).getLong(); cz = (int)((NumericValue) lv.get(2).evalValue(c)).getLong();
if (lv.size()==3) if (lv.size()==3)
{ {
Value retval = new ListValue(Arrays.asList( Value retval = ListValue.of(
BlockValue.fromCoords(cc, cx, cy-1, cz), BlockValue.fromCoords(cc, cx, cy-1, cz),
BlockValue.fromCoords(cc, cx, cy, cz), BlockValue.fromCoords(cc, cx, cy, cz),
BlockValue.fromCoords(cc, cx-1, cy, cz), BlockValue.fromCoords(cc, cx-1, cy, cz),
@@ -2351,7 +2351,7 @@ public class CarpetExpression
BlockValue.fromCoords(cc, cx+1, cy, cz), BlockValue.fromCoords(cc, cx+1, cy, cz),
BlockValue.fromCoords(cc, cx, cy, cz+1), BlockValue.fromCoords(cc, cx, cy, cz+1),
BlockValue.fromCoords(cc, cx, cy+1, cz) BlockValue.fromCoords(cc, cx, cy+1, cz)
)); );
return (_c, _t ) -> retval; return (_c, _t ) -> retval;
} }
else if (lv.size()==4) else if (lv.size()==4)
@@ -58,6 +58,11 @@ public class ListValue extends AbstractListValue implements ContainerValueInterf
items.addAll(list); items.addAll(list);
} }
private ListValue(List<Value> list)
{
items = list;
}
public static Value fromItemStack(ItemStack itemstack) public static Value fromItemStack(ItemStack itemstack)
{ {
if (itemstack == null || itemstack.isEmpty()) if (itemstack == null || itemstack.isEmpty())
@@ -307,7 +312,7 @@ public class ListValue extends AbstractListValue implements ContainerValueInterf
if (from < 0 || from > size) from = size; if (from < 0 || from > size) from = size;
if (from > to) if (from > to)
return ListValue.of(); return ListValue.of();
return new ListValue(getItems().subList((int)from, (int) to)); return new ListValue((Collection<? extends Value>) getItems().subList((int)from, (int) to));
} }
@Override @Override
@@ -72,9 +72,9 @@ public class MapValue extends AbstractListValue implements ContainerValueInterfa
return new MapValue(copyMap); return new MapValue(copyMap);
} }
public MapValue(Map<Value,Value> other) private MapValue(Map<Value,Value> other)
{ {
map = new HashMap<>(other); map = other;
} }
@Override @Override