Merge branch 'master' into 1.15
This commit is contained in:
commit
bf22134640
19 files changed
+141
-60
No files matched your search
@@ -302,7 +302,7 @@ public class CarpetEventServer
|
||||
{
|
||||
eventHandlers.get("player_clicks_block").call( () -> Arrays.asList(
|
||||
((c, t) -> new EntityValue(player)),
|
||||
((c, t) -> new BlockValue(null, player.world, blockpos)),
|
||||
((c, t) -> new BlockValue(null, player.getServerWorld(), blockpos)),
|
||||
((c, t) -> new StringValue(facing.getName()))
|
||||
), player::getCommandSource);
|
||||
}
|
||||
@@ -319,7 +319,7 @@ public class CarpetEventServer
|
||||
((c, t) -> new EntityValue(player)),
|
||||
((c, t) -> ListValue.fromItemStack(itemstack)),
|
||||
((c, t) -> new StringValue(enumhand == Hand.MAIN_HAND ? "mainhand" : "offhand")),
|
||||
((c, t) -> new BlockValue(null, player.world, blockpos)),
|
||||
((c, t) -> new BlockValue(null, player.getServerWorld(), blockpos)),
|
||||
((c, t) -> new StringValue(enumfacing.getName())),
|
||||
((c, t) -> ListValue.of(
|
||||
new NumericValue(vec3d.x),
|
||||
@@ -330,11 +330,11 @@ public class CarpetEventServer
|
||||
}, player::getCommandSource);
|
||||
}
|
||||
|
||||
public void onBlockBroken(PlayerEntity player, BlockPos pos, BlockState previousBS)
|
||||
public void onBlockBroken(ServerPlayerEntity player, BlockPos pos, BlockState previousBS)
|
||||
{
|
||||
eventHandlers.get("player_breaks_block").call( () -> Arrays.asList(
|
||||
((c, t) -> new EntityValue(player)),
|
||||
((c, t) -> new BlockValue(previousBS, player.getEntityWorld(), pos))
|
||||
((c, t) -> new BlockValue(previousBS, player.getServerWorld(), pos))
|
||||
), player::getCommandSource);
|
||||
}
|
||||
|
||||
@@ -355,22 +355,22 @@ public class CarpetEventServer
|
||||
), player::getCommandSource);
|
||||
}
|
||||
|
||||
public void onStartSneaking(PlayerEntity player)
|
||||
public void onStartSneaking(ServerPlayerEntity player)
|
||||
{
|
||||
eventHandlers.get("player_starts_sneaking").call( () -> Arrays.asList(((c, t) -> new EntityValue(player))), player::getCommandSource);
|
||||
}
|
||||
|
||||
public void onStopSneaking(PlayerEntity player)
|
||||
public void onStopSneaking(ServerPlayerEntity player)
|
||||
{
|
||||
eventHandlers.get("player_stops_sneaking").call( () -> Arrays.asList(((c, t) -> new EntityValue(player))), player::getCommandSource);
|
||||
}
|
||||
|
||||
public void onStartSprinting(PlayerEntity player)
|
||||
public void onStartSprinting(ServerPlayerEntity player)
|
||||
{
|
||||
eventHandlers.get("player_starts_sprinting").call( () -> Arrays.asList(((c, t) -> new EntityValue(player))), player::getCommandSource);
|
||||
}
|
||||
|
||||
public void onStopSprinting(PlayerEntity player)
|
||||
public void onStopSprinting(ServerPlayerEntity player)
|
||||
{
|
||||
eventHandlers.get("player_stops_sprinting").call( () -> Arrays.asList(((c, t) -> new EntityValue(player))), player::getCommandSource);
|
||||
}
|
||||
|
||||
@@ -61,7 +61,6 @@ import net.minecraft.sound.SoundCategory;
|
||||
import net.minecraft.state.StateFactory;
|
||||
import net.minecraft.state.property.Property;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
import net.minecraft.util.Clearable;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
@@ -75,6 +74,7 @@ import net.minecraft.world.LightType;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
import net.minecraft.world.loot.context.LootContext;
|
||||
import net.minecraft.world.loot.context.LootContextParameters;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
@@ -798,7 +798,7 @@ public class CarpetExpression
|
||||
this.expr.addLazyFunction("set", -1, (c, t, lv) ->
|
||||
{
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
World world = cc.s.getWorld();
|
||||
ServerWorld world = cc.s.getWorld();
|
||||
if (lv.size() < 2 || lv.size() % 2 == 1)
|
||||
throw new InternalExpressionException("set block should have at least 2 params and odd attributes");
|
||||
BlockValue.LocatorResult targetLocator = BlockValue.fromParams(cc, lv, 0);
|
||||
@@ -1983,7 +1983,7 @@ public class CarpetExpression
|
||||
{
|
||||
|
||||
BlockPos center = BlockValue.fromParams((CarpetContext) c, lv,0).block.getPos();
|
||||
World world = ((CarpetContext) c).s.getWorld();
|
||||
ServerWorld world = ((CarpetContext) c).s.getWorld();
|
||||
|
||||
List<Value> neighbours = new ArrayList<>();
|
||||
neighbours.add(new BlockValue(null, world, center.up()));
|
||||
@@ -2308,6 +2308,10 @@ public class CarpetExpression
|
||||
* </pre>
|
||||
* <h3><code>current_dimension()</code></h3>
|
||||
* <p>Returns current dimension that scripts run in.</p>
|
||||
* <h3><code>in_dimension(smth, expr)</code></h3>
|
||||
* <p>Evaluates the expression <code>expr</code> with different dimension execution context. <code>smth</code> can
|
||||
* be an entity, world-localized block, so not <code>block('stone')</code>, or a string representing a dimension like:
|
||||
* <code>'nether'</code>, <code>'end'</code> or <code>'overworld'</code>.</p>
|
||||
* <h3><code>schedule(delay, function, args...)</code></h3>
|
||||
* <p>Schedules a user defined function to run with a specified <code>delay</code> ticks of delay.
|
||||
* Scheduled functions run at the end of the tick, and they will run in order they were scheduled.</p>
|
||||
@@ -2681,6 +2685,53 @@ public class CarpetExpression
|
||||
return (cc, tt) -> retval;
|
||||
});
|
||||
|
||||
this.expr.addLazyFunction("in_dimension", 2, (c, t, lv) -> {
|
||||
ServerCommandSource outerSource = ((CarpetContext)c).s;
|
||||
Value dimensionValue = lv.get(0).evalValue(c);
|
||||
ServerCommandSource innerSource = outerSource;
|
||||
if (dimensionValue instanceof EntityValue)
|
||||
{
|
||||
innerSource = outerSource.withWorld((ServerWorld) ((EntityValue)dimensionValue).getEntity().getEntityWorld());
|
||||
}
|
||||
else if (dimensionValue instanceof BlockValue)
|
||||
{
|
||||
BlockValue bv = (BlockValue)dimensionValue;
|
||||
if (bv.getWorld() != null)
|
||||
{
|
||||
innerSource = outerSource.withWorld(bv.getWorld());
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InternalExpressionException("in_dimension accepts only world-localized block arguments");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
String dimString = dimensionValue.getString().toLowerCase(Locale.ROOT);
|
||||
switch (dimString)
|
||||
{
|
||||
case "nether":
|
||||
case "the_nether":
|
||||
innerSource = outerSource.withWorld(outerSource.getMinecraftServer().getWorld(DimensionType.THE_NETHER));
|
||||
break;
|
||||
case "end":
|
||||
case "the_end":
|
||||
innerSource = outerSource.withWorld(outerSource.getMinecraftServer().getWorld(DimensionType.THE_END));
|
||||
break;
|
||||
case "overworld":
|
||||
case "over_world":
|
||||
innerSource = outerSource.withWorld(outerSource.getMinecraftServer().getWorld(DimensionType.OVERWORLD));
|
||||
break;
|
||||
default:
|
||||
throw new InternalExpressionException("Incorrect dimension string: "+dimString);
|
||||
}
|
||||
}
|
||||
((CarpetContext) c).s = innerSource;
|
||||
Value retval = lv.get(1).evalValue(c);
|
||||
((CarpetContext) c).s = outerSource;
|
||||
return (cc, tt) -> retval;
|
||||
});
|
||||
|
||||
this.expr.addLazyFunction("plop", 4, (c, t, lv) ->{
|
||||
BlockValue.LocatorResult locator = BlockValue.fromParams((CarpetContext)c, lv, 0);
|
||||
if (lv.size() <= locator.offset)
|
||||
|
||||
@@ -12,6 +12,7 @@ import net.minecraft.block.Blocks;
|
||||
import net.minecraft.item.ItemPlacementContext;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
@@ -32,7 +33,7 @@ public class BlockValue extends Value
|
||||
public static final BlockValue NULL = new BlockValue(null, null, null);
|
||||
private BlockState blockState;
|
||||
private BlockPos pos;
|
||||
private World world;
|
||||
private ServerWorld world;
|
||||
private CompoundTag data;
|
||||
|
||||
public static BlockValue fromCoords(CarpetContext c, int x, int y, int z)
|
||||
@@ -212,7 +213,7 @@ public class BlockValue extends Value
|
||||
}
|
||||
|
||||
|
||||
public BlockValue(BlockState state, World world, BlockPos position)
|
||||
public BlockValue(BlockState state, ServerWorld world, BlockPos position)
|
||||
{
|
||||
this.world = world;
|
||||
blockState = state;
|
||||
@@ -220,7 +221,7 @@ public class BlockValue extends Value
|
||||
data = null;
|
||||
}
|
||||
|
||||
public BlockValue(BlockState state, World world, BlockPos position, CompoundTag nbt)
|
||||
public BlockValue(BlockState state, ServerWorld world, BlockPos position, CompoundTag nbt)
|
||||
{
|
||||
this.world = world;
|
||||
blockState = state;
|
||||
@@ -258,6 +259,8 @@ public class BlockValue extends Value
|
||||
return pos;
|
||||
}
|
||||
|
||||
public ServerWorld getWorld() { return world;}
|
||||
|
||||
|
||||
public static class LocatorResult
|
||||
{
|
||||
|
||||
@@ -7,12 +7,10 @@ import carpet.helpers.Tracer;
|
||||
import carpet.script.CarpetContext;
|
||||
import carpet.script.Fluff;
|
||||
import carpet.script.exception.InternalExpressionException;
|
||||
import carpet.settings.CarpetSettings;
|
||||
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.EntityVelocityUpdateS2CPacket;
|
||||
import net.minecraft.command.EntitySelector;
|
||||
import net.minecraft.command.EntitySelectorReader;
|
||||
import net.minecraft.command.arguments.NbtPathArgumentType;
|
||||
@@ -234,7 +232,7 @@ public class EntityValue extends Value
|
||||
put("home", (e, a) -> {
|
||||
if (e instanceof MobEntity)
|
||||
{
|
||||
return (((MobEntity) e).getWalkTargetRange () > 0)?new BlockValue(null, e.getEntityWorld(), ((MobEntityWithAi) e).getWalkTarget()):Value.FALSE;
|
||||
return (((MobEntity) e).getWalkTargetRange () > 0)?new BlockValue(null, (ServerWorld) e.getEntityWorld(), ((MobEntityWithAi) e).getWalkTarget()):Value.FALSE;
|
||||
}
|
||||
return Value.NULL;
|
||||
});
|
||||
@@ -379,7 +377,7 @@ public class EntityValue extends Value
|
||||
switch (hitres.getType())
|
||||
{
|
||||
case MISS: return Value.NULL;
|
||||
case BLOCK: return new BlockValue(null, e.getEntityWorld(), ((BlockHitResult)hitres).getBlockPos() );
|
||||
case BLOCK: return new BlockValue(null, (ServerWorld) e.getEntityWorld(), ((BlockHitResult)hitres).getBlockPos() );
|
||||
case ENTITY: return new EntityValue(((EntityHitResult)hitres).getEntity());
|
||||
}
|
||||
return Value.NULL;
|
||||
|
||||
Reference in new issue
Block a user