Merge branch 'master' into 1.17
This commit is contained in:
commit
ed4afa15ff
49 files changed
+593
-211
No files matched your search
@@ -4,7 +4,7 @@ import carpet.script.exception.InternalExpressionException;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
public abstract class AbstractListValue extends Value
|
||||
public abstract class AbstractListValue extends Value implements Iterable<Value>
|
||||
{
|
||||
public abstract Iterator<Value> iterator();
|
||||
public void fatality() { }
|
||||
|
||||
@@ -7,6 +7,7 @@ import carpet.fakes.LivingEntityInterface;
|
||||
import carpet.fakes.MemoryInterface;
|
||||
import carpet.fakes.MobEntityInterface;
|
||||
import carpet.fakes.HungerManagerInterface;
|
||||
import carpet.fakes.ServerPlayerEntityInterface;
|
||||
import carpet.fakes.ServerPlayerInteractionManagerInterface;
|
||||
import carpet.helpers.Tracer;
|
||||
import carpet.network.ServerNetworkHandler;
|
||||
@@ -91,7 +92,7 @@ import static carpet.utils.MobAI.genericJump;
|
||||
// TODO: decide whether copy(entity) should duplicate entity in the world.
|
||||
public class EntityValue extends Value
|
||||
{
|
||||
private final Entity entity;
|
||||
private Entity entity;
|
||||
|
||||
public EntityValue(Entity e)
|
||||
{
|
||||
@@ -120,6 +121,11 @@ public class EntityValue extends Value
|
||||
|
||||
public Entity getEntity()
|
||||
{
|
||||
if (entity instanceof ServerPlayerEntity && ((ServerPlayerEntityInterface)entity).isInvalidEntityObject())
|
||||
{
|
||||
ServerPlayerEntity newPlayer = entity.getServer().getPlayerManager().getPlayer(entity.getUuid());
|
||||
if (newPlayer != null) entity = newPlayer;
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
|
||||
@@ -171,7 +177,7 @@ public class EntityValue extends Value
|
||||
@Override
|
||||
public String getString()
|
||||
{
|
||||
return entity.getName().getString();
|
||||
return getEntity().getName().getString();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -185,7 +191,7 @@ public class EntityValue extends Value
|
||||
{
|
||||
if (v instanceof EntityValue)
|
||||
{
|
||||
return entity.getEntityId()==((EntityValue) v).entity.getEntityId();
|
||||
return getEntity().getEntityId()==((EntityValue) v).getEntity().getEntityId();
|
||||
}
|
||||
return super.equals((Value)v);
|
||||
}
|
||||
@@ -221,7 +227,7 @@ public class EntityValue extends Value
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return entity.hashCode();
|
||||
return getEntity().hashCode();
|
||||
}
|
||||
|
||||
public static EntityClassDescriptor getEntityDescriptor(String who, MinecraftServer server)
|
||||
@@ -389,7 +395,7 @@ public class EntityValue extends Value
|
||||
throw new InternalExpressionException("Unknown entity feature: "+what);
|
||||
try
|
||||
{
|
||||
return featureAccessors.get(what).apply(entity, arg);
|
||||
return featureAccessors.get(what).apply(getEntity(), arg);
|
||||
}
|
||||
catch (NullPointerException npe)
|
||||
{
|
||||
@@ -850,7 +856,7 @@ public class EntityValue extends Value
|
||||
throw new InternalExpressionException("Unknown entity action: " + what);
|
||||
try
|
||||
{
|
||||
featureModifiers.get(what).accept(entity, toWhat);
|
||||
featureModifiers.get(what).accept(getEntity(), toWhat);
|
||||
}
|
||||
catch (NullPointerException npe)
|
||||
{
|
||||
@@ -1483,7 +1489,7 @@ public class EntityValue extends Value
|
||||
EntityEventsGroup.Event event = EntityEventsGroup.Event.byName.get(eventName);
|
||||
if (event == null)
|
||||
throw new InternalExpressionException("Unknown entity event: " + eventName);
|
||||
((EntityInterface)entity).getEventContainer().addEvent(event, cc.host, fun, args);
|
||||
((EntityInterface)getEntity()).getEventContainer().addEvent(event, cc.host, fun, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1492,7 +1498,7 @@ public class EntityValue extends Value
|
||||
if (!force) throw new NBTSerializableValue.IncompatibleTypeException(this);
|
||||
CompoundTag tag = new CompoundTag();
|
||||
tag.put("Data", getEntity().toTag( new CompoundTag()));
|
||||
tag.put("Name", StringTag.of(Registry.ENTITY_TYPE.getId(entity.getType()).toString()));
|
||||
tag.put("Name", StringTag.of(Registry.ENTITY_TYPE.getId(getEntity().getType()).toString()));
|
||||
return tag;
|
||||
}
|
||||
}
|
||||
@@ -133,7 +133,7 @@ public class FunctionValue extends Value implements Fluff.ILazyFunction
|
||||
}
|
||||
|
||||
@Override
|
||||
public Value slice(long from, long to)
|
||||
public Value slice(long from, Long to)
|
||||
{
|
||||
throw new InternalExpressionException("Cannot slice a function");
|
||||
}
|
||||
|
||||
@@ -129,9 +129,9 @@ public abstract class LazyListValue extends AbstractListValue implements Iterato
|
||||
}
|
||||
|
||||
@Override
|
||||
public Value slice(long from, long to)
|
||||
public Value slice(long from, Long to)
|
||||
{
|
||||
if (to < 0) to = Integer.MAX_VALUE;
|
||||
if (to == null || to < 0) to = (long) Integer.MAX_VALUE;
|
||||
if (from < 0) from = 0;
|
||||
if (from > to)
|
||||
return ListValue.of();
|
||||
|
||||
@@ -289,27 +289,22 @@ public class ListValue extends AbstractListValue implements ContainerValueInterf
|
||||
items.add(v);
|
||||
}
|
||||
|
||||
public void addAtIndex(int index, List<Value> subList)
|
||||
/**
|
||||
* Finds a proper list index >=0 and < len that correspont to the rolling index value of idx
|
||||
*
|
||||
* @param idx
|
||||
* @param len
|
||||
* @return
|
||||
*/
|
||||
public static int normalizeIndex(long idx, int len)
|
||||
{
|
||||
int numitems = items.size();
|
||||
long range = abs(index)/numitems;
|
||||
index += (range+2)*numitems;
|
||||
index = index % numitems;
|
||||
for (Value v: subList)
|
||||
{
|
||||
if (index < numitems)
|
||||
{
|
||||
items.set(index, v);
|
||||
}
|
||||
else
|
||||
{
|
||||
items.add(v);
|
||||
}
|
||||
index++;
|
||||
}
|
||||
if (idx >=0 && idx < len) return (int)idx;
|
||||
long range = abs(idx)/len;
|
||||
idx += (range+2)*len;
|
||||
idx = idx % len;
|
||||
return (int)idx;
|
||||
}
|
||||
|
||||
|
||||
public static class ListConstructorValue extends ListValue
|
||||
{
|
||||
public ListConstructorValue(Collection<? extends Value> list)
|
||||
@@ -339,15 +334,17 @@ public class ListValue extends AbstractListValue implements ContainerValueInterf
|
||||
}
|
||||
|
||||
@Override
|
||||
public Value slice(long from, long to)
|
||||
public Value slice(long fromDesc, Long toDesc)
|
||||
{
|
||||
List<Value> items = getItems();
|
||||
int size = items.size();
|
||||
if (to < 0 || to > size) to = size;
|
||||
if (from < 0 || from > size) from = size;
|
||||
int from = normalizeIndex(fromDesc, size);
|
||||
if (toDesc == null)
|
||||
return new ListValue((Collection<? extends Value>) getItems().subList(from, size));
|
||||
int to = normalizeIndex(toDesc, size);
|
||||
if (from > to)
|
||||
return ListValue.of();
|
||||
return new ListValue((Collection<? extends Value>) getItems().subList((int)from, (int) to));
|
||||
return new ListValue((Collection<? extends Value>) getItems().subList(from, to));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -395,10 +392,8 @@ public class ListValue extends AbstractListValue implements ContainerValueInterf
|
||||
return false;
|
||||
int index = (int)((NumericValue) ind).getLong();
|
||||
if (index < 0)
|
||||
{
|
||||
long range = abs(index) / numitems;
|
||||
index += (range + 2) * numitems;
|
||||
index = index % numitems;
|
||||
{// only for values < 0
|
||||
index = normalizeIndex(index, numitems);
|
||||
}
|
||||
if (replace)
|
||||
{
|
||||
@@ -424,11 +419,7 @@ public class ListValue extends AbstractListValue implements ContainerValueInterf
|
||||
public Value get(Value value)
|
||||
{
|
||||
long index = NumericValue.asNumber(value, "'address' to a list index").getLong();
|
||||
int numitems = items.size();
|
||||
long range = abs(index)/numitems;
|
||||
index += (range+2)*numitems;
|
||||
index = index % numitems;
|
||||
return items.get((int)index);
|
||||
return items.get(normalizeIndex(index, items.size()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -443,11 +434,7 @@ public class ListValue extends AbstractListValue implements ContainerValueInterf
|
||||
{
|
||||
if (!(where instanceof NumericValue) || items.isEmpty()) return false;
|
||||
long index = ((NumericValue) where).getLong();
|
||||
int numitems = items.size();
|
||||
long range = abs(index)/numitems;
|
||||
index += (range+2)*numitems;
|
||||
index = index % numitems;
|
||||
items.remove((int)index);
|
||||
items.remove(normalizeIndex(index, items.size()));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -198,7 +198,7 @@ public class MapValue extends AbstractListValue implements ContainerValueInterfa
|
||||
}
|
||||
|
||||
@Override
|
||||
public Value slice(long from, long to)
|
||||
public Value slice(long from, Long to)
|
||||
{
|
||||
throw new InternalExpressionException("Cannot slice a map value");
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ import net.minecraft.nbt.Tag;
|
||||
|
||||
public class StringValue extends Value
|
||||
{
|
||||
public static Value EMPTY = StringValue.of("");
|
||||
|
||||
private String str;
|
||||
|
||||
@Override
|
||||
|
||||
@@ -178,16 +178,15 @@ public abstract class Value implements Comparable<Value>, Cloneable
|
||||
return getString().length();
|
||||
}
|
||||
|
||||
public Value slice(long from, long to)
|
||||
public Value slice(long fromDesc, Long toDesc)
|
||||
{
|
||||
String value = this.getString();
|
||||
int size = value.length();
|
||||
if (to > size) to = -1;
|
||||
if (from < 0) from = 0;
|
||||
if (from > size) from = size;
|
||||
if (to>=0)
|
||||
return new StringValue(value.substring((int)from, (int)to));
|
||||
return new StringValue(value.substring((int)from));
|
||||
int from = ListValue.normalizeIndex(fromDesc, size);
|
||||
if (toDesc == null) return new StringValue(value.substring(from));
|
||||
int to = ListValue.normalizeIndex(toDesc, size);
|
||||
if (from > to) return StringValue.EMPTY;
|
||||
return new StringValue(value.substring(from, to));
|
||||
}
|
||||
public double readDoubleNumber()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user