hash code and stump of map
This commit is contained in:
1 parent
b6fe264a76
commit
8b7b285503
12 files changed
+125
-5
No files matched your search
@@ -2155,6 +2155,12 @@ public class CarpetExpression
|
|||||||
y = miny;
|
y = miny;
|
||||||
z = minz;
|
z = minz;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getString()
|
||||||
|
{
|
||||||
|
return String.format("rect[(%d,%d,%d),..,(%d,%d,%d)]",minx, miny, minz, maxx, maxy, maxz);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -2246,6 +2252,12 @@ public class CarpetExpression
|
|||||||
curradius = 0;
|
curradius = 0;
|
||||||
curpos = 0;
|
curpos = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getString()
|
||||||
|
{
|
||||||
|
return String.format("diamond[(%d,%d,%d),%d,0]",cx, cy, cz, width);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -2302,6 +2314,12 @@ public class CarpetExpression
|
|||||||
curpos = 0;
|
curpos = 0;
|
||||||
curheight = -height;
|
curheight = -height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getString()
|
||||||
|
{
|
||||||
|
return String.format("diamond[(%d,%d,%d),%d,%d]",cx, cy, cz, width, height);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -2402,6 +2402,8 @@ public class Expression implements Cloneable
|
|||||||
*/
|
*/
|
||||||
public void SystemFunctions()
|
public void SystemFunctions()
|
||||||
{
|
{
|
||||||
|
addUnaryFunction("hash_code", v -> new NumericValue(v.hashCode()));
|
||||||
|
|
||||||
addLazyFunction("bool", 1, (c, t, lv) -> {
|
addLazyFunction("bool", 1, (c, t, lv) -> {
|
||||||
Value v = lv.get(0).evalValue(c, Context.BOOLEAN);
|
Value v = lv.get(0).evalValue(c, Context.BOOLEAN);
|
||||||
if (v instanceof StringValue)
|
if (v instanceof StringValue)
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import net.minecraft.item.ItemPlacementContext;
|
|||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.server.world.ServerWorld;
|
import net.minecraft.server.world.ServerWorld;
|
||||||
|
import net.minecraft.util.GlobalPos;
|
||||||
import net.minecraft.util.Hand;
|
import net.minecraft.util.Hand;
|
||||||
import net.minecraft.util.hit.BlockHitResult;
|
import net.minecraft.util.hit.BlockHitResult;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
@@ -254,6 +255,14 @@ public class BlockValue extends Value
|
|||||||
return new BlockValue(blockState, world, pos);
|
return new BlockValue(blockState, world, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode()
|
||||||
|
{
|
||||||
|
if (world != null && pos != null )
|
||||||
|
return GlobalPos.create(world.getDimension().getType(), pos).hashCode();
|
||||||
|
return ("b"+getString()).hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
public BlockPos getPos()
|
public BlockPos getPos()
|
||||||
{
|
{
|
||||||
return pos;
|
return pos;
|
||||||
|
|||||||
@@ -138,6 +138,13 @@ public class EntityValue extends Value
|
|||||||
return "entity";
|
return "entity";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode()
|
||||||
|
{
|
||||||
|
return entity.hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
public static Pair<EntityType<?>, Predicate<? super Entity>> getPredicate(String who)
|
public static Pair<EntityType<?>, Predicate<? super Entity>> getPredicate(String who)
|
||||||
{
|
{
|
||||||
Pair<EntityType<?>, Predicate<? super Entity>> res = entityPredicates.get(who);
|
Pair<EntityType<?>, Predicate<? super Entity>> res = entityPredicates.get(who);
|
||||||
|
|||||||
@@ -43,5 +43,11 @@ public class FunctionSignatureValue extends Value
|
|||||||
}
|
}
|
||||||
public List<String> getGlobals() {return globals;}
|
public List<String> getGlobals() {return globals;}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode()
|
||||||
|
{
|
||||||
|
throw new UnsupportedOperationException("function signature value cannot be used as map key");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -19,4 +19,10 @@ public class GlobalValue extends Value
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode()
|
||||||
|
{
|
||||||
|
throw new UnsupportedOperationException("global value cannot be used as map key");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -44,6 +44,12 @@ public abstract class LazyListValue extends AbstractListValue implements Iterato
|
|||||||
{
|
{
|
||||||
return stepp > 0?(current < limit):(current > limit);
|
return stepp > 0?(current < limit):(current > limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getString()
|
||||||
|
{
|
||||||
|
return String.format("[%d, %d, ..., %d]",start, start+stepp, limit);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,4 +151,10 @@ public abstract class LazyListValue extends AbstractListValue implements Iterato
|
|||||||
((LazyListValue)copy).reset();
|
((LazyListValue)copy).reset();
|
||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode()
|
||||||
|
{
|
||||||
|
return ("i"+getString()).hashCode();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -4,11 +4,7 @@ import carpet.script.exception.InternalExpressionException;
|
|||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.registry.Registry;
|
import net.minecraft.util.registry.Registry;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
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.Collectors;
|
||||||
|
|
||||||
import static java.lang.Math.abs;
|
import static java.lang.Math.abs;
|
||||||
@@ -322,9 +318,16 @@ public class ListValue extends AbstractListValue
|
|||||||
index = index % numitems;
|
index = index % numitems;
|
||||||
return items.get((int)index);
|
return items.get((int)index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeString()
|
public String getTypeString()
|
||||||
{
|
{
|
||||||
return "list";
|
return "list";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode()
|
||||||
|
{
|
||||||
|
return items.hashCode();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package carpet.script.value;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class MapValue extends AbstractListValue
|
||||||
|
{
|
||||||
|
private Map<Value, Value> map;
|
||||||
|
public MapValue()
|
||||||
|
{
|
||||||
|
map = new HashMap<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterator<Value> iterator()
|
||||||
|
{
|
||||||
|
return map.keySet().iterator();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getString()
|
||||||
|
{
|
||||||
|
return Arrays.toString(map.entrySet().toArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean getBoolean()
|
||||||
|
{
|
||||||
|
return !map.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -44,4 +44,10 @@ public class NullValue extends NumericValue // TODO check nonsingleton code
|
|||||||
{
|
{
|
||||||
return "null";
|
return "null";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -179,4 +179,13 @@ public class NumericValue extends Value
|
|||||||
return "number";
|
return "number";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode()
|
||||||
|
{
|
||||||
|
if (Math.abs(Math.floor(value + 0.5D)-value) < epsilon) // is sufficiently close to the integer value
|
||||||
|
return Long.hashCode(getLong());
|
||||||
|
return Double.hashCode(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -182,4 +182,12 @@ public abstract class Value implements Comparable<Value>, Cloneable
|
|||||||
{
|
{
|
||||||
throw new InternalExpressionException("How did you get here? Cannot get type of an intenal type.");
|
throw new InternalExpressionException("How did you get here? Cannot get type of an intenal type.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode()
|
||||||
|
{
|
||||||
|
String stringVal = getString();
|
||||||
|
if (stringVal.isEmpty()) return 0;
|
||||||
|
return ("s"+stringVal).hashCode();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user