Merge branch 'master' into 1.17

This commit is contained in:
gnembon committed 2020-12-06 20:36:40 -04:00
commit 89e61db56e
22 files changed
+657 -88

No files matched your search

+18 -34
View File
@@ -18,6 +18,7 @@ import carpet.script.argument.FunctionArgument;
import carpet.script.argument.Vector3Argument;
import carpet.script.exception.ExitStatement;
import carpet.script.exception.InternalExpressionException;
import carpet.script.utils.FixedCommandSource;
import carpet.script.utils.ShapeDispatcher;
import carpet.script.utils.WorldTools;
import carpet.script.value.EntityValue;
@@ -34,7 +35,6 @@ import carpet.script.value.ValueConversions;
import carpet.utils.Messenger;
import com.google.common.collect.ImmutableMap;
import net.minecraft.block.BlockState;
import net.minecraft.command.argument.EntityAnchorArgumentType;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.EquipmentSlot;
@@ -49,7 +49,6 @@ import net.minecraft.network.packet.s2c.play.TitleS2CPacket;
import net.minecraft.network.packet.s2c.play.TitleS2CPacket.Action;
import net.minecraft.particle.ParticleEffect;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.command.CommandOutput;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
@@ -63,7 +62,6 @@ import net.minecraft.util.InvalidIdentifierException;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.math.EulerAngle;
import net.minecraft.util.math.Vec2f;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.registry.DynamicRegistryManager;
import net.minecraft.util.registry.Registry;
@@ -331,7 +329,7 @@ public class Auxiliary {
{
Value nameValue = lv.get(0).evalValue(c);
name = nameValue instanceof NullValue ? "" : nameValue.getString();
pointLocator = Vector3Argument.findIn(cc, lv, 1, true);
pointLocator = Vector3Argument.findIn(cc, lv, 1, true, false);
if (lv.size()>pointLocator.offset)
{
BlockArgument blockLocator = BlockArgument.findIn(cc, lv, pointLocator.offset, true, true, false);
@@ -467,28 +465,29 @@ public class Auxiliary {
{
if (lv.size() == 0 || lv.size() > 2) throw new InternalExpressionException("'print' takes one or two arguments");
ServerCommandSource s = ((CarpetContext)c).s;
MinecraftServer server = s.getMinecraftServer();
Value res = lv.get(0).evalValue(c);
List<ServerPlayerEntity> targets = null;
if (lv.size() == 2)
{
ServerPlayerEntity player = EntityValue.getPlayerByValue(s.getMinecraftServer(), res);
if (player == null) return LazyValue.NULL;
s = player.getCommandSource();
List<Value> playerValues = (res instanceof ListValue)?((ListValue) res).getItems():Collections.singletonList(res);
List<ServerPlayerEntity> playerTargets = new ArrayList<>();
playerValues.forEach(pv -> {
ServerPlayerEntity player = EntityValue.getPlayerByValue(server, pv);
if (player == null) throw new InternalExpressionException("Cannot target player "+pv.getString()+" in print");
playerTargets.add(player);
});
targets = playerTargets;
res = lv.get(1).evalValue(c);
}
if (res instanceof FormattedTextValue)
Text message = (res instanceof FormattedTextValue)?((FormattedTextValue) res).getText():new LiteralText(res.getString());
if (targets == null)
{
s.sendFeedback(((FormattedTextValue) res).getText(), false);
s.sendFeedback(message, false);
}
else
{
if (s.getEntity() instanceof PlayerEntity)
{
Messenger.m((PlayerEntity) s.getEntity(), "w " + res.getString());
}
else
{
Messenger.m(s, "w " + res.getString());
}
targets.forEach(p -> p.getCommandSource().sendFeedback(message, false));
}
Value finalRes = res;
return (_c, _t) -> finalRes; // pass through for variables
@@ -565,29 +564,14 @@ public class Auxiliary {
expression.addLazyFunction("run", 1, (c, t, lv) -> {
BlockPos target = ((CarpetContext)c).origin;
Vec3d posf = new Vec3d((double)target.getX()+0.5D,(double)target.getY(),(double)target.getZ()+0.5D);
Vec3d posf = new Vec3d((double)target.getX()+0.5D, target.getY(),(double)target.getZ()+0.5D);
ServerCommandSource s = ((CarpetContext)c).s;
try
{
Value[] error = {Value.NULL};
List<Value> output = new ArrayList<>();
Value retval = new NumericValue(s.getMinecraftServer().getCommandManager().execute(
new ServerCommandSource(
CommandOutput.DUMMY, posf, Vec2f.ZERO, s.getWorld(), CarpetSettings.runPermissionLevel,
s.getName(), s.getDisplayName(), s.getMinecraftServer(), s.getEntity(), true,
(ctx, succ, res) -> { }, EntityAnchorArgumentType.EntityAnchor.FEET)
{
@Override
public void sendError(Text message)
{
error[0] = new FormattedTextValue(message);
}
@Override
public void sendFeedback(Text message, boolean broadcastToOps)
{
output.add(new FormattedTextValue(message));
}
},
new FixedCommandSource(s, posf, error, output),
lv.get(0).evalValue(c).getString())
);
Value ret = ListValue.of(retval, ListValue.wrap(output), error[0]);
+14 -4
View File
@@ -194,14 +194,24 @@ public class Entities {
if (lv.size()<3) throw new InternalExpressionException("'entity_area' requires entity type, center and range arguments");
String who = lv.get(0).evalValue(c).getString();
CarpetContext cc = (CarpetContext)c;
Vector3Argument centerLocator = Vector3Argument.findIn(cc, lv, 1);
Vec3d center = centerLocator.vec;
if (centerLocator.fromBlock) center.add(0.5, 0.5, 0.5);
Vector3Argument centerLocator = Vector3Argument.findIn(cc, lv, 1, false, true);
Box centerBox;
if (centerLocator.entity != null)
{
centerBox = centerLocator.entity.getBoundingBox();
}
else
{
Vec3d center = centerLocator.vec;
if (centerLocator.fromBlock) center.add(0.5, 0.5, 0.5);
centerBox = new Box(center, center);
}
Vector3Argument rangeLocator = Vector3Argument.findIn(cc, lv, centerLocator.offset);
if (rangeLocator.fromBlock)
throw new InternalExpressionException("Range of 'entity_area' cannot come from a block argument");
Vec3d range = rangeLocator.vec;
Box area = new Box(center, center).expand(range.x, range.y, range.z);
Box area = centerBox.expand(range.x, range.y, range.z);
EntityValue.EntityClassDescriptor eDesc = EntityValue.getEntityDescriptor(who);
List<? extends Entity> entityList = ((CarpetContext)c).s.getWorld().getEntitiesByType(eDesc.directType, area,eDesc.filteringPredicate);
Value retval = ListValue.wrap(entityList.stream().map(EntityValue::new).collect(Collectors.toList()));
@@ -6,6 +6,7 @@ import carpet.fakes.BiomeArrayInterface;
import carpet.fakes.ChunkGeneratorInterface;
import carpet.fakes.ChunkTicketManagerInterface;
import carpet.fakes.ServerChunkManagerInterface;
import carpet.fakes.ServerWorldInterface;
import carpet.fakes.SpawnHelperInnerInterface;
import carpet.fakes.ThreadedAnvilChunkStorageInterface;
import carpet.helpers.FeatureGenerator;
@@ -58,6 +59,7 @@ import net.minecraft.item.SwordItem;
import net.minecraft.item.TridentItem;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.Tag;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ChunkTicket;
import net.minecraft.server.world.ChunkTicketType;
@@ -89,6 +91,7 @@ import net.minecraft.world.gen.ChunkRandom;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.feature.ConfiguredStructureFeature;
import net.minecraft.world.gen.feature.StructureFeature;
import net.minecraft.world.level.ServerWorldProperties;
import net.minecraft.world.poi.PointOfInterest;
import net.minecraft.world.poi.PointOfInterestStorage;
import net.minecraft.world.poi.PointOfInterestType;
@@ -413,6 +416,67 @@ public class WorldAccess {
});
expression.addLazyFunction("weather",-1,(c, t, lv) -> {
ServerWorld world = ((CarpetContext) c).s.getWorld();
if(lv.size()==0)//cos it can thunder when raining or when clear.
{
Value ret = new StringValue(world.isThundering() ? "thunder" : (world.isRaining() ? "rain" : "clear"));
return (_c, _t) -> ret;
}
Value weather = lv.get(0).evalValue(c);
ServerWorldProperties worldProperties = ((ServerWorldInterface) world).getWorldPropertiesCM();
if(lv.size()==1)
{
int ticks;
switch (weather.getString().toLowerCase(Locale.ROOT)) {
case "clear":
ticks = worldProperties.getClearWeatherTime();
break;
case "rain":
ticks = world.isRaining()? worldProperties.getRainTime():0;//cos if not it gives 1 for some reason
break;
case "thunder":
ticks = world.isThundering()? worldProperties.getThunderTime():0;//same dealio here
break;
default:
throw new InternalExpressionException("Weather can only be 'clear', 'rain' or 'thunder'");
}
Value ret = new NumericValue(ticks);
return (_c,_t) -> ret;
}
if(lv.size()==2)
{
int ticks = NumericValue.asNumber(lv.get(1).evalValue(c), "tick_time in 'weather'").getInt();
switch (weather.getString().toLowerCase(Locale.ROOT))
{
case "clear":
world.setWeather(ticks,0,false,false);
break;
case "rain":
world.setWeather(0,ticks,true,false);
break;
case "thunder":
world.setWeather(
0,
ticks,//this is used to set thunder time, idk why...
true,
true
);
break;
default:
throw new InternalExpressionException("Weather can only be 'clear', 'rain' or 'thunder'");
}
Value ret = NumericValue.of(ticks);
return (_c, _t) -> ret;
}
throw new InternalExpressionException("'weather' requires 0, 1 or 2 arguments");
});
expression.addLazyFunction("pos", 1, (c, t, lv) ->
{
Value arg = lv.get(0).evalValue(c);