fixed named results, and added loaded_status

This commit is contained in:
gnembon committed 2019-10-29 00:46:44 -03:00
1 parent 9315bc09dd
commit 6c2ddd68db
5 files changed
+35 -8

No files matched your search

@@ -77,6 +77,7 @@ import net.minecraft.world.LightType;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.WorldChunk;
import net.minecraft.world.dimension.DimensionType;
import net.minecraft.world.loot.context.LootContext;
import net.minecraft.world.loot.context.LootContextParameters;
@@ -95,6 +96,7 @@ import java.util.function.BiFunction;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import static carpet.script.value.NBTSerializableValue.nameFromRegistryId;
import static java.lang.Math.abs;
import static java.lang.Math.max;
import static java.lang.Math.min;
@@ -789,8 +791,16 @@ public class CarpetExpression
{
BlockPos pos = BlockValue.fromParams((CarpetContext)c, lv, 0).block.getPos();
Value retval = ((CarpetContext)c).s.getWorld().getChunkManager().shouldTickChunk(new ChunkPos(pos))?Value.TRUE : Value.FALSE;
//Value retval = ((CarpetContext)c).s.getWorld().isAreaLoaded(pos.getX() - 32, 0, pos.getZ() - 32,
// pos.getX() + 32, 0, pos.getZ() + 32) ? Value.TRUE : Value.FALSE;
return (c_, t_) -> retval;
});
this.expr.addLazyFunction("loaded_status", -1, (c, t, lv) ->
{
BlockPos pos = BlockValue.fromParams((CarpetContext)c, lv, 0).block.getPos();
WorldChunk chunk = ((CarpetContext)c).s.getWorld().getChunkManager().getWorldChunk(pos.getX()>>4, pos.getZ()>>4, false);
if (chunk == null)
return LazyValue.ZERO;
Value retval = new NumericValue(chunk.getLevelType().ordinal());
return (c_, t_) -> retval;
});
@@ -2869,7 +2879,7 @@ public class CarpetExpression
this.expr.addLazyFunction("current_dimension", 0, (c, t, lv) -> {
ServerCommandSource s = ((CarpetContext)c).s;
Value retval = new StringValue(s.getWorld().dimension.getType().toString().replaceFirst("minecraft:",""));
Value retval = new StringValue(nameFromRegistryId(Registry.DIMENSION.getId(s.getWorld().dimension.getType())));
return (cc, tt) -> retval;
});
@@ -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;