added more types, entities
This commit is contained in:
1 parent
faf4d7b7db
commit
ce8529d084
5 files changed
+108
-48
No files matched your search
@@ -14,7 +14,6 @@ import carpet.script.CarpetContext;
|
||||
import carpet.script.EntityEventsGroup;
|
||||
import carpet.script.argument.Vector3Argument;
|
||||
import carpet.script.exception.InternalExpressionException;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.mojang.brigadier.StringReader;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
@@ -66,13 +65,11 @@ import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.registry.RegistryKey;
|
||||
import net.minecraft.world.GameMode;
|
||||
import net.minecraft.world.World;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
@@ -444,8 +441,8 @@ public class EntityValue extends Value
|
||||
ServerPlayerEntity spe = (ServerPlayerEntity)e;
|
||||
if (spe.getSpawnPointPosition() == null) return Value.FALSE;
|
||||
return ListValue.of(
|
||||
ValueConversions.fromPos(spe.getSpawnPointPosition()),
|
||||
ValueConversions.dimName(spe.getSpawnPointDimension()),
|
||||
ValueConversions.of(spe.getSpawnPointPosition()),
|
||||
ValueConversions.of(spe.getSpawnPointDimension()),
|
||||
new NumericValue(spe.getSpawnAngle()),
|
||||
new NumericValue(spe.isSpawnPointSet()) // true if forced spawn point
|
||||
);
|
||||
@@ -715,7 +712,7 @@ public class EntityValue extends Value
|
||||
hitres = Tracer.rayTraceBlocks(e, 1, reach, liquids);
|
||||
|
||||
if (hitres == null) return Value.NULL;
|
||||
if (exact && hitres.getType() != HitResult.Type.MISS) return ValueConversions.fromVec(hitres.getPos());
|
||||
if (exact && hitres.getType() != HitResult.Type.MISS) return ValueConversions.of(hitres.getPos());
|
||||
switch (hitres.getType())
|
||||
{
|
||||
case MISS: return Value.NULL;
|
||||
|
||||
@@ -17,6 +17,7 @@ import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.dynamic.GlobalPos;
|
||||
import net.minecraft.util.math.BlockBox;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.ColumnPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.registry.RegistryKey;
|
||||
@@ -33,25 +34,27 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class ValueConversions
|
||||
{
|
||||
public static Value fromPos(BlockPos pos)
|
||||
public static Value of(BlockPos pos)
|
||||
{
|
||||
return ListValue.of(new NumericValue(pos.getX()), new NumericValue(pos.getY()), new NumericValue(pos.getZ()));
|
||||
}
|
||||
|
||||
public static Value fromPosOptional(BlockPos pos)
|
||||
public static Value ofOptional(BlockPos pos)
|
||||
{
|
||||
if (pos == null) return Value.NULL;
|
||||
return ListValue.of(new NumericValue(pos.getX()), new NumericValue(pos.getY()), new NumericValue(pos.getZ()));
|
||||
}
|
||||
|
||||
public static Value fromVec(Vec3d vec)
|
||||
public static Value of(Vec3d vec)
|
||||
{
|
||||
return ListValue.of(new NumericValue(vec.x), new NumericValue(vec.y), new NumericValue(vec.z));
|
||||
}
|
||||
|
||||
public static Value dimName(ServerWorld world)
|
||||
public static Value of(ColumnPos cpos) { return ListValue.of(new NumericValue(cpos.x), new NumericValue(cpos.z));}
|
||||
|
||||
public static Value of(ServerWorld world)
|
||||
{
|
||||
return ofId(world.getRegistryKey().getValue());
|
||||
return of(world.getRegistryKey().getValue());
|
||||
}
|
||||
|
||||
public static World dimFromValue(Value dimensionValue, MinecraftServer server)
|
||||
@@ -105,12 +108,12 @@ public class ValueConversions
|
||||
}
|
||||
}
|
||||
|
||||
public static Value dimName(RegistryKey<World> dim)
|
||||
public static Value of(RegistryKey<World> dim)
|
||||
{
|
||||
return ofId(dim.getValue());
|
||||
return of(dim.getValue());
|
||||
}
|
||||
|
||||
public static Value ofId(Identifier id)
|
||||
public static Value of(Identifier id)
|
||||
{
|
||||
if (id == null) // should be Value.NULL
|
||||
return Value.NULL;
|
||||
@@ -128,11 +131,11 @@ public class ValueConversions
|
||||
return id.toString();
|
||||
}
|
||||
|
||||
public static Value ofGlobalPos(GlobalPos pos)
|
||||
public static Value of(GlobalPos pos)
|
||||
{
|
||||
return ListValue.of(
|
||||
ValueConversions.dimName(pos.getDimension()),
|
||||
ValueConversions.fromPos(pos.getPos())
|
||||
ValueConversions.of(pos.getDimension()),
|
||||
ValueConversions.of(pos.getPos())
|
||||
);
|
||||
}
|
||||
|
||||
@@ -165,7 +168,7 @@ public class ValueConversions
|
||||
if (v instanceof GlobalPos)
|
||||
{
|
||||
GlobalPos pos = (GlobalPos)v;
|
||||
return ofGlobalPos(pos);
|
||||
return of(pos);
|
||||
}
|
||||
if (v instanceof Entity)
|
||||
{
|
||||
@@ -226,7 +229,7 @@ public class ValueConversions
|
||||
}
|
||||
if (el instanceof GlobalPos)
|
||||
{
|
||||
return ListValue.wrap((List<Value>) l.stream().map(o -> ofGlobalPos((GlobalPos) o)).collect(Collectors.toList()));
|
||||
return ListValue.wrap((List<Value>) l.stream().map(o -> of((GlobalPos) o)).collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
return Value.NULL;
|
||||
@@ -241,7 +244,7 @@ public class ValueConversions
|
||||
);
|
||||
}
|
||||
|
||||
public static Value fromStructure(StructureStart<?> structure)
|
||||
public static Value of(StructureStart<?> structure)
|
||||
{
|
||||
if (structure == null || structure == StructureStart.DEFAULT) return Value.NULL;
|
||||
List<Value> pieces = new ArrayList<>();
|
||||
|
||||
Reference in new issue
Block a user