Merge branch 'master' into 1.15
# Conflicts: # src/main/java/carpet/script/value/EntityValue.java
This commit is contained in:
commit
a3715f08a4
4 files changed
+71
-46
No files matched your search
@@ -71,7 +71,8 @@ public class ScriptCommand
|
||||
public static void register(CommandDispatcher<ServerCommandSource> dispatcher)
|
||||
{
|
||||
LiteralArgumentBuilder<ServerCommandSource> b = literal("globals").
|
||||
executes(ScriptCommand::listGlobals);
|
||||
executes(context -> listGlobals(context, false)).
|
||||
then(literal("all").executes(context -> listGlobals(context, true)));
|
||||
LiteralArgumentBuilder<ServerCommandSource> o = literal("stop").
|
||||
executes( (cc) -> { CarpetServer.scriptServer.stopAll = true; return 1;});
|
||||
LiteralArgumentBuilder<ServerCommandSource> u = literal("resume").
|
||||
@@ -308,13 +309,13 @@ public class ScriptCommand
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
private static int listGlobals(CommandContext<ServerCommandSource> context)
|
||||
private static int listGlobals(CommandContext<ServerCommandSource> context, boolean all)
|
||||
{
|
||||
ScriptHost host = getHost(context);
|
||||
ServerCommandSource source = context.getSource();
|
||||
|
||||
Messenger.m(source, "lb Stored functions"+((host == CarpetServer.scriptServer.globalHost)?":":" in "+host.getName()+":"));
|
||||
for (String fname : host.getAvailableFunctions())
|
||||
for (String fname : host.getAvailableFunctions(all))
|
||||
{
|
||||
Expression expr = host.getExpressionForFunction(fname);
|
||||
Tokenizer.Token tok = host.getTokenForFunction(fname);
|
||||
|
||||
@@ -978,17 +978,20 @@ public class Expression implements Cloneable
|
||||
addLazyBinaryOperatorWithDelegation("->", precedence.get("def->"), false, (c, type, e, t, lv1, lv2) ->
|
||||
{
|
||||
Value v1 = lv1.evalValue(c, Context.SIGNATURE);
|
||||
String result;
|
||||
if (v1 instanceof FunctionSignatureValue)
|
||||
{
|
||||
FunctionSignatureValue sign = (FunctionSignatureValue) v1;
|
||||
addContextFunction(c, sign.getName(), e, t, sign.getArgs(), sign.getGlobals(), lv2);
|
||||
result = sign.getName();
|
||||
}
|
||||
else
|
||||
{
|
||||
v1.assertAssignable();
|
||||
c.setVariable(v1.getVariable(), lv2);
|
||||
result = v1.getVariable();
|
||||
}
|
||||
return (cc, tt) -> new StringValue("OK");
|
||||
return (cc, tt) -> new StringValue(result);
|
||||
});
|
||||
|
||||
addFunction("exit", (lv) -> { throw new ExitStatement(lv.size()==0?Value.NULL:lv.get(0)); });
|
||||
|
||||
@@ -108,9 +108,9 @@ public class ScriptHost
|
||||
{
|
||||
return globalFunctions.keySet().stream().filter((str) -> !str.startsWith("_")).collect(Collectors.toList());
|
||||
}
|
||||
public List<String> getAvailableFunctions()
|
||||
public List<String> getAvailableFunctions(boolean all)
|
||||
{
|
||||
return globalFunctions.keySet().stream().filter((str) -> !str.startsWith("__")).collect(Collectors.toList());
|
||||
return globalFunctions.keySet().stream().filter((str) -> all || !str.startsWith("__")).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public String call(ServerCommandSource source, String call, List<Integer> coords, String arg)
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.mojang.brigadier.StringReader;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import net.minecraft.client.network.packet.EntityPassengersSetS2CPacket;
|
||||
import net.minecraft.client.network.packet.EntityPositionS2CPacket;
|
||||
import net.minecraft.client.network.packet.PlayerPositionLookS2CPacket;
|
||||
import net.minecraft.command.EntitySelector;
|
||||
import net.minecraft.command.EntitySelectorReader;
|
||||
import net.minecraft.entity.Entity;
|
||||
@@ -45,9 +46,11 @@ 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.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Predicate;
|
||||
@@ -418,13 +421,43 @@ public class EntityValue extends Value
|
||||
featureModifiers.get(what).accept(entity, toWhat);
|
||||
}
|
||||
|
||||
private static void updatePosition(Entity e)
|
||||
private static void updatePosition(Entity e, double x, double y, double z, float yaw, float pitch)
|
||||
{
|
||||
if (
|
||||
!Double.isFinite(x) || Double.isNaN(x) ||
|
||||
!Double.isFinite(y) || Double.isNaN(y) ||
|
||||
!Double.isFinite(z) || Double.isNaN(z) ||
|
||||
!Float.isFinite(yaw) || Float.isNaN(yaw) ||
|
||||
!Float.isFinite(pitch) || Float.isNaN(pitch)
|
||||
)
|
||||
return;
|
||||
if (e instanceof ServerPlayerEntity)
|
||||
{
|
||||
// TODO next - figure out proper way of informting client about pos changes
|
||||
((ServerPlayerEntity)e).networkHandler.requestTeleport(e.getX(), e.getY(), e.getZ(), e.yaw, e.pitch);
|
||||
//((ServerPlayerEntity) e).networkHandler.requestTeleport(e.x, e.y, e.z, e.yaw, e.pitch);
|
||||
Set<PlayerPositionLookS2CPacket.Flag> set_1 = EnumSet.allOf(PlayerPositionLookS2CPacket.Flag.class);
|
||||
double prevX = e.getX();
|
||||
double prevY = e.getY();
|
||||
double prevZ = e.getZ();
|
||||
float prevYaw = e.yaw;
|
||||
float prevPitch = e.pitch;
|
||||
|
||||
e.setPositionAnglesAndUpdate(x, y, z, yaw, pitch);
|
||||
((ServerPlayerEntity) e).networkHandler.sendPacket(new PlayerPositionLookS2CPacket(
|
||||
x - prevX,
|
||||
y - prevY,
|
||||
z - prevZ,
|
||||
yaw - prevYaw,
|
||||
pitch - prevPitch,
|
||||
set_1, -1)
|
||||
);
|
||||
}
|
||||
else
|
||||
((ServerWorld)e.getEntityWorld()).method_14178().sendToNearbyPlayers(e,new EntityPositionS2CPacket(e));
|
||||
{
|
||||
e.setPositionAnglesAndUpdate(x, y, z, yaw, pitch);
|
||||
((ServerWorld) e.getEntityWorld()).method_14178().sendToNearbyPlayers(e, new EntityPositionS2CPacket(e));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void updateVelocity(Entity e)
|
||||
@@ -446,16 +479,13 @@ public class EntityValue extends Value
|
||||
throw new InternalExpressionException("Expected a list of 5 parameters as a second argument");
|
||||
}
|
||||
List<Value> coords = ((ListValue) v).getItems();
|
||||
e.pitch = (float) NumericValue.asNumber(coords.get(4)).getDouble();
|
||||
e.prevPitch = e.pitch;
|
||||
e.yaw = (float) NumericValue.asNumber(coords.get(3)).getDouble();
|
||||
e.prevYaw = e.yaw;
|
||||
e.setPosition(
|
||||
updatePosition(e,
|
||||
NumericValue.asNumber(coords.get(0)).getDouble(),
|
||||
NumericValue.asNumber(coords.get(1)).getDouble(),
|
||||
NumericValue.asNumber(coords.get(2)).getDouble())
|
||||
;
|
||||
updatePosition(e);
|
||||
NumericValue.asNumber(coords.get(2)).getDouble(),
|
||||
(float) NumericValue.asNumber(coords.get(3)).getDouble(),
|
||||
(float) NumericValue.asNumber(coords.get(4)).getDouble()
|
||||
);
|
||||
});
|
||||
put("pos", (e, v) ->
|
||||
{
|
||||
@@ -464,49 +494,35 @@ public class EntityValue extends Value
|
||||
throw new InternalExpressionException("Expected a list of 3 parameters as a second argument");
|
||||
}
|
||||
List<Value> coords = ((ListValue) v).getItems();
|
||||
e.setPosition(
|
||||
updatePosition(e,
|
||||
NumericValue.asNumber(coords.get(0)).getDouble(),
|
||||
NumericValue.asNumber(coords.get(1)).getDouble(),
|
||||
NumericValue.asNumber(coords.get(2)).getDouble()
|
||||
NumericValue.asNumber(coords.get(2)).getDouble(),
|
||||
e.yaw,
|
||||
e.pitch
|
||||
);
|
||||
updatePosition(e);
|
||||
});
|
||||
put("x", (e, v) ->
|
||||
{
|
||||
//e.x = NumericValue.asNumber(v).getDouble();
|
||||
e.setPosition(NumericValue.asNumber(v).getDouble(), e.getY(), e.getZ());
|
||||
updatePosition(e);
|
||||
updatePosition(e, NumericValue.asNumber(v).getDouble(), e.getY(), e.getZ(), e.yaw, e.pitch);
|
||||
});
|
||||
put("y", (e, v) ->
|
||||
{
|
||||
//e.y = NumericValue.asNumber(v).getDouble();
|
||||
e.setPosition(e.getX(), NumericValue.asNumber(v).getDouble(), e.getZ());
|
||||
updatePosition(e);
|
||||
updatePosition(e, e.getX(), NumericValue.asNumber(v).getDouble(), e.getZ(), e.yaw, e.pitch);
|
||||
});
|
||||
put("z", (e, v) ->
|
||||
{
|
||||
//e.z = NumericValue.asNumber(v).getDouble();
|
||||
e.setPosition(e.getX(), e.getY(), NumericValue.asNumber(v).getDouble());
|
||||
updatePosition(e);
|
||||
});
|
||||
put("pitch", (e, v) ->
|
||||
{
|
||||
float p = (float) NumericValue.asNumber(v).getDouble();
|
||||
if (Float.isNaN(p))
|
||||
return;
|
||||
e.pitch = MathHelper.clamp(p, -90, 90);
|
||||
e.prevPitch = e.pitch;
|
||||
updatePosition(e);
|
||||
updatePosition(e, e.getX(), e.getY(), NumericValue.asNumber(v).getDouble(), e.yaw, e.pitch);
|
||||
});
|
||||
put("yaw", (e, v) ->
|
||||
{
|
||||
float p = (float) NumericValue.asNumber(v).getDouble();
|
||||
if (Float.isNaN(p))
|
||||
return;
|
||||
e.yaw = p % 360;
|
||||
e.prevYaw = e.yaw;
|
||||
updatePosition(e);
|
||||
updatePosition(e, e.getX(), e.getY(), e.getZ(), ((float)NumericValue.asNumber(v).getDouble()) % 360, e.pitch);
|
||||
});
|
||||
put("pitch", (e, v) ->
|
||||
{
|
||||
updatePosition(e, e.getX(), e.getY(), e.getZ(), e.yaw, MathHelper.clamp((float)NumericValue.asNumber(v).getDouble(), -90, 90));
|
||||
});
|
||||
|
||||
//"look"
|
||||
//"turn"
|
||||
//"nod"
|
||||
@@ -518,8 +534,13 @@ public class EntityValue extends Value
|
||||
throw new InternalExpressionException("Expected a list of 3 parameters as a second argument");
|
||||
}
|
||||
List<Value> coords = ((ListValue) v).getItems();
|
||||
e.setPosition(NumericValue.asNumber(coords.get(0)).getDouble(),NumericValue.asNumber(coords.get(1)).getDouble(), NumericValue.asNumber(coords.get(2)).getDouble());
|
||||
updatePosition(e);
|
||||
updatePosition(e,
|
||||
e.getX() + NumericValue.asNumber(coords.get(0)).getDouble(),
|
||||
e.getY() + NumericValue.asNumber(coords.get(1)).getDouble(),
|
||||
e.getZ() + NumericValue.asNumber(coords.get(2)).getDouble(),
|
||||
e.yaw,
|
||||
e.pitch
|
||||
);
|
||||
});
|
||||
|
||||
put("motion", (e, v) ->
|
||||
|
||||
Reference in new issue
Block a user