move getItemStackFromValue to ValueConversions

This commit is contained in:
ch-yx authored and gnembon committed 2022-08-28 18:59:11 +02:00
1 parent 40bc200615
commit d418b7d090
3 files changed
+32 -28

No files matched your search

@@ -1701,7 +1701,7 @@ public class EntityValue extends Value
});
put("item", (e, v) -> {
ItemStack item=getItemStackFromValue(v);
ItemStack item=ValueConversions.getItemStackFromValue(v);
if(e instanceof ItemEntity itementity)
itementity.setItem(item);
if(e instanceof ItemFrame itemframe)
@@ -1712,32 +1712,6 @@ public class EntityValue extends Value
// "effect_"name []
}};
static public ItemStack getItemStackFromValue(Value value){
List<Value> items;
if(value instanceof ListValue blv && blv.length()==3){
items = blv.getItems();
}else if(value.isNull()){
return ItemStack.EMPTY;
}else{
items= List.of(StringValue.of(value.getString()),Value.ONE,Value.NULL);
}
String id=items.get(0).getString();
int count=((NumericValue)items.get(1)).getInt();
CompoundTag nbt=null;
if (!items.get(2).isNull()){
if(items.get(2) instanceof NBTSerializableValue nbtv){
nbt=nbtv.getCompoundTag();
}
else{
nbt=new NBTSerializableValue(items.get(2).getString()).getCompoundTag();
}
}
try{
return NBTSerializableValue.parseItem(id,nbt).createItemStack(count,false);
} catch (CommandSyntaxException e1) {
throw new IllegalStateException("Unexpected exception while creating item stack", e1);
}
}
public void setEvent(CarpetContext cc, String eventName, FunctionValue fun, List<Value> args)
{
EntityEventsGroup.Event event = EntityEventsGroup.Event.byName.get(eventName);