Merge branch 'master' into 1.17
This commit is contained in:
commit
31afc28401
4 files changed
+32
-19
No files matched your search
@@ -121,9 +121,11 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -331,7 +333,7 @@ public class Auxiliary {
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
ServerWorld world = cc.s.getWorld();
|
||||
MinecraftServer server = world.getServer();
|
||||
ServerPlayerEntity player[] = {null};
|
||||
Set<ServerPlayerEntity> playerTargets = new HashSet<>();
|
||||
List<Pair<ShapeDispatcher.ExpiringShape, Map<String,Value>>> shapes = new ArrayList<>();
|
||||
if (lv.size() == 1) // bulk
|
||||
{
|
||||
@@ -340,16 +342,16 @@ public class Auxiliary {
|
||||
for (Value list : ((ListValue) specLoad).getItems())
|
||||
{
|
||||
if (!(list instanceof ListValue)) throw new InternalExpressionException("In bulk mode - shapes need to be provided as a list of shape specs");
|
||||
shapes.add( ShapeDispatcher.fromFunctionArgs(server, world, ((ListValue) list).getItems(), player));
|
||||
shapes.add( ShapeDispatcher.fromFunctionArgs(server, world, ((ListValue) list).getItems(), playerTargets));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
shapes.add(ShapeDispatcher.fromFunctionArgs(server, world, lv, player));
|
||||
shapes.add(ShapeDispatcher.fromFunctionArgs(server, world, lv, playerTargets));
|
||||
}
|
||||
|
||||
ShapeDispatcher.sendShape(
|
||||
(player[0]==null)?cc.s.getWorld().getPlayers():Collections.singletonList(player[0]),
|
||||
(playerTargets.isEmpty())?cc.s.getWorld().getPlayers():playerTargets,
|
||||
shapes
|
||||
);
|
||||
return Value.TRUE;
|
||||
|
||||
@@ -47,6 +47,7 @@ import net.minecraft.util.registry.RegistryKey;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -65,7 +66,7 @@ public class ShapeDispatcher
|
||||
public static Pair<ExpiringShape,Map<String, Value>> fromFunctionArgs(
|
||||
MinecraftServer server, ServerWorld world,
|
||||
List<Value> lv,
|
||||
ServerPlayerEntity[] playerRef
|
||||
Set<ServerPlayerEntity> playerSet
|
||||
)
|
||||
{
|
||||
if (lv.size() < 3) throw new InternalExpressionException("'draw_shape' takes at least three parameters, shape name, duration, and its params");
|
||||
@@ -97,16 +98,25 @@ public class ShapeDispatcher
|
||||
|
||||
if (params.containsKey("player"))
|
||||
{
|
||||
ServerPlayerEntity player = EntityValue.getPlayerByValue(server, params.get("player"));
|
||||
if (player == null)
|
||||
throw new InternalExpressionException("'player' parameter needs to represent an existing player");
|
||||
Value players = params.get("player");
|
||||
List<Value> playerVals;
|
||||
if (players instanceof ListValue)
|
||||
playerVals = ((ListValue) players).getItems();
|
||||
else
|
||||
playerVals = Collections.singletonList(players);
|
||||
for (Value pVal : playerVals)
|
||||
{
|
||||
ServerPlayerEntity player = EntityValue.getPlayerByValue(server, pVal);
|
||||
if (player == null)
|
||||
throw new InternalExpressionException("'player' parameter needs to represent an existing player, not "+pVal.getString());
|
||||
playerSet.add(player);
|
||||
}
|
||||
params.remove("player");
|
||||
playerRef[0] = player;
|
||||
}
|
||||
return Pair.of(ShapeDispatcher.create(server, shapeType, params), params);
|
||||
}
|
||||
|
||||
public static void sendShape(List<ServerPlayerEntity> players, List<Pair<ExpiringShape,Map<String, Value>>> shapes)
|
||||
public static void sendShape(Collection<ServerPlayerEntity> players, List<Pair<ExpiringShape,Map<String, Value>>> shapes)
|
||||
{
|
||||
List<ServerPlayerEntity> clientPlayers = new ArrayList<>();
|
||||
List<ServerPlayerEntity> alternativePlayers = new ArrayList<>();
|
||||
|
||||
@@ -103,14 +103,14 @@ public class ListValue extends AbstractListValue implements ContainerValueInterf
|
||||
}
|
||||
public static ListValue of(Value ... list)
|
||||
{
|
||||
return ListValue.wrap(Arrays.asList(list));
|
||||
return new ListValue(new ArrayList<>(Arrays.asList(list)));
|
||||
}
|
||||
public static ListValue ofNums(Number ... list)
|
||||
{
|
||||
List<Value> valList = new ArrayList<>();
|
||||
for (Number i : list)
|
||||
valList.add(new NumericValue(i.doubleValue()));
|
||||
return ListValue.wrap(valList);
|
||||
return new ListValue(valList);
|
||||
}
|
||||
|
||||
public static LazyValue lazyEmpty()
|
||||
@@ -342,11 +342,11 @@ public class ListValue extends AbstractListValue implements ContainerValueInterf
|
||||
int size = items.size();
|
||||
int from = normalizeIndex(fromDesc, size);
|
||||
if (toDesc == null)
|
||||
return new ListValue((Collection<? extends Value>) getItems().subList(from, size));
|
||||
return new ListValue(new ArrayList<>(getItems().subList(from, size)));
|
||||
int to = normalizeIndex(toDesc, size+1);
|
||||
if (from > to)
|
||||
return ListValue.of();
|
||||
return new ListValue((Collection<? extends Value>) getItems().subList(from, to));
|
||||
return new ListValue(new ArrayList<>(getItems().subList(from, to)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -364,11 +364,11 @@ public class ListValue extends AbstractListValue implements ContainerValueInterf
|
||||
index++;
|
||||
if (val.equals(delimiter))
|
||||
{
|
||||
result.items.add(ListValue.wrap(this.items.subList(startIndex, index-1)));
|
||||
result.items.add(new ListValue(new ArrayList<>(this.items.subList(startIndex, index-1))));
|
||||
startIndex = index;
|
||||
}
|
||||
}
|
||||
result.items.add(ListValue.wrap(this.items.subList(startIndex, length())));
|
||||
result.items.add(new ListValue(new ArrayList<>(this.items.subList(startIndex, length()))));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user