move getItemStackFromValue to ValueConversions
This commit is contained in:
1 parent
40bc200615
commit
d418b7d090
3 files changed
+32
-28
No files matched your search
@@ -259,7 +259,7 @@ public class Auxiliary {
|
|||||||
});
|
});
|
||||||
|
|
||||||
expression.addContextFunction("item_display_name", -1, (c, t, lv)->{
|
expression.addContextFunction("item_display_name", -1, (c, t, lv)->{
|
||||||
return new FormattedTextValue(EntityValue.getItemStackFromValue(lv.get(0)).getHoverName());
|
return new FormattedTextValue(ValueConversions.getItemStackFromValue(lv.get(0)).getHoverName());
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1701,7 +1701,7 @@ public class EntityValue extends Value
|
|||||||
|
|
||||||
});
|
});
|
||||||
put("item", (e, v) -> {
|
put("item", (e, v) -> {
|
||||||
ItemStack item=getItemStackFromValue(v);
|
ItemStack item=ValueConversions.getItemStackFromValue(v);
|
||||||
if(e instanceof ItemEntity itementity)
|
if(e instanceof ItemEntity itementity)
|
||||||
itementity.setItem(item);
|
itementity.setItem(item);
|
||||||
if(e instanceof ItemFrame itemframe)
|
if(e instanceof ItemFrame itemframe)
|
||||||
@@ -1712,32 +1712,6 @@ public class EntityValue extends Value
|
|||||||
// "effect_"name []
|
// "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)
|
public void setEvent(CarpetContext cc, String eventName, FunctionValue fun, List<Value> args)
|
||||||
{
|
{
|
||||||
EntityEventsGroup.Event event = EntityEventsGroup.Event.byName.get(eventName);
|
EntityEventsGroup.Event event = EntityEventsGroup.Event.byName.get(eventName);
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import net.minecraft.core.Registry;
|
|||||||
import net.minecraft.core.RegistryAccess;
|
import net.minecraft.core.RegistryAccess;
|
||||||
import net.minecraft.core.Vec3i;
|
import net.minecraft.core.Vec3i;
|
||||||
import net.minecraft.core.particles.ParticleOptions;
|
import net.minecraft.core.particles.ParticleOptions;
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.resources.ResourceKey;
|
import net.minecraft.resources.ResourceKey;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
@@ -52,6 +53,8 @@ import java.util.function.Predicate;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.StreamSupport;
|
import java.util.stream.StreamSupport;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
|
|
||||||
public class ValueConversions
|
public class ValueConversions
|
||||||
{
|
{
|
||||||
public static Value of(BlockPos pos)
|
public static Value of(BlockPos pos)
|
||||||
@@ -411,6 +414,33 @@ public class ValueConversions
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 static Value guess(ServerLevel serverWorld, Object o) {
|
public static Value guess(ServerLevel serverWorld, Object o) {
|
||||||
if (o == null)
|
if (o == null)
|
||||||
return Value.NULL;
|
return Value.NULL;
|
||||||
|
|||||||
Reference in new issue
Block a user