Merge branch 'master' into 1.15
This commit is contained in:
commit
125a409813
5 files changed
+35
-8
No files matched your search
@@ -28,6 +28,8 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static carpet.script.value.NBTSerializableValue.nameFromRegistryId;
|
||||
|
||||
public class BlockValue extends Value
|
||||
{
|
||||
public static final BlockValue AIR = new BlockValue(Blocks.AIR.getDefaultState(), null, BlockPos.ORIGIN);
|
||||
@@ -234,7 +236,7 @@ public class BlockValue extends Value
|
||||
@Override
|
||||
public String getString()
|
||||
{
|
||||
return Registry.BLOCK.getId(getBlockState().getBlock()).getPath();
|
||||
return nameFromRegistryId(Registry.BLOCK.getId(getBlockState().getBlock()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -56,6 +56,8 @@ import java.util.function.BiFunction;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static carpet.script.value.NBTSerializableValue.nameFromRegistryId;
|
||||
|
||||
public class EntityValue extends Value
|
||||
{
|
||||
private Entity entity;
|
||||
@@ -197,7 +199,7 @@ public class EntityValue extends Value
|
||||
put("motion_z", (e, a) -> new NumericValue(e.getVelocity().z));
|
||||
put("name", (e, a) -> new StringValue(e.getDisplayName().getString()));
|
||||
put("custom_name", (e, a) -> e.hasCustomName()?new StringValue(e.getCustomName().getString()):Value.NULL);
|
||||
put("type", (e, a) -> new StringValue(Registry.ENTITY_TYPE.getId(e.getType()).toString().replaceFirst("minecraft:","")));
|
||||
put("type", (e, a) -> new StringValue(nameFromRegistryId(Registry.ENTITY_TYPE.getId(e.getType()))));
|
||||
put("is_riding", (e, a) -> new NumericValue(e.hasVehicle()));
|
||||
put("is_ridden", (e, a) -> new NumericValue(e.hasPassengers()));
|
||||
put("passengers", (e, a) -> ListValue.wrap(e.getPassengerList().stream().map(EntityValue::new).collect(Collectors.toList())));
|
||||
@@ -217,7 +219,7 @@ public class EntityValue extends Value
|
||||
put("immune_to_fire", (e, a) -> new NumericValue(e.isFireImmune()));
|
||||
|
||||
put("invulnerable", (e, a) -> new NumericValue(e.isInvulnerable()));
|
||||
put("dimension", (e, a) -> new StringValue(e.dimension.toString().replaceFirst("minecraft:","")));
|
||||
put("dimension", (e, a) -> new StringValue(nameFromRegistryId(Registry.DIMENSION.getId(e.dimension))));
|
||||
put("height", (e, a) -> new NumericValue(e.getDimensions(EntityPose.STANDING).height));
|
||||
put("width", (e, a) -> new NumericValue(e.getDimensions(EntityPose.STANDING).width));
|
||||
put("eye_height", (e, a) -> new NumericValue(e.getEyeHeight(EntityPose.STANDING)));
|
||||
|
||||
@@ -4,10 +4,15 @@ import carpet.script.exception.InternalExpressionException;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
import static carpet.script.value.NBTSerializableValue.nameFromRegistryId;
|
||||
import static java.lang.Math.abs;
|
||||
|
||||
public class ListValue extends AbstractListValue implements ContainerValueInterface
|
||||
@@ -49,7 +54,7 @@ public class ListValue extends AbstractListValue implements ContainerValueInterf
|
||||
if (itemstack == null || itemstack.isEmpty())
|
||||
return Value.NULL;
|
||||
return ListValue.of(
|
||||
new StringValue(Registry.ITEM.getId(itemstack.getItem()).getPath()),
|
||||
new StringValue(nameFromRegistryId(Registry.ITEM.getId(itemstack.getItem()))),
|
||||
new NumericValue(itemstack.getCount()),
|
||||
NBTSerializableValue.fromStack(itemstack)
|
||||
);
|
||||
|
||||
@@ -21,6 +21,7 @@ import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.StringNbtReader;
|
||||
import net.minecraft.nbt.StringTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -71,6 +72,13 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
|
||||
return Value.NULL;
|
||||
}
|
||||
|
||||
public static String nameFromRegistryId(Identifier id)
|
||||
{
|
||||
if (id.getNamespace().equals("minecraft"))
|
||||
return id.getPath();
|
||||
return id.toString();
|
||||
}
|
||||
|
||||
public static NBTSerializableValue parseString(String nbtString)
|
||||
{
|
||||
Tag tag;
|
||||
|
||||
Reference in new issue
Block a user