This commit is contained in:
gnembon committed 2022-10-20 14:33:36 +02:00
1 parent ffa4fcf2a6
commit 9f776167e3
23 files changed
+179 -136

No files matched your search

+1
View File
@@ -48,6 +48,7 @@ import static carpet.api.settings.RuleCategory.CLIENT;
public class CarpetSettings
{
public static final String carpetVersion = "1.4.84+v221018";
public static final String releaseTarget = "1.19.3";
public static final Logger LOG = LoggerFactory.getLogger("carpet");
public static final ThreadLocal<Boolean> skipGenerationChecks = ThreadLocal.withInitial(() -> false);
public static final ThreadLocal<Boolean> impendingFillSkipUpdates = ThreadLocal.withInitial(() -> false);
@@ -8,12 +8,13 @@ import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import net.minecraft.commands.CommandBuildContext;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.arguments.EntitySummonArgument;
import net.minecraft.core.Registry;
import static net.minecraft.commands.Commands.argument;
import static net.minecraft.commands.Commands.literal;
import static net.minecraft.commands.SharedSuggestionProvider.suggest;
import static net.minecraft.commands.arguments.ResourceArgument.getSummonableEntityType;
import static net.minecraft.commands.arguments.ResourceArgument.resource;
public class MobAICommand
{
@@ -21,20 +22,20 @@ public class MobAICommand
{
LiteralArgumentBuilder<CommandSourceStack> command = literal("track").
requires((player) -> CommandHelper.canUseCommand(player, CarpetSettings.commandTrackAI)).
then(argument("entity type", EntitySummonArgument.id()).
then(argument("entity type", resource(commandBuildContext, Registry.ENTITY_TYPE_REGISTRY)).
suggests( (c, b) -> suggest(MobAI.availbleTypes(), b)).
then(literal("clear").executes( (c) ->
{
MobAI.clearTracking(Registry.ENTITY_TYPE.get(EntitySummonArgument.getSummonableEntity(c, "entity type")));
MobAI.clearTracking(getSummonableEntityType(c, "entity type").value());
return 1;
}
)).
then(argument("aspect", StringArgumentType.word()).
suggests( (c, b) -> suggest(MobAI.availableFor(Registry.ENTITY_TYPE.get(EntitySummonArgument.getSummonableEntity(c, "entity type"))),b)).
suggests( (c, b) -> suggest(MobAI.availableFor(getSummonableEntityType(c, "entity type").value()),b)).
executes( (c) -> {
MobAI.startTracking(
Registry.ENTITY_TYPE.get(EntitySummonArgument.getSummonableEntity(c, "entity type")),
getSummonableEntityType(c, "entity type").value(),
MobAI.TrackingType.valueOf(StringArgumentType.getString(c, "aspect").toUpperCase())
);
return 1;
@@ -8,10 +8,10 @@ import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import net.minecraft.commands.CommandBuildContext;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.arguments.EntitySummonArgument;
import net.minecraft.commands.arguments.coordinates.BlockPosArgument;
import net.minecraft.commands.synchronization.SuggestionProviders;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Registry;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
@@ -19,6 +19,8 @@ import net.minecraft.world.entity.Mob;
import static net.minecraft.commands.Commands.argument;
import static net.minecraft.commands.Commands.literal;
import static net.minecraft.commands.arguments.ResourceArgument.getSummonableEntityType;
import static net.minecraft.commands.arguments.ResourceArgument.resource;
public class PerimeterInfoCommand
{
@@ -35,12 +37,12 @@ public class PerimeterInfoCommand
c.getSource(),
BlockPosArgument.getSpawnablePos(c, "center position"),
null)).
then(argument("mob",EntitySummonArgument.id()).
then(argument("mob", resource(commandBuildContext, Registry.ENTITY_TYPE_REGISTRY)).
suggests(SuggestionProviders.SUMMONABLE_ENTITIES).
executes( (c) -> perimeterDiagnose(
c.getSource(),
BlockPosArgument.getSpawnablePos(c, "center position"),
EntitySummonArgument.getSummonableEntity(c, "mob").toString()
getSummonableEntityType(c, "mob").key().location().toString()
))));
dispatcher.register(command);
}
@@ -58,7 +60,7 @@ public class PerimeterInfoCommand
});
if (!(baseEntity instanceof Mob))
{
Messenger.m(source, "r /perimeterinfo requires a mob entity to test agains.");
Messenger.m(source, "r /perimeterinfo requires a mob entity to test against.");
if (baseEntity != null) baseEntity.discard();
return 0;
}
@@ -5,6 +5,8 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
import java.util.HashMap;
import java.util.Map;
import net.minecraft.commands.arguments.ParticleArgument;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.Registry;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
@@ -18,7 +20,7 @@ public class ParticleDisplay
{
try
{
return ParticleArgument.readParticle(new StringReader(name));
return ParticleArgument.readParticle(new StringReader(name), HolderLookup.forRegistry(Registry.PARTICLE_TYPE));
}
catch (CommandSyntaxException e)
{
@@ -3,27 +3,32 @@ package carpet.mixins;
import carpet.CarpetServer;
import carpet.network.CarpetClient;
import carpet.api.settings.SettingsManager;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientPacketListener;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.network.chat.Component;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(LocalPlayer.class)
public class LocalPlayer_clientCommandMixin
@Mixin(ClientPacketListener.class)
public class ClientPacketListener_clientCommandMixin
{
@Inject(method = "commandSigned", at = @At("HEAD"))
private void inspectMessage(String string, Component component, CallbackInfo ci)
@Shadow @Final private Minecraft minecraft;
@Inject(method = "sendCommand", at = @At("HEAD"))
private void inspectMessage(String string, CallbackInfo ci)
{
if (string.startsWith("call "))
{
String command = string.substring(5);
CarpetClient.sendClientCommand(command);
}
if (CarpetServer.minecraft_server == null && !CarpetClient.isCarpet())
if (CarpetServer.minecraft_server == null && !CarpetClient.isCarpet() && minecraft.player != null)
{
LocalPlayer playerSource = (LocalPlayer)(Object) this;
LocalPlayer playerSource = minecraft.player;
CarpetServer.settingsManager.inspectClientsideCommand(playerSource.createCommandSourceStack(), "/"+string);
CarpetServer.extensions.forEach(e -> {
SettingsManager sm = e.extensionSettingsManager();
@@ -3,10 +3,10 @@ package carpet.mixins;
import carpet.fakes.ServerPlayerEntityInterface;
import carpet.helpers.EntityPlayerActionPack;
import com.mojang.authlib.GameProfile;
import net.minecraft.network.chat.RemoteChatSession;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.player.ProfilePublicKey;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
@@ -25,7 +25,7 @@ public abstract class ServerPlayer_actionPackMixin implements ServerPlayerEntity
}
@Inject(method = "<init>", at = @At(value = "RETURN"))
private void onServerPlayerEntityContructor(MinecraftServer foo, ServerLevel bar, GameProfile baz, ProfilePublicKey qux, CallbackInfo ci)
private void onServerPlayerEntityContructor(MinecraftServer minecraftServer, ServerLevel serverLevel, GameProfile gameProfile, RemoteChatSession remoteChatSession, CallbackInfo ci)
{
this.actionPack = new EntityPlayerActionPack((ServerPlayer) (Object) this);
}
@@ -14,7 +14,6 @@ import net.minecraft.world.InteractionHand;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.player.ProfilePublicKey;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
import org.spongepowered.asm.mixin.Mixin;
@@ -39,8 +38,8 @@ public abstract class ServerPlayer_scarpetEventMixin extends Player implements S
@Unique
private boolean isInvalidReference = false;
public ServerPlayer_scarpetEventMixin(Level level, BlockPos blockPos, float f, GameProfile gameProfile, ProfilePublicKey profilePublicKey) {
super(level, blockPos, f, gameProfile, profilePublicKey);
public ServerPlayer_scarpetEventMixin(Level level, BlockPos blockPos, float f, GameProfile gameProfile) {
super(level, blockPos, f, gameProfile);
}
@Shadow protected abstract void completeUsingItem();
@@ -4,8 +4,9 @@ import carpet.CarpetSettings;
import com.mojang.authlib.GameProfile;
import net.minecraft.core.UUIDUtil;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.RemoteChatSession;
import net.minecraft.network.protocol.PacketFlow;
import net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket;
import net.minecraft.network.protocol.game.ClientboundPlayerInfoUpdatePacket;
import net.minecraft.network.protocol.game.ClientboundRotateHeadPacket;
import net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket;
import net.minecraft.resources.ResourceKey;
@@ -18,7 +19,6 @@ import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.player.ProfilePublicKey;
import net.minecraft.world.food.FoodData;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.GameType;
@@ -62,7 +62,7 @@ public class EntityPlayerMPFake extends ServerPlayer
SkullBlockEntity.updateGameprofile(gameprofile, result::set);
gameprofile = result.get();
}
EntityPlayerMPFake instance = new EntityPlayerMPFake(server, worldIn, gameprofile, false, null);
EntityPlayerMPFake instance = new EntityPlayerMPFake(server, worldIn, gameprofile, false, RemoteChatSession.UNVERIFIED);
instance.fixStartingPosition = () -> instance.moveTo(d0, d1, d2, (float) yaw, (float) pitch);
server.getPlayerList().placeNewPlayer(new FakeClientConnection(PacketFlow.SERVERBOUND), instance);
instance.teleportTo(worldIn, d0, d1, d2, (float)yaw, (float)pitch);
@@ -84,7 +84,7 @@ public class EntityPlayerMPFake extends ServerPlayer
player.connection.disconnect(Component.translatable("multiplayer.disconnect.duplicate_login"));
ServerLevel worldIn = player.getLevel();//.getWorld(player.dimension);
GameProfile gameprofile = player.getGameProfile();
EntityPlayerMPFake playerShadow = new EntityPlayerMPFake(server, worldIn, gameprofile, true, player.getProfilePublicKey());
EntityPlayerMPFake playerShadow = new EntityPlayerMPFake(server, worldIn, gameprofile, true, player.getChatSession());
server.getPlayerList().placeNewPlayer(new FakeClientConnection(PacketFlow.SERVERBOUND), playerShadow);
playerShadow.setHealth(player.getHealth());
@@ -96,15 +96,15 @@ public class EntityPlayerMPFake extends ServerPlayer
server.getPlayerList().broadcastAll(new ClientboundRotateHeadPacket(playerShadow, (byte) (player.yHeadRot * 256 / 360)), playerShadow.level.dimension());
server.getPlayerList().broadcastAll(new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.ADD_PLAYER, playerShadow));
server.getPlayerList().broadcastAll(new ClientboundPlayerInfoUpdatePacket(ClientboundPlayerInfoUpdatePacket.Action.ADD_PLAYER, playerShadow));
//player.world.getChunkManager().updatePosition(playerShadow);
playerShadow.getAbilities().flying = player.getAbilities().flying;
return playerShadow;
}
private EntityPlayerMPFake(MinecraftServer server, ServerLevel worldIn, GameProfile profile, boolean shadow, ProfilePublicKey profilePublicKey)
private EntityPlayerMPFake(MinecraftServer server, ServerLevel worldIn, GameProfile profile, boolean shadow, RemoteChatSession chatSession)
{
super(server, worldIn, profile, profilePublicKey);
super(server, worldIn, profile, chatSession);
isAShadow = shadow;
}
@@ -38,6 +38,7 @@ import carpet.script.value.Value;
import carpet.script.value.ValueConversions;
import carpet.utils.Messenger;
import com.google.common.collect.Lists;
import com.mojang.bridge.game.PackType;
import net.minecraft.SharedConstants;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.core.BlockPos;
@@ -1050,7 +1051,7 @@ public class Auxiliary {
Path zipRoot = zipfs.getPath("/");
zipValueToJson(zipRoot.resolve("pack.mcmeta"), MapValue.wrap(
Map.of(StringValue.of("pack"), MapValue.wrap(Map.of(
StringValue.of("pack_format"), new NumericValue(SharedConstants.getCurrentVersion().getPackVersion()),
StringValue.of("pack_format"), new NumericValue(SharedConstants.getCurrentVersion().getPackVersion(PackType.DATA)),
StringValue.of("description"), StringValue.of(name),
StringValue.of("source"), StringValue.of("scarpet")
)))
@@ -59,11 +59,10 @@ public class Inventories {
expression.addUnaryFunction("stack_limit", v ->
new NumericValue(NBTSerializableValue.parseItem(v.getString()).getItem().getMaxStackSize()));
expression.addUnaryFunction("item_category", v ->
{
ItemInput item = NBTSerializableValue.parseItem(v.getString());
CreativeModeTab ig = item.getItem().getItemCategory();
return (ig==null)?Value.NULL:new StringValue(ig.getRecipeFolderName());
expression.addContextFunction("item_category", -1, (c, t, lv) -> {
CarpetContext cc = (CarpetContext)c;
cc.host.issueDeprecation("item_category in 1.19.3+");
return Value.NULL;
});
expression.addContextFunction("item_list", -1, (c, t, lv) ->
@@ -50,6 +50,7 @@ import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import net.minecraft.ChatFormatting;
@@ -63,20 +64,17 @@ import net.minecraft.commands.arguments.ColorArgument;
import net.minecraft.commands.arguments.CompoundTagArgument;
import net.minecraft.commands.arguments.DimensionArgument;
import net.minecraft.commands.arguments.EntityAnchorArgument;
import net.minecraft.commands.arguments.EntitySummonArgument;
import net.minecraft.commands.arguments.GameProfileArgument;
import net.minecraft.commands.arguments.ItemEnchantmentArgument;
import net.minecraft.commands.arguments.MessageArgument;
import net.minecraft.commands.arguments.MobEffectArgument;
import net.minecraft.commands.arguments.NbtPathArgument;
import net.minecraft.commands.arguments.NbtTagArgument;
import net.minecraft.commands.arguments.ObjectiveArgument;
import net.minecraft.commands.arguments.ObjectiveCriteriaArgument;
import net.minecraft.commands.arguments.ParticleArgument;
import net.minecraft.commands.arguments.RangeArgument;
import net.minecraft.commands.arguments.ResourceKeyArgument;
import net.minecraft.commands.arguments.ResourceArgument;
import net.minecraft.commands.arguments.ResourceLocationArgument;
import net.minecraft.commands.arguments.ResourceOrTagLocationArgument;
import net.minecraft.commands.arguments.ResourceOrTagArgument;
import net.minecraft.commands.arguments.ScoreHolderArgument;
import net.minecraft.commands.arguments.ScoreboardSlotArgument;
import net.minecraft.commands.arguments.TeamArgument;
@@ -94,13 +92,14 @@ import net.minecraft.commands.arguments.item.ItemArgument;
import net.minecraft.commands.synchronization.SuggestionProviders;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Holder;
import net.minecraft.core.HolderSet;
import net.minecraft.core.Registry;
import net.minecraft.core.RegistryAccess;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.commands.BossBarCommands;
import net.minecraft.tags.TagKey;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.phys.Vec2;
@@ -137,10 +136,11 @@ public abstract class CommandArgument
BlockInput result = BlockStateArgument.getBlock(c, p);
return new BlockValue(result.getState(), null, null, ((BlockStateArgumentInterface)result).getCMTag() );
},
false
param -> (ctx, builder) -> ctx.getArgument(param, BlockStateArgument.class).listSuggestions(ctx, builder)
),
new VanillaUnconfigurableArgument( "blockpredicate", BlockPredicateArgument::blockPredicate,
(c, p) -> ValueConversions.ofBlockPredicate(c.getSource().getServer().registryAccess(), BlockPredicateArgument.getBlockPredicate(c, p)), false
(c, p) -> ValueConversions.ofBlockPredicate(c.getSource().getServer().registryAccess(), BlockPredicateArgument.getBlockPredicate(c, p)),
param -> (ctx, builder) -> ctx.getArgument(param, BlockPredicateArgument.class).listSuggestions(ctx, builder)
),
new VanillaUnconfigurableArgument("teamcolor", ColorArgument::color,
(c, p) -> {
@@ -160,8 +160,8 @@ public abstract class CommandArgument
new VanillaUnconfigurableArgument("anchor", EntityAnchorArgument::anchor,
(c, p) -> StringValue.of(EntityAnchorArgument.getAnchor(c, p).name()), false
),
new VanillaUnconfigurableArgument("entitytype", EntitySummonArgument::id,
(c, p) -> ValueConversions.of(EntitySummonArgument.getSummonableEntity(c, p)), SuggestionProviders.SUMMONABLE_ENTITIES
new VanillaUnconfigurableArgument("entitytype", c -> ResourceArgument.resource(c, Registry.ENTITY_TYPE_REGISTRY),
(c, p) -> ValueConversions.of(ResourceArgument.getSummonableEntityType(c, p).key()), SuggestionProviders.SUMMONABLE_ENTITIES
),
new VanillaUnconfigurableArgument("floatrange", RangeArgument::floatRange,
(c, p) -> ValueConversions.of(c.getArgument(p, MinMaxBounds.Doubles.class)), true
@@ -172,20 +172,19 @@ public abstract class CommandArgument
new VanillaUnconfigurableArgument("intrange", RangeArgument::intRange,
(c, p) -> ValueConversions.of(RangeArgument.Ints.getRange(c, p)), true
),
new VanillaUnconfigurableArgument("enchantment", ItemEnchantmentArgument::enchantment,
(c, p) -> ValueConversions.of(Registry.ENCHANTMENT.getKey(ItemEnchantmentArgument.getEnchantment(c, p))), false
),
new VanillaUnconfigurableArgument("enchantment", Registry.ENCHANTMENT_REGISTRY),
// item_predicate ?? //same as item but accepts tags, not sure right now
new SlotArgument(),
new VanillaUnconfigurableArgument("item", ItemArgument::item,
(c, p) -> ValueConversions.of(ItemArgument.getItem(c, p).createItemStack(1, false)), false
(c, p) -> ValueConversions.of(ItemArgument.getItem(c, p).createItemStack(1, false)),
param -> (ctx, builder) -> ctx.getArgument(param, ItemArgument.class).listSuggestions(ctx, builder)
),
new VanillaUnconfigurableArgument("message", MessageArgument::message,
(c, p) -> new FormattedTextValue(MessageArgument.getMessage(c, p)), true
),
new VanillaUnconfigurableArgument("effect", MobEffectArgument::effect,
(c, p) -> ValueConversions.of(Registry.MOB_EFFECT.getKey(MobEffectArgument.getEffect(c, p))),false
),
new VanillaUnconfigurableArgument("effect", Registry.MOB_EFFECT_REGISTRY),
new TagArgument(), // for nbt_compound_tag and nbt_tag
new VanillaUnconfigurableArgument("path", NbtPathArgument::nbtPath,
(c, p) -> StringValue.of(NbtPathArgument.getPath(c, p).toString()), true
@@ -198,7 +197,7 @@ public abstract class CommandArgument
),
// operation // not sure if we need it, you have scarpet for that
new VanillaUnconfigurableArgument("particle", ParticleArgument::particle,
(c, p) -> ValueConversions.of(ParticleArgument.getParticle(c, p)), false
(c, p) -> ValueConversions.of(ParticleArgument.getParticle(c, p)), (c, b) -> SharedSuggestionProvider.suggestResource(c.getSource().getServer().registryAccess().registryOrThrow(Registry.PARTICLE_TYPE_REGISTRY).keySet(), b)
),
// resource / identifier section
@@ -215,23 +214,23 @@ public abstract class CommandArgument
new VanillaUnconfigurableArgument("loottable", ResourceLocationArgument::id,
(c, p) -> ValueConversions.of( ResourceLocationArgument.getId(c, p)), (ctx, builder) -> SharedSuggestionProvider.suggestResource(ctx.getSource().getServer().getLootTables().getIds(), builder)
),
new VanillaUnconfigurableArgument("attribute", ResourceLocationArgument::id,
(c, p) -> ValueConversions.of( Registry.ATTRIBUTE.getKey(ResourceKeyArgument.getAttribute(c, p))), (ctx, builder) -> SharedSuggestionProvider.suggestResource(Registry.ATTRIBUTE.keySet(), builder)
),
new VanillaUnconfigurableArgument("attribute", Registry.ATTRIBUTE_REGISTRY),
new VanillaUnconfigurableArgument("boss", ResourceLocationArgument::id,
(c, p) -> ValueConversions.of( ResourceLocationArgument.getId(c, p)), BossBarCommands.SUGGEST_BOSS_BAR
),
new VanillaUnconfigurableArgument("biome", () -> ResourceOrTagLocationArgument.resourceOrTag(Registry.BIOME_REGISTRY),
new VanillaUnconfigurableArgument("biome", (c) -> ResourceOrTagArgument.resourceOrTag(c, Registry.BIOME_REGISTRY),
(c, p) -> {
ResourceOrTagLocationArgument.Result<Biome> result = ResourceOrTagLocationArgument.getRegistryType(c, "biome", Registry.BIOME_REGISTRY, ERROR_BIOME_INVALID);
Either<ResourceKey<Biome>, TagKey<Biome>> res = result.unwrap();
ResourceOrTagArgument.Result<Biome> result = ResourceOrTagArgument.getResourceOrTag(c, "biome", Registry.BIOME_REGISTRY);
Either<Holder.Reference<Biome>, HolderSet.Named<Biome>> res = result.unwrap();
if (res.left().isPresent())
{
return ValueConversions.of(res.left().get());
return ValueConversions.of(res.left().get().key());
}
if (res.right().isPresent())
{
return ValueConversions.of(res.right().get());
return ValueConversions.of(res.right().get().key());
}
return Value.NULL;
}, (ctx, builder) -> SharedSuggestionProvider.suggestResource(ctx.getSource().getServer().registryAccess().registryOrThrow(Registry.BIOME_REGISTRY).keySet(), builder)
@@ -304,7 +303,7 @@ public abstract class CommandArgument
public static RequiredArgumentBuilder<CommandSourceStack, ?> argumentNode(String param, CarpetScriptHost host) throws CommandSyntaxException
{
CommandArgument arg = getTypeForArgument(param, host);
if (arg.suggestionProvider != null) return argument(param, arg.getArgumentType(host)).suggests(arg.suggestionProvider);
if (arg.suggestionProvider != null) return argument(param, arg.getArgumentType(host)).suggests(arg.suggestionProvider.apply(param));
if (!arg.needsMatching) return argument(param, arg.getArgumentType(host));
String hostName = host.getName();
return argument(param, arg.getArgumentType(host)).suggests((ctx, b) -> {
@@ -317,7 +316,7 @@ public abstract class CommandArgument
protected Collection<String> examples;
protected boolean needsMatching;
protected boolean caseSensitive = true;
protected SuggestionProvider<CommandSourceStack> suggestionProvider;
protected Function<String, SuggestionProvider<CommandSourceStack>> suggestionProvider;
protected FunctionArgument customSuggester;
@@ -353,7 +352,7 @@ public abstract class CommandArgument
String baseType = config.get("type").getString();
if (!builtIns.containsKey(baseType))
throw CommandArgument.error("Unknown base type "+baseType+" for custom type "+suffix);
CommandArgument variant = builtIns.get(baseType).factory().get();
CommandArgument variant = builtIns.get(baseType).factory(host.scriptServer().server).get();
variant.suffix = suffix;
variant.configure(config, host);
return variant;
@@ -440,7 +439,7 @@ public abstract class CommandArgument
return true;
}
protected abstract Supplier<CommandArgument> factory();
protected abstract Supplier<CommandArgument> factory(MinecraftServer server);
private static class StringArgument extends CommandArgument
{
@@ -489,7 +488,7 @@ public abstract class CommandArgument
}
@Override
protected Supplier<CommandArgument> factory() { return StringArgument::new; }
protected Supplier<CommandArgument> factory(MinecraftServer server) { return StringArgument::new; }
}
private static class WordArgument extends StringArgument
@@ -498,7 +497,7 @@ public abstract class CommandArgument
@Override
public ArgumentType<?> getArgumentType(CarpetScriptHost host) { return StringArgumentType.word(); }
@Override
protected Supplier<CommandArgument> factory() { return WordArgument::new; }
protected Supplier<CommandArgument> factory(MinecraftServer server) { return WordArgument::new; }
}
private static class GreedyStringArgument extends StringArgument
@@ -507,7 +506,7 @@ public abstract class CommandArgument
@Override
public ArgumentType<?> getArgumentType(CarpetScriptHost host) { return StringArgumentType.greedyString(); }
@Override
protected Supplier<CommandArgument> factory() { return GreedyStringArgument::new; }
protected Supplier<CommandArgument> factory(MinecraftServer server) { return GreedyStringArgument::new; }
}
private static class BlockPosArgument extends CommandArgument
@@ -542,7 +541,7 @@ public abstract class CommandArgument
}
@Override
protected Supplier<CommandArgument> factory()
protected Supplier<CommandArgument> factory(MinecraftServer server)
{
return BlockPosArgument::new;
}
@@ -577,7 +576,7 @@ public abstract class CommandArgument
}
@Override
protected Supplier<CommandArgument> factory()
protected Supplier<CommandArgument> factory(MinecraftServer server)
{
return LocationArgument::new;
}
@@ -626,7 +625,7 @@ public abstract class CommandArgument
}
@Override
protected Supplier<CommandArgument> factory()
protected Supplier<CommandArgument> factory(MinecraftServer server)
{
return EntityArgument::new;
}
@@ -666,7 +665,7 @@ public abstract class CommandArgument
}
@Override
protected Supplier<CommandArgument> factory()
protected Supplier<CommandArgument> factory(MinecraftServer server)
{
return PlayerProfileArgument::new;
}
@@ -680,7 +679,7 @@ public abstract class CommandArgument
{
super("scoreholder", ScoreHolderArgument.scoreHolder().getExamples(), false);
single = false;
suggestionProvider = ScoreHolderArgument.SUGGEST_SCORE_HOLDERS;
suggestionProvider = param -> ScoreHolderArgument.SUGGEST_SCORE_HOLDERS;
}
@Override
protected ArgumentType<?> getArgumentType(CarpetScriptHost host)
@@ -707,7 +706,7 @@ public abstract class CommandArgument
}
@Override
protected Supplier<CommandArgument> factory()
protected Supplier<CommandArgument> factory(MinecraftServer server)
{
return PlayerProfileArgument::new;
}
@@ -744,7 +743,7 @@ public abstract class CommandArgument
}
@Override
protected Supplier<CommandArgument> factory()
protected Supplier<CommandArgument> factory(MinecraftServer server)
{
return TagArgument::new;
}
@@ -777,7 +776,7 @@ public abstract class CommandArgument
}
@Override
protected Supplier<CommandArgument> factory()
protected Supplier<CommandArgument> factory(MinecraftServer server)
{
return CustomIdentifierArgument::new;
}
@@ -840,7 +839,7 @@ public abstract class CommandArgument
}
@Override
protected Supplier<CommandArgument> factory()
protected Supplier<CommandArgument> factory(MinecraftServer server)
{
return FloatArgument::new;
}
@@ -891,7 +890,7 @@ public abstract class CommandArgument
}
@Override
protected Supplier<CommandArgument> factory()
protected Supplier<CommandArgument> factory(MinecraftServer server)
{
return IntArgument::new;
}
@@ -986,7 +985,7 @@ public abstract class CommandArgument
}
@Override
protected Supplier<CommandArgument> factory()
protected Supplier<CommandArgument> factory(MinecraftServer server)
{
return SlotArgument::new;
}
@@ -1046,7 +1045,7 @@ public abstract class CommandArgument
)
{
super(suffix, Collections.emptyList(), false);
this.suggestionProvider = suggester;
this.suggestionProvider = param -> suggester;
this.providesExamples = false;
this.argumentTypeSupplier = argumentTypeSupplier;
this.valueExtractor = valueExtractor;
@@ -1056,13 +1055,13 @@ public abstract class CommandArgument
String suffix,
ArgumentProviderEx argumentTypeSupplier,
ValueExtractor valueExtractor,
boolean suggestFromExamples
)
boolean suggestFromExamples,
MinecraftServer server)
{
super(suffix, null, suggestFromExamples);
try
{
final CommandBuildContext context = new CommandBuildContext(RegistryAccess.BUILTIN.get());
final CommandBuildContext context = new CommandBuildContext(server.registryAccess(), server.getWorldData().enabledFeatures());
context.missingTagAccessPolicy(CommandBuildContext.MissingTagAccessPolicy.RETURN_EMPTY);
this.examples = argumentTypeSupplier.get(context).getExamples();
}
@@ -1076,11 +1075,54 @@ public abstract class CommandArgument
this.argumentTypeSupplier = null;
}
public VanillaUnconfigurableArgument(
String suffix,
ArgumentProviderEx argumentTypeSupplier,
ValueExtractor valueExtractor,
SuggestionProvider<CommandSourceStack> suggester
)
{
super(suffix, Collections.emptyList(), false);
this.suggestionProvider = param -> suggester;
this.providesExamples = false;
this.argumentTypeSupplierEx = argumentTypeSupplier;
this.valueExtractor = valueExtractor;
this.argumentTypeSupplier = null;
}
public VanillaUnconfigurableArgument(
String suffix,
ArgumentProviderEx argumentTypeSupplier,
ValueExtractor valueExtractor,
Function<String, SuggestionProvider<CommandSourceStack>> suggesterGen
)
{
super(suffix, Collections.emptyList(), false);
this.suggestionProvider = suggesterGen;
this.providesExamples = false;
this.argumentTypeSupplierEx = argumentTypeSupplier;
this.valueExtractor = valueExtractor;
this.argumentTypeSupplier = null;
}
public <T> VanillaUnconfigurableArgument(
String suffix,
ResourceKey<Registry<T>> registry
)
{
this(
suffix,
(c) -> ResourceArgument.resource(c, registry),
(c, p) -> ValueConversions.of(ResourceArgument.getResource(c, p, registry).key()),
(c, b) -> SharedSuggestionProvider.suggestResource(c.getSource().getServer().registryAccess().registryOrThrow(registry).keySet(), b)
);
}
@Override
protected ArgumentType<?> getArgumentType(CarpetScriptHost host) throws CommandSyntaxException
{
if (argumentTypeSupplier != null) return argumentTypeSupplier.get();
CommandBuildContext registryAccess = new CommandBuildContext(host.scriptServer().server.registryAccess());
CommandBuildContext registryAccess = new CommandBuildContext(host.scriptServer().server.registryAccess(), host.scriptServer().server.getWorldData().enabledFeatures());
return argumentTypeSupplierEx.get(registryAccess);
}
@@ -1091,10 +1133,10 @@ public abstract class CommandArgument
}
@Override
protected Supplier<CommandArgument> factory()
protected Supplier<CommandArgument> factory(MinecraftServer server)
{
if (argumentTypeSupplier != null) return () -> new VanillaUnconfigurableArgument(getTypeSuffix(), argumentTypeSupplier, valueExtractor, providesExamples);
return () -> new VanillaUnconfigurableArgument(getTypeSuffix(), argumentTypeSupplierEx, valueExtractor, providesExamples);
return () -> new VanillaUnconfigurableArgument(getTypeSuffix(), argumentTypeSupplierEx, valueExtractor, providesExamples, server);
}
}
}
@@ -48,6 +48,7 @@ import java.util.Objects;
public class Experimental
{
/*
public static Value reloadOne(MinecraftServer server)
{
LevelStorageSource.LevelStorageAccess session = ((MinecraftServerInterface) server).getCMSession();
@@ -146,4 +147,6 @@ public class Experimental
((MinecraftServerInterface)server).reloadAfterReload(stem.registryAccess());
return ListValue.wrap(addeds);
}
*/
}
@@ -26,10 +26,10 @@ import com.mojang.blaze3d.vertex.VertexFormat.Mode;
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.client.renderer.block.model.ItemTransforms.TransformType;
import net.minecraft.commands.arguments.ParticleArgument;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.Registry;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.nbt.ByteTag;
@@ -69,7 +69,6 @@ import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import static java.util.Map.entry;
@@ -180,7 +179,7 @@ public class ShapeDispatcher
return particle;
try
{
particle = ParticleArgument.readParticle(new StringReader(name));
particle = ParticleArgument.readParticle(new StringReader(name), HolderLookup.forRegistry(Registry.PARTICLE_TYPE));
}
catch (CommandSyntaxException e)
{
@@ -220,7 +219,7 @@ public class ShapeDispatcher
}
// client
public static ExpiringShape fromTag(CompoundTag tag)
public static ExpiringShape fromTag(CompoundTag tag, Level level)
{
Map<String, Value> options = new HashMap<>();
for (String key : tag.getAllKeys())
@@ -231,7 +230,7 @@ public class ShapeDispatcher
CarpetSettings.LOG.info("Unknown parameter for shape: "+key);
return null;
}
Value decodedValue = decoder.decode(tag.get(key));
Value decodedValue = decoder.decode(tag.get(key), level);
options.put(key, decodedValue);
}
Value shapeValue = options.get("shape");
@@ -1257,7 +1256,7 @@ public class ShapeDispatcher
public abstract Tag toTag(Value value); //validates value, returning null if not necessary to keep it and serialize
public abstract Value validate(Map<String, Value> options, MinecraftServer server, Value value); // makes sure the value is proper
public abstract Value decode(Tag tag);
public abstract Value decode(Tag tag, Level level);
}
public static class OptionalBoolListParam extends Param
{
@@ -1266,7 +1265,7 @@ public class ShapeDispatcher
@Override
public Tag toTag(Value value) { return value.toTag(true);}
@Override
public Value decode(Tag tag) {
public Value decode(Tag tag, Level level) {
if(tag instanceof ListTag){
return ListValue.wrap(((ListTag)tag).stream().map(x->BooleanValue.of(((NumericTag)x).getAsNumber().doubleValue()!=0)));
}
@@ -1294,7 +1293,7 @@ public class ShapeDispatcher
@Override
public Tag toTag(Value value) { return StringTag.valueOf(value.getString()); }
@Override
public Value decode(Tag tag) { return new StringValue(tag.getAsString()); }
public Value decode(Tag tag, Level level) { return new StringValue(tag.getAsString()); }
}
public static class BlockParam extends Param
{
@@ -1325,8 +1324,8 @@ public class ShapeDispatcher
}
@Override
public Value decode(Tag tag) {
BlockState bs = NbtUtils.readBlockState((CompoundTag) tag);
public Value decode(Tag tag, Level level) {
BlockState bs = NbtUtils.readBlockState(level.holderLookup(Registry.BLOCK_REGISTRY), (CompoundTag) tag);
CompoundTag compoundTag2 = null;
if (((CompoundTag) tag).contains("TileEntityData", 10)) {
compoundTag2 = ((CompoundTag) tag).getCompound("TileEntityData");
@@ -1351,7 +1350,7 @@ public class ShapeDispatcher
return ((NBTSerializableValue)value).getTag();
}
@Override
public Value decode(Tag tag) {
public Value decode(Tag tag, Level level) {
return new NBTSerializableValue(tag);
}
}
@@ -1391,7 +1390,7 @@ public class ShapeDispatcher
}
@Override
public Value decode(Tag tag)
public Value decode(Tag tag, Level level)
{
return FormattedTextValue.deserialize(tag.getAsString());
}
@@ -1462,7 +1461,7 @@ public class ShapeDispatcher
}
@Override
public Value decode(Tag tag)
public Value decode(Tag tag, Level level)
{
return BooleanValue.of(((ByteTag) tag).getAsByte() > 0);
}
@@ -1471,7 +1470,7 @@ public class ShapeDispatcher
{
protected FloatParam(String id) { super(id); }
@Override
public Value decode(Tag tag) { return new NumericValue(((FloatTag)tag).getAsFloat()); }
public Value decode(Tag tag, Level level) { return new NumericValue(((FloatTag)tag).getAsFloat()); }
@Override
public Tag toTag(Value value) { return FloatTag.valueOf(NumericValue.asNumber(value, id).getFloat()); }
}
@@ -1490,7 +1489,7 @@ public class ShapeDispatcher
{
protected PositiveFloatParam(String id) { super(id); }
@Override
public Value decode(Tag tag) { return new NumericValue(((FloatTag)tag).getAsFloat()); }
public Value decode(Tag tag, Level level) { return new NumericValue(((FloatTag)tag).getAsFloat()); }
@Override
public Tag toTag(Value value) { return FloatTag.valueOf(NumericValue.asNumber(value, id).getFloat()); }
@@ -1499,7 +1498,7 @@ public class ShapeDispatcher
{
protected PositiveIntParam(String id) { super(id); }
@Override
public Value decode(Tag tag) { return new NumericValue(((IntTag)tag).getAsInt()); }
public Value decode(Tag tag, Level level) { return new NumericValue(((IntTag)tag).getAsInt()); }
@Override
public Tag toTag(Value value) { return IntTag.valueOf(NumericValue.asNumber(value, id).getInt()); }
@@ -1508,7 +1507,7 @@ public class ShapeDispatcher
{
protected NonNegativeIntParam(String id) { super(id); }
@Override
public Value decode(Tag tag) { return new NumericValue(((IntTag)tag).getAsInt()); }
public Value decode(Tag tag, Level level) { return new NumericValue(((IntTag)tag).getAsInt()); }
@Override
public Tag toTag(Value value) { return IntTag.valueOf(NumericValue.asNumber(value, id).getInt()); }
@Override public Value validate(Map<String, Value> options, MinecraftServer server, Value value)
@@ -1522,7 +1521,7 @@ public class ShapeDispatcher
{
protected NonNegativeFloatParam(String id) { super(id); }
@Override
public Value decode(Tag tag) { return new NumericValue(((FloatTag)tag).getAsFloat()); }
public Value decode(Tag tag, Level level) { return new NumericValue(((FloatTag)tag).getAsFloat()); }
@Override
public Tag toTag(Value value) { return FloatTag.valueOf(NumericValue.asNumber(value, id).getFloat()); }
@Override public Value validate(Map<String, Value> options, MinecraftServer server, Value value)
@@ -1590,7 +1589,7 @@ public class ShapeDispatcher
}
@Override
public Value decode(Tag tag)
public Value decode(Tag tag, Level level)
{
ListTag ctag = (ListTag)tag;
return ListValue.of(
@@ -1629,7 +1628,7 @@ public class ShapeDispatcher
}
@Override
public Value decode(Tag tag)
public Value decode(Tag tag, Level level)
{
ListTag ltag = (ListTag)tag;
List<Value> points = new ArrayList<>();
@@ -1671,7 +1670,7 @@ public class ShapeDispatcher
}
@Override
public Value decode(Tag tag) { return new NumericValue(((IntTag)tag).getAsInt()); }
public Value decode(Tag tag, Level level) { return new NumericValue(((IntTag)tag).getAsInt()); }
@Override
public Tag toTag(Value value) { return IntTag.valueOf(NumericValue.asNumber(value, id).getInt()); }
}
@@ -1698,7 +1697,7 @@ public class ShapeDispatcher
}
@Override
public Value decode(Tag tag) { return new NumericValue(((IntTag)tag).getAsInt()); }
public Value decode(Tag tag, Level level) { return new NumericValue(((IntTag)tag).getAsInt()); }
}
private static boolean isStraight(Vec3 from, Vec3 to, double density)
@@ -164,7 +164,7 @@ public class ShapesRenderer
public void addShape(CompoundTag tag)
{
ShapeDispatcher.ExpiringShape shape = ShapeDispatcher.fromTag(tag);
ShapeDispatcher.ExpiringShape shape = ShapeDispatcher.fromTag(tag, client.level);
if (shape == null) return;
BiFunction<Minecraft, ShapeDispatcher.ExpiringShape, RenderedShape<? extends ShapeDispatcher.ExpiringShape >> shapeFactory;
shapeFactory = renderedShapes.get(tag.getString("shape"));
@@ -44,7 +44,7 @@ public class SnoopyCommandSource extends CommandSourceStack
{
super(CommandSource.NULL, original.getPosition(), original.getRotation(), original.getLevel(), CarpetSettings.runPermissionLevel,
original.getTextName(), original.getDisplayName(), original.getServer(), original.getEntity(), false,
(ctx, succ, res) -> { }, EntityAnchorArgument.Anchor.FEET, CommandSigningContext.ANONYMOUS, TaskChainer.IMMEDIATE);
(ctx, succ, res) -> { }, EntityAnchorArgument.Anchor.FEET, CommandSigningContext.ANONYMOUS, TaskChainer.immediate(original.getServer()));
this.output = CommandSource.NULL;
this.position = original.getPosition();
this.world = original.getLevel();
@@ -87,7 +87,7 @@ public class SnoopyCommandSource extends CommandSourceStack
) {
super(output, pos, rot, world, level,
simpleName, name, server, entity, false,
consumer, entityAnchor, context, TaskChainer.IMMEDIATE);
consumer, entityAnchor, context, TaskChainer.immediate(server));
this.output = output;
this.position = pos;
this.rotation = rot;
@@ -15,6 +15,7 @@ import carpet.script.value.StringValue;
import carpet.script.value.Value;
import carpet.script.value.ValueConversions;
import carpet.api.settings.SettingsManager;
import com.mojang.bridge.game.PackType;
import com.sun.management.OperatingSystemMXBean;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.ModContainer;
@@ -87,19 +88,19 @@ public class SystemInfo {
put("game_view_distance", c -> new NumericValue(c.s.getServer().getPlayerList().getViewDistance()));
put("game_mod_name", c -> StringValue.of(c.s.getServer().getServerModName()));
put("game_version", c -> StringValue.of(c.s.getServer().getServerVersion()));
put("game_target", c -> StringValue.of(SharedConstants.getCurrentVersion().getReleaseTarget()));
put("game_target", c -> StringValue.of(CarpetSettings.releaseTarget));
put("game_protocol", c -> NumericValue.of(SharedConstants.getProtocolVersion()));
put("game_major_target", c -> {
String [] vers = SharedConstants.getCurrentVersion().getReleaseTarget().split("\\.");
String [] vers = CarpetSettings.releaseTarget.split("\\.");
return NumericValue.of((vers.length > 1)?Integer.parseInt(vers[1]):0);
});
put("game_minor_target", c -> {
String [] vers = SharedConstants.getCurrentVersion().getReleaseTarget().split("\\.");
String [] vers = CarpetSettings.releaseTarget.split("\\.");
return NumericValue.of((vers.length > 2)?Integer.parseInt(vers[2]):0);
});
put("game_stable", c -> BooleanValue.of(SharedConstants.getCurrentVersion().isStable()));
put("game_data_version", c->NumericValue.of(SharedConstants.getCurrentVersion().getWorldVersion()));
put("game_pack_version", c->NumericValue.of(SharedConstants.getCurrentVersion().getPackVersion()));
put("game_pack_version", c->NumericValue.of(SharedConstants.getCurrentVersion().getPackVersion(PackType.DATA)));
put("server_ip", c -> StringValue.of(c.s.getServer().getLocalIp()));
put("server_whitelisted", c -> BooleanValue.of(c.s.getServer().isEnforceWhitelist()));
@@ -9,6 +9,7 @@ import net.minecraft.commands.CommandBuildContext;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.core.RegistryAccess;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.flag.FeatureFlags;
import org.apache.logging.log4j.util.TriConsumer;
import java.util.Collection;
import java.util.List;
@@ -207,7 +208,7 @@ public class SettingsManager extends carpet.api.settings.SettingsManager
@Deprecated(forRemoval = true)
public void registerCommand(CommandDispatcher<CommandSourceStack> dispatcher)
{
final CommandBuildContext context = new CommandBuildContext(RegistryAccess.BUILTIN.get());
final CommandBuildContext context = new CommandBuildContext(RegistryAccess.EMPTY, FeatureFlags.VANILLA_SET);
context.missingTagAccessPolicy(CommandBuildContext.MissingTagAccessPolicy.RETURN_EMPTY);
registerCommand(dispatcher, context);
}