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 -1
View File
@@ -1,5 +1,5 @@
plugins { plugins {
id 'fabric-loom' version '0.12-SNAPSHOT' id 'fabric-loom' version '1.0-SNAPSHOT'
id 'io.github.juuxel.loom-quiltflower' version '1.7.3' id 'io.github.juuxel.loom-quiltflower' version '1.7.3'
id 'maven-publish' id 'maven-publish'
} }
-12
View File
@@ -53,18 +53,6 @@ stack_limit('ender_pearl') => 16
stack_limit('stone') => 64 stack_limit('stone') => 64
</pre> </pre>
### `item_category(item)`
Returns the string representing the category of a given item, like `building_blocks`, `combat`, or `tools`.
Throws `unknown_item` if item doesn't exist.
<pre>
item_category('wooden_axe') => tools
item_category('ender_pearl') => misc
item_category('stone') => building_blocks
</pre>
### `recipe_data(item, type?)`, `recipe_data(recipe, type?)` ### `recipe_data(item, type?)`, `recipe_data(recipe, type?)`
returns all recipes matching either an `item`, or represent actual `recipe` name. In vanilla datapack, for all items returns all recipes matching either an `item`, or represent actual `recipe` name. In vanilla datapack, for all items
@@ -56,7 +56,6 @@ inventory_get
inventory_remove inventory_remove
inventory_set inventory_set
inventory_size inventory_size
item_category
item_display_name item_display_name
item_list item_list
item_tags item_tags
@@ -77,7 +77,7 @@
player spawn entity_id entity_list entity_area entity_selector query modify entity_event entity_load_handler entity_types player spawn entity_id entity_list entity_area entity_selector query modify entity_event entity_load_handler entity_types
item_list item_tags stack_limit item_category recipe_data crafting_remaining_item item_display_name item_list item_tags stack_limit recipe_data crafting_remaining_item item_display_name
inventory_size inventory_has_items inventory_get inventory_set inventory_find inventory_remove drop_item inventory_size inventory_has_items inventory_get inventory_set inventory_find inventory_remove drop_item
+3 -3
View File
@@ -4,9 +4,9 @@ org.gradle.jvmargs=-Xmx1G
# Fabric Properties # Fabric Properties
# check these on https://fabricmc.net/use # check these on https://fabricmc.net/use
# or better: https://modmuss50.me/fabric.html # or better: https://modmuss50.me/fabric.html
minecraft_version=1.19.2 minecraft_version=22w42a
loader_version=0.14.9 loader_version=0.14.10
fabric_version=0.58.6+1.19.2 fabric_version=0.58.0+1.19
# Mod Properties # Mod Properties
mod_version = 1.4.84 mod_version = 1.4.84
+1
View File
@@ -48,6 +48,7 @@ import static carpet.api.settings.RuleCategory.CLIENT;
public class CarpetSettings public class CarpetSettings
{ {
public static final String carpetVersion = "1.4.84+v221018"; 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 Logger LOG = LoggerFactory.getLogger("carpet");
public static final ThreadLocal<Boolean> skipGenerationChecks = ThreadLocal.withInitial(() -> false); public static final ThreadLocal<Boolean> skipGenerationChecks = ThreadLocal.withInitial(() -> false);
public static final ThreadLocal<Boolean> impendingFillSkipUpdates = 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 com.mojang.brigadier.builder.LiteralArgumentBuilder;
import net.minecraft.commands.CommandBuildContext; import net.minecraft.commands.CommandBuildContext;
import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.arguments.EntitySummonArgument;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import static net.minecraft.commands.Commands.argument; import static net.minecraft.commands.Commands.argument;
import static net.minecraft.commands.Commands.literal; import static net.minecraft.commands.Commands.literal;
import static net.minecraft.commands.SharedSuggestionProvider.suggest; 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 public class MobAICommand
{ {
@@ -21,20 +22,20 @@ public class MobAICommand
{ {
LiteralArgumentBuilder<CommandSourceStack> command = literal("track"). LiteralArgumentBuilder<CommandSourceStack> command = literal("track").
requires((player) -> CommandHelper.canUseCommand(player, CarpetSettings.commandTrackAI)). 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)). suggests( (c, b) -> suggest(MobAI.availbleTypes(), b)).
then(literal("clear").executes( (c) -> 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; return 1;
} }
)). )).
then(argument("aspect", StringArgumentType.word()). 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) -> { executes( (c) -> {
MobAI.startTracking( MobAI.startTracking(
Registry.ENTITY_TYPE.get(EntitySummonArgument.getSummonableEntity(c, "entity type")), getSummonableEntityType(c, "entity type").value(),
MobAI.TrackingType.valueOf(StringArgumentType.getString(c, "aspect").toUpperCase()) MobAI.TrackingType.valueOf(StringArgumentType.getString(c, "aspect").toUpperCase())
); );
return 1; return 1;
@@ -8,10 +8,10 @@ import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import net.minecraft.commands.CommandBuildContext; import net.minecraft.commands.CommandBuildContext;
import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.arguments.EntitySummonArgument;
import net.minecraft.commands.arguments.coordinates.BlockPosArgument; import net.minecraft.commands.arguments.coordinates.BlockPosArgument;
import net.minecraft.commands.synchronization.SuggestionProviders; import net.minecraft.commands.synchronization.SuggestionProviders;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Registry;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType; 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.argument;
import static net.minecraft.commands.Commands.literal; 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 public class PerimeterInfoCommand
{ {
@@ -35,12 +37,12 @@ public class PerimeterInfoCommand
c.getSource(), c.getSource(),
BlockPosArgument.getSpawnablePos(c, "center position"), BlockPosArgument.getSpawnablePos(c, "center position"),
null)). null)).
then(argument("mob",EntitySummonArgument.id()). then(argument("mob", resource(commandBuildContext, Registry.ENTITY_TYPE_REGISTRY)).
suggests(SuggestionProviders.SUMMONABLE_ENTITIES). suggests(SuggestionProviders.SUMMONABLE_ENTITIES).
executes( (c) -> perimeterDiagnose( executes( (c) -> perimeterDiagnose(
c.getSource(), c.getSource(),
BlockPosArgument.getSpawnablePos(c, "center position"), BlockPosArgument.getSpawnablePos(c, "center position"),
EntitySummonArgument.getSummonableEntity(c, "mob").toString() getSummonableEntityType(c, "mob").key().location().toString()
)))); ))));
dispatcher.register(command); dispatcher.register(command);
} }
@@ -58,7 +60,7 @@ public class PerimeterInfoCommand
}); });
if (!(baseEntity instanceof Mob)) 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(); if (baseEntity != null) baseEntity.discard();
return 0; return 0;
} }
@@ -5,6 +5,8 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import net.minecraft.commands.arguments.ParticleArgument; 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.core.particles.ParticleOptions;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
@@ -18,7 +20,7 @@ public class ParticleDisplay
{ {
try try
{ {
return ParticleArgument.readParticle(new StringReader(name)); return ParticleArgument.readParticle(new StringReader(name), HolderLookup.forRegistry(Registry.PARTICLE_TYPE));
} }
catch (CommandSyntaxException e) catch (CommandSyntaxException e)
{ {
@@ -3,27 +3,32 @@ package carpet.mixins;
import carpet.CarpetServer; import carpet.CarpetServer;
import carpet.network.CarpetClient; import carpet.network.CarpetClient;
import carpet.api.settings.SettingsManager; 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.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.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(LocalPlayer.class) @Mixin(ClientPacketListener.class)
public class LocalPlayer_clientCommandMixin public class ClientPacketListener_clientCommandMixin
{ {
@Inject(method = "commandSigned", at = @At("HEAD")) @Shadow @Final private Minecraft minecraft;
private void inspectMessage(String string, Component component, CallbackInfo ci)
@Inject(method = "sendCommand", at = @At("HEAD"))
private void inspectMessage(String string, CallbackInfo ci)
{ {
if (string.startsWith("call ")) if (string.startsWith("call "))
{ {
String command = string.substring(5); String command = string.substring(5);
CarpetClient.sendClientCommand(command); 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.settingsManager.inspectClientsideCommand(playerSource.createCommandSourceStack(), "/"+string);
CarpetServer.extensions.forEach(e -> { CarpetServer.extensions.forEach(e -> {
SettingsManager sm = e.extensionSettingsManager(); SettingsManager sm = e.extensionSettingsManager();
@@ -3,10 +3,10 @@ package carpet.mixins;
import carpet.fakes.ServerPlayerEntityInterface; import carpet.fakes.ServerPlayerEntityInterface;
import carpet.helpers.EntityPlayerActionPack; import carpet.helpers.EntityPlayerActionPack;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
import net.minecraft.network.chat.RemoteChatSession;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.player.ProfilePublicKey;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At; 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")) @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); 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.damagesource.DamageSource;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.player.ProfilePublicKey;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
@@ -39,8 +38,8 @@ public abstract class ServerPlayer_scarpetEventMixin extends Player implements S
@Unique @Unique
private boolean isInvalidReference = false; private boolean isInvalidReference = false;
public ServerPlayer_scarpetEventMixin(Level level, BlockPos blockPos, float f, GameProfile gameProfile, ProfilePublicKey profilePublicKey) { public ServerPlayer_scarpetEventMixin(Level level, BlockPos blockPos, float f, GameProfile gameProfile) {
super(level, blockPos, f, gameProfile, profilePublicKey); super(level, blockPos, f, gameProfile);
} }
@Shadow protected abstract void completeUsingItem(); @Shadow protected abstract void completeUsingItem();
@@ -4,8 +4,9 @@ import carpet.CarpetSettings;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
import net.minecraft.core.UUIDUtil; import net.minecraft.core.UUIDUtil;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.RemoteChatSession;
import net.minecraft.network.protocol.PacketFlow; 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.ClientboundRotateHeadPacket;
import net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket; import net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket;
import net.minecraft.resources.ResourceKey; 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.Entity;
import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.player.ProfilePublicKey;
import net.minecraft.world.food.FoodData; import net.minecraft.world.food.FoodData;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.GameType; import net.minecraft.world.level.GameType;
@@ -62,7 +62,7 @@ public class EntityPlayerMPFake extends ServerPlayer
SkullBlockEntity.updateGameprofile(gameprofile, result::set); SkullBlockEntity.updateGameprofile(gameprofile, result::set);
gameprofile = result.get(); 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); instance.fixStartingPosition = () -> instance.moveTo(d0, d1, d2, (float) yaw, (float) pitch);
server.getPlayerList().placeNewPlayer(new FakeClientConnection(PacketFlow.SERVERBOUND), instance); server.getPlayerList().placeNewPlayer(new FakeClientConnection(PacketFlow.SERVERBOUND), instance);
instance.teleportTo(worldIn, d0, d1, d2, (float)yaw, (float)pitch); 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")); player.connection.disconnect(Component.translatable("multiplayer.disconnect.duplicate_login"));
ServerLevel worldIn = player.getLevel();//.getWorld(player.dimension); ServerLevel worldIn = player.getLevel();//.getWorld(player.dimension);
GameProfile gameprofile = player.getGameProfile(); 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); server.getPlayerList().placeNewPlayer(new FakeClientConnection(PacketFlow.SERVERBOUND), playerShadow);
playerShadow.setHealth(player.getHealth()); 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 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); //player.world.getChunkManager().updatePosition(playerShadow);
playerShadow.getAbilities().flying = player.getAbilities().flying; playerShadow.getAbilities().flying = player.getAbilities().flying;
return playerShadow; 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; isAShadow = shadow;
} }
@@ -38,6 +38,7 @@ import carpet.script.value.Value;
import carpet.script.value.ValueConversions; import carpet.script.value.ValueConversions;
import carpet.utils.Messenger; import carpet.utils.Messenger;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.mojang.bridge.game.PackType;
import net.minecraft.SharedConstants; import net.minecraft.SharedConstants;
import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.CommandSourceStack;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
@@ -1050,7 +1051,7 @@ public class Auxiliary {
Path zipRoot = zipfs.getPath("/"); Path zipRoot = zipfs.getPath("/");
zipValueToJson(zipRoot.resolve("pack.mcmeta"), MapValue.wrap( zipValueToJson(zipRoot.resolve("pack.mcmeta"), MapValue.wrap(
Map.of(StringValue.of("pack"), MapValue.wrap(Map.of( 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("description"), StringValue.of(name),
StringValue.of("source"), StringValue.of("scarpet") StringValue.of("source"), StringValue.of("scarpet")
))) )))
@@ -59,11 +59,10 @@ public class Inventories {
expression.addUnaryFunction("stack_limit", v -> expression.addUnaryFunction("stack_limit", v ->
new NumericValue(NBTSerializableValue.parseItem(v.getString()).getItem().getMaxStackSize())); new NumericValue(NBTSerializableValue.parseItem(v.getString()).getItem().getMaxStackSize()));
expression.addUnaryFunction("item_category", v -> expression.addContextFunction("item_category", -1, (c, t, lv) -> {
{ CarpetContext cc = (CarpetContext)c;
ItemInput item = NBTSerializableValue.parseItem(v.getString()); cc.host.issueDeprecation("item_category in 1.19.3+");
CreativeModeTab ig = item.getItem().getItemCategory(); return Value.NULL;
return (ig==null)?Value.NULL:new StringValue(ig.getRecipeFolderName());
}); });
expression.addContextFunction("item_list", -1, (c, t, lv) -> expression.addContextFunction("item_list", -1, (c, t, lv) ->
@@ -50,6 +50,7 @@ import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.function.Function;
import java.util.function.Supplier; import java.util.function.Supplier;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import net.minecraft.ChatFormatting; 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.CompoundTagArgument;
import net.minecraft.commands.arguments.DimensionArgument; import net.minecraft.commands.arguments.DimensionArgument;
import net.minecraft.commands.arguments.EntityAnchorArgument; import net.minecraft.commands.arguments.EntityAnchorArgument;
import net.minecraft.commands.arguments.EntitySummonArgument;
import net.minecraft.commands.arguments.GameProfileArgument; import net.minecraft.commands.arguments.GameProfileArgument;
import net.minecraft.commands.arguments.ItemEnchantmentArgument;
import net.minecraft.commands.arguments.MessageArgument; import net.minecraft.commands.arguments.MessageArgument;
import net.minecraft.commands.arguments.MobEffectArgument;
import net.minecraft.commands.arguments.NbtPathArgument; import net.minecraft.commands.arguments.NbtPathArgument;
import net.minecraft.commands.arguments.NbtTagArgument; import net.minecraft.commands.arguments.NbtTagArgument;
import net.minecraft.commands.arguments.ObjectiveArgument; import net.minecraft.commands.arguments.ObjectiveArgument;
import net.minecraft.commands.arguments.ObjectiveCriteriaArgument; import net.minecraft.commands.arguments.ObjectiveCriteriaArgument;
import net.minecraft.commands.arguments.ParticleArgument; import net.minecraft.commands.arguments.ParticleArgument;
import net.minecraft.commands.arguments.RangeArgument; 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.ResourceLocationArgument;
import net.minecraft.commands.arguments.ResourceOrTagLocationArgument; import net.minecraft.commands.arguments.ResourceOrTagArgument;
import net.minecraft.commands.arguments.ScoreHolderArgument; import net.minecraft.commands.arguments.ScoreHolderArgument;
import net.minecraft.commands.arguments.ScoreboardSlotArgument; import net.minecraft.commands.arguments.ScoreboardSlotArgument;
import net.minecraft.commands.arguments.TeamArgument; 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.commands.synchronization.SuggestionProviders;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.core.Holder;
import net.minecraft.core.HolderSet;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.core.RegistryAccess;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.commands.BossBarCommands; import net.minecraft.server.commands.BossBarCommands;
import net.minecraft.tags.TagKey;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.phys.Vec2; import net.minecraft.world.phys.Vec2;
@@ -137,10 +136,11 @@ public abstract class CommandArgument
BlockInput result = BlockStateArgument.getBlock(c, p); BlockInput result = BlockStateArgument.getBlock(c, p);
return new BlockValue(result.getState(), null, null, ((BlockStateArgumentInterface)result).getCMTag() ); 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, 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, new VanillaUnconfigurableArgument("teamcolor", ColorArgument::color,
(c, p) -> { (c, p) -> {
@@ -160,8 +160,8 @@ public abstract class CommandArgument
new VanillaUnconfigurableArgument("anchor", EntityAnchorArgument::anchor, new VanillaUnconfigurableArgument("anchor", EntityAnchorArgument::anchor,
(c, p) -> StringValue.of(EntityAnchorArgument.getAnchor(c, p).name()), false (c, p) -> StringValue.of(EntityAnchorArgument.getAnchor(c, p).name()), false
), ),
new VanillaUnconfigurableArgument("entitytype", EntitySummonArgument::id, new VanillaUnconfigurableArgument("entitytype", c -> ResourceArgument.resource(c, Registry.ENTITY_TYPE_REGISTRY),
(c, p) -> ValueConversions.of(EntitySummonArgument.getSummonableEntity(c, p)), SuggestionProviders.SUMMONABLE_ENTITIES (c, p) -> ValueConversions.of(ResourceArgument.getSummonableEntityType(c, p).key()), SuggestionProviders.SUMMONABLE_ENTITIES
), ),
new VanillaUnconfigurableArgument("floatrange", RangeArgument::floatRange, new VanillaUnconfigurableArgument("floatrange", RangeArgument::floatRange,
(c, p) -> ValueConversions.of(c.getArgument(p, MinMaxBounds.Doubles.class)), true (c, p) -> ValueConversions.of(c.getArgument(p, MinMaxBounds.Doubles.class)), true
@@ -172,20 +172,19 @@ public abstract class CommandArgument
new VanillaUnconfigurableArgument("intrange", RangeArgument::intRange, new VanillaUnconfigurableArgument("intrange", RangeArgument::intRange,
(c, p) -> ValueConversions.of(RangeArgument.Ints.getRange(c, p)), true (c, p) -> ValueConversions.of(RangeArgument.Ints.getRange(c, p)), true
), ),
new VanillaUnconfigurableArgument("enchantment", ItemEnchantmentArgument::enchantment, new VanillaUnconfigurableArgument("enchantment", Registry.ENCHANTMENT_REGISTRY),
(c, p) -> ValueConversions.of(Registry.ENCHANTMENT.getKey(ItemEnchantmentArgument.getEnchantment(c, p))), false
),
// item_predicate ?? //same as item but accepts tags, not sure right now // item_predicate ?? //same as item but accepts tags, not sure right now
new SlotArgument(), new SlotArgument(),
new VanillaUnconfigurableArgument("item", ItemArgument::item, 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, new VanillaUnconfigurableArgument("message", MessageArgument::message,
(c, p) -> new FormattedTextValue(MessageArgument.getMessage(c, p)), true (c, p) -> new FormattedTextValue(MessageArgument.getMessage(c, p)), true
), ),
new VanillaUnconfigurableArgument("effect", MobEffectArgument::effect, new VanillaUnconfigurableArgument("effect", Registry.MOB_EFFECT_REGISTRY),
(c, p) -> ValueConversions.of(Registry.MOB_EFFECT.getKey(MobEffectArgument.getEffect(c, p))),false
),
new TagArgument(), // for nbt_compound_tag and nbt_tag new TagArgument(), // for nbt_compound_tag and nbt_tag
new VanillaUnconfigurableArgument("path", NbtPathArgument::nbtPath, new VanillaUnconfigurableArgument("path", NbtPathArgument::nbtPath,
(c, p) -> StringValue.of(NbtPathArgument.getPath(c, p).toString()), true (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 // operation // not sure if we need it, you have scarpet for that
new VanillaUnconfigurableArgument("particle", ParticleArgument::particle, 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 // resource / identifier section
@@ -215,23 +214,23 @@ public abstract class CommandArgument
new VanillaUnconfigurableArgument("loottable", ResourceLocationArgument::id, new VanillaUnconfigurableArgument("loottable", ResourceLocationArgument::id,
(c, p) -> ValueConversions.of( ResourceLocationArgument.getId(c, p)), (ctx, builder) -> SharedSuggestionProvider.suggestResource(ctx.getSource().getServer().getLootTables().getIds(), builder) (c, p) -> ValueConversions.of( ResourceLocationArgument.getId(c, p)), (ctx, builder) -> SharedSuggestionProvider.suggestResource(ctx.getSource().getServer().getLootTables().getIds(), builder)
), ),
new VanillaUnconfigurableArgument("attribute", ResourceLocationArgument::id, new VanillaUnconfigurableArgument("attribute", Registry.ATTRIBUTE_REGISTRY),
(c, p) -> ValueConversions.of( Registry.ATTRIBUTE.getKey(ResourceKeyArgument.getAttribute(c, p))), (ctx, builder) -> SharedSuggestionProvider.suggestResource(Registry.ATTRIBUTE.keySet(), builder)
),
new VanillaUnconfigurableArgument("boss", ResourceLocationArgument::id, new VanillaUnconfigurableArgument("boss", ResourceLocationArgument::id,
(c, p) -> ValueConversions.of( ResourceLocationArgument.getId(c, p)), BossBarCommands.SUGGEST_BOSS_BAR (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) -> { (c, p) -> {
ResourceOrTagLocationArgument.Result<Biome> result = ResourceOrTagLocationArgument.getRegistryType(c, "biome", Registry.BIOME_REGISTRY, ERROR_BIOME_INVALID); ResourceOrTagArgument.Result<Biome> result = ResourceOrTagArgument.getResourceOrTag(c, "biome", Registry.BIOME_REGISTRY);
Either<ResourceKey<Biome>, TagKey<Biome>> res = result.unwrap(); Either<Holder.Reference<Biome>, HolderSet.Named<Biome>> res = result.unwrap();
if (res.left().isPresent()) if (res.left().isPresent())
{ {
return ValueConversions.of(res.left().get()); return ValueConversions.of(res.left().get().key());
} }
if (res.right().isPresent()) if (res.right().isPresent())
{ {
return ValueConversions.of(res.right().get()); return ValueConversions.of(res.right().get().key());
} }
return Value.NULL; return Value.NULL;
}, (ctx, builder) -> SharedSuggestionProvider.suggestResource(ctx.getSource().getServer().registryAccess().registryOrThrow(Registry.BIOME_REGISTRY).keySet(), builder) }, (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 public static RequiredArgumentBuilder<CommandSourceStack, ?> argumentNode(String param, CarpetScriptHost host) throws CommandSyntaxException
{ {
CommandArgument arg = getTypeForArgument(param, host); 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)); if (!arg.needsMatching) return argument(param, arg.getArgumentType(host));
String hostName = host.getName(); String hostName = host.getName();
return argument(param, arg.getArgumentType(host)).suggests((ctx, b) -> { return argument(param, arg.getArgumentType(host)).suggests((ctx, b) -> {
@@ -317,7 +316,7 @@ public abstract class CommandArgument
protected Collection<String> examples; protected Collection<String> examples;
protected boolean needsMatching; protected boolean needsMatching;
protected boolean caseSensitive = true; protected boolean caseSensitive = true;
protected SuggestionProvider<CommandSourceStack> suggestionProvider; protected Function<String, SuggestionProvider<CommandSourceStack>> suggestionProvider;
protected FunctionArgument customSuggester; protected FunctionArgument customSuggester;
@@ -353,7 +352,7 @@ public abstract class CommandArgument
String baseType = config.get("type").getString(); String baseType = config.get("type").getString();
if (!builtIns.containsKey(baseType)) if (!builtIns.containsKey(baseType))
throw CommandArgument.error("Unknown base type "+baseType+" for custom type "+suffix); 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.suffix = suffix;
variant.configure(config, host); variant.configure(config, host);
return variant; return variant;
@@ -440,7 +439,7 @@ public abstract class CommandArgument
return true; return true;
} }
protected abstract Supplier<CommandArgument> factory(); protected abstract Supplier<CommandArgument> factory(MinecraftServer server);
private static class StringArgument extends CommandArgument private static class StringArgument extends CommandArgument
{ {
@@ -489,7 +488,7 @@ public abstract class CommandArgument
} }
@Override @Override
protected Supplier<CommandArgument> factory() { return StringArgument::new; } protected Supplier<CommandArgument> factory(MinecraftServer server) { return StringArgument::new; }
} }
private static class WordArgument extends StringArgument private static class WordArgument extends StringArgument
@@ -498,7 +497,7 @@ public abstract class CommandArgument
@Override @Override
public ArgumentType<?> getArgumentType(CarpetScriptHost host) { return StringArgumentType.word(); } public ArgumentType<?> getArgumentType(CarpetScriptHost host) { return StringArgumentType.word(); }
@Override @Override
protected Supplier<CommandArgument> factory() { return WordArgument::new; } protected Supplier<CommandArgument> factory(MinecraftServer server) { return WordArgument::new; }
} }
private static class GreedyStringArgument extends StringArgument private static class GreedyStringArgument extends StringArgument
@@ -507,7 +506,7 @@ public abstract class CommandArgument
@Override @Override
public ArgumentType<?> getArgumentType(CarpetScriptHost host) { return StringArgumentType.greedyString(); } public ArgumentType<?> getArgumentType(CarpetScriptHost host) { return StringArgumentType.greedyString(); }
@Override @Override
protected Supplier<CommandArgument> factory() { return GreedyStringArgument::new; } protected Supplier<CommandArgument> factory(MinecraftServer server) { return GreedyStringArgument::new; }
} }
private static class BlockPosArgument extends CommandArgument private static class BlockPosArgument extends CommandArgument
@@ -542,7 +541,7 @@ public abstract class CommandArgument
} }
@Override @Override
protected Supplier<CommandArgument> factory() protected Supplier<CommandArgument> factory(MinecraftServer server)
{ {
return BlockPosArgument::new; return BlockPosArgument::new;
} }
@@ -577,7 +576,7 @@ public abstract class CommandArgument
} }
@Override @Override
protected Supplier<CommandArgument> factory() protected Supplier<CommandArgument> factory(MinecraftServer server)
{ {
return LocationArgument::new; return LocationArgument::new;
} }
@@ -626,7 +625,7 @@ public abstract class CommandArgument
} }
@Override @Override
protected Supplier<CommandArgument> factory() protected Supplier<CommandArgument> factory(MinecraftServer server)
{ {
return EntityArgument::new; return EntityArgument::new;
} }
@@ -666,7 +665,7 @@ public abstract class CommandArgument
} }
@Override @Override
protected Supplier<CommandArgument> factory() protected Supplier<CommandArgument> factory(MinecraftServer server)
{ {
return PlayerProfileArgument::new; return PlayerProfileArgument::new;
} }
@@ -680,7 +679,7 @@ public abstract class CommandArgument
{ {
super("scoreholder", ScoreHolderArgument.scoreHolder().getExamples(), false); super("scoreholder", ScoreHolderArgument.scoreHolder().getExamples(), false);
single = false; single = false;
suggestionProvider = ScoreHolderArgument.SUGGEST_SCORE_HOLDERS; suggestionProvider = param -> ScoreHolderArgument.SUGGEST_SCORE_HOLDERS;
} }
@Override @Override
protected ArgumentType<?> getArgumentType(CarpetScriptHost host) protected ArgumentType<?> getArgumentType(CarpetScriptHost host)
@@ -707,7 +706,7 @@ public abstract class CommandArgument
} }
@Override @Override
protected Supplier<CommandArgument> factory() protected Supplier<CommandArgument> factory(MinecraftServer server)
{ {
return PlayerProfileArgument::new; return PlayerProfileArgument::new;
} }
@@ -744,7 +743,7 @@ public abstract class CommandArgument
} }
@Override @Override
protected Supplier<CommandArgument> factory() protected Supplier<CommandArgument> factory(MinecraftServer server)
{ {
return TagArgument::new; return TagArgument::new;
} }
@@ -777,7 +776,7 @@ public abstract class CommandArgument
} }
@Override @Override
protected Supplier<CommandArgument> factory() protected Supplier<CommandArgument> factory(MinecraftServer server)
{ {
return CustomIdentifierArgument::new; return CustomIdentifierArgument::new;
} }
@@ -840,7 +839,7 @@ public abstract class CommandArgument
} }
@Override @Override
protected Supplier<CommandArgument> factory() protected Supplier<CommandArgument> factory(MinecraftServer server)
{ {
return FloatArgument::new; return FloatArgument::new;
} }
@@ -891,7 +890,7 @@ public abstract class CommandArgument
} }
@Override @Override
protected Supplier<CommandArgument> factory() protected Supplier<CommandArgument> factory(MinecraftServer server)
{ {
return IntArgument::new; return IntArgument::new;
} }
@@ -986,7 +985,7 @@ public abstract class CommandArgument
} }
@Override @Override
protected Supplier<CommandArgument> factory() protected Supplier<CommandArgument> factory(MinecraftServer server)
{ {
return SlotArgument::new; return SlotArgument::new;
} }
@@ -1046,7 +1045,7 @@ public abstract class CommandArgument
) )
{ {
super(suffix, Collections.emptyList(), false); super(suffix, Collections.emptyList(), false);
this.suggestionProvider = suggester; this.suggestionProvider = param -> suggester;
this.providesExamples = false; this.providesExamples = false;
this.argumentTypeSupplier = argumentTypeSupplier; this.argumentTypeSupplier = argumentTypeSupplier;
this.valueExtractor = valueExtractor; this.valueExtractor = valueExtractor;
@@ -1056,13 +1055,13 @@ public abstract class CommandArgument
String suffix, String suffix,
ArgumentProviderEx argumentTypeSupplier, ArgumentProviderEx argumentTypeSupplier,
ValueExtractor valueExtractor, ValueExtractor valueExtractor,
boolean suggestFromExamples boolean suggestFromExamples,
) MinecraftServer server)
{ {
super(suffix, null, suggestFromExamples); super(suffix, null, suggestFromExamples);
try 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); context.missingTagAccessPolicy(CommandBuildContext.MissingTagAccessPolicy.RETURN_EMPTY);
this.examples = argumentTypeSupplier.get(context).getExamples(); this.examples = argumentTypeSupplier.get(context).getExamples();
} }
@@ -1076,11 +1075,54 @@ public abstract class CommandArgument
this.argumentTypeSupplier = null; 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 @Override
protected ArgumentType<?> getArgumentType(CarpetScriptHost host) throws CommandSyntaxException protected ArgumentType<?> getArgumentType(CarpetScriptHost host) throws CommandSyntaxException
{ {
if (argumentTypeSupplier != null) return argumentTypeSupplier.get(); 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); return argumentTypeSupplierEx.get(registryAccess);
} }
@@ -1091,10 +1133,10 @@ public abstract class CommandArgument
} }
@Override @Override
protected Supplier<CommandArgument> factory() protected Supplier<CommandArgument> factory(MinecraftServer server)
{ {
if (argumentTypeSupplier != null) return () -> new VanillaUnconfigurableArgument(getTypeSuffix(), argumentTypeSupplier, valueExtractor, providesExamples); 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 class Experimental
{ {
/*
public static Value reloadOne(MinecraftServer server) public static Value reloadOne(MinecraftServer server)
{ {
LevelStorageSource.LevelStorageAccess session = ((MinecraftServerInterface) server).getCMSession(); LevelStorageSource.LevelStorageAccess session = ((MinecraftServerInterface) server).getCMSession();
@@ -146,4 +147,6 @@ public class Experimental
((MinecraftServerInterface)server).reloadAfterReload(stem.registryAccess()); ((MinecraftServerInterface)server).reloadAfterReload(stem.registryAccess());
return ListValue.wrap(addeds); return ListValue.wrap(addeds);
} }
*/
} }
@@ -26,10 +26,10 @@ import com.mojang.blaze3d.vertex.VertexFormat.Mode;
import com.mojang.brigadier.StringReader; import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.client.renderer.block.model.ItemTransforms.TransformType;
import net.minecraft.commands.arguments.ParticleArgument; import net.minecraft.commands.arguments.ParticleArgument;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.core.particles.ParticleOptions; import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.nbt.ByteTag; import net.minecraft.nbt.ByteTag;
@@ -69,7 +69,6 @@ import java.util.Set;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.Function; import java.util.function.Function;
import java.util.function.Supplier; import java.util.function.Supplier;
import java.util.stream.Collectors;
import static java.util.Map.entry; import static java.util.Map.entry;
@@ -180,7 +179,7 @@ public class ShapeDispatcher
return particle; return particle;
try try
{ {
particle = ParticleArgument.readParticle(new StringReader(name)); particle = ParticleArgument.readParticle(new StringReader(name), HolderLookup.forRegistry(Registry.PARTICLE_TYPE));
} }
catch (CommandSyntaxException e) catch (CommandSyntaxException e)
{ {
@@ -220,7 +219,7 @@ public class ShapeDispatcher
} }
// client // client
public static ExpiringShape fromTag(CompoundTag tag) public static ExpiringShape fromTag(CompoundTag tag, Level level)
{ {
Map<String, Value> options = new HashMap<>(); Map<String, Value> options = new HashMap<>();
for (String key : tag.getAllKeys()) for (String key : tag.getAllKeys())
@@ -231,7 +230,7 @@ public class ShapeDispatcher
CarpetSettings.LOG.info("Unknown parameter for shape: "+key); CarpetSettings.LOG.info("Unknown parameter for shape: "+key);
return null; return null;
} }
Value decodedValue = decoder.decode(tag.get(key)); Value decodedValue = decoder.decode(tag.get(key), level);
options.put(key, decodedValue); options.put(key, decodedValue);
} }
Value shapeValue = options.get("shape"); 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 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 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 public static class OptionalBoolListParam extends Param
{ {
@@ -1266,7 +1265,7 @@ public class ShapeDispatcher
@Override @Override
public Tag toTag(Value value) { return value.toTag(true);} public Tag toTag(Value value) { return value.toTag(true);}
@Override @Override
public Value decode(Tag tag) { public Value decode(Tag tag, Level level) {
if(tag instanceof ListTag){ if(tag instanceof ListTag){
return ListValue.wrap(((ListTag)tag).stream().map(x->BooleanValue.of(((NumericTag)x).getAsNumber().doubleValue()!=0))); return ListValue.wrap(((ListTag)tag).stream().map(x->BooleanValue.of(((NumericTag)x).getAsNumber().doubleValue()!=0)));
} }
@@ -1294,7 +1293,7 @@ public class ShapeDispatcher
@Override @Override
public Tag toTag(Value value) { return StringTag.valueOf(value.getString()); } public Tag toTag(Value value) { return StringTag.valueOf(value.getString()); }
@Override @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 public static class BlockParam extends Param
{ {
@@ -1325,8 +1324,8 @@ public class ShapeDispatcher
} }
@Override @Override
public Value decode(Tag tag) { public Value decode(Tag tag, Level level) {
BlockState bs = NbtUtils.readBlockState((CompoundTag) tag); BlockState bs = NbtUtils.readBlockState(level.holderLookup(Registry.BLOCK_REGISTRY), (CompoundTag) tag);
CompoundTag compoundTag2 = null; CompoundTag compoundTag2 = null;
if (((CompoundTag) tag).contains("TileEntityData", 10)) { if (((CompoundTag) tag).contains("TileEntityData", 10)) {
compoundTag2 = ((CompoundTag) tag).getCompound("TileEntityData"); compoundTag2 = ((CompoundTag) tag).getCompound("TileEntityData");
@@ -1351,7 +1350,7 @@ public class ShapeDispatcher
return ((NBTSerializableValue)value).getTag(); return ((NBTSerializableValue)value).getTag();
} }
@Override @Override
public Value decode(Tag tag) { public Value decode(Tag tag, Level level) {
return new NBTSerializableValue(tag); return new NBTSerializableValue(tag);
} }
} }
@@ -1391,7 +1390,7 @@ public class ShapeDispatcher
} }
@Override @Override
public Value decode(Tag tag) public Value decode(Tag tag, Level level)
{ {
return FormattedTextValue.deserialize(tag.getAsString()); return FormattedTextValue.deserialize(tag.getAsString());
} }
@@ -1462,7 +1461,7 @@ public class ShapeDispatcher
} }
@Override @Override
public Value decode(Tag tag) public Value decode(Tag tag, Level level)
{ {
return BooleanValue.of(((ByteTag) tag).getAsByte() > 0); return BooleanValue.of(((ByteTag) tag).getAsByte() > 0);
} }
@@ -1471,7 +1470,7 @@ public class ShapeDispatcher
{ {
protected FloatParam(String id) { super(id); } protected FloatParam(String id) { super(id); }
@Override @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 @Override
public Tag toTag(Value value) { return FloatTag.valueOf(NumericValue.asNumber(value, id).getFloat()); } 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); } protected PositiveFloatParam(String id) { super(id); }
@Override @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 @Override
public Tag toTag(Value value) { return FloatTag.valueOf(NumericValue.asNumber(value, id).getFloat()); } 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); } protected PositiveIntParam(String id) { super(id); }
@Override @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 @Override
public Tag toTag(Value value) { return IntTag.valueOf(NumericValue.asNumber(value, id).getInt()); } 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); } protected NonNegativeIntParam(String id) { super(id); }
@Override @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 @Override
public Tag toTag(Value value) { return IntTag.valueOf(NumericValue.asNumber(value, id).getInt()); } 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) @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); } protected NonNegativeFloatParam(String id) { super(id); }
@Override @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 @Override
public Tag toTag(Value value) { return FloatTag.valueOf(NumericValue.asNumber(value, id).getFloat()); } 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) @Override public Value validate(Map<String, Value> options, MinecraftServer server, Value value)
@@ -1590,7 +1589,7 @@ public class ShapeDispatcher
} }
@Override @Override
public Value decode(Tag tag) public Value decode(Tag tag, Level level)
{ {
ListTag ctag = (ListTag)tag; ListTag ctag = (ListTag)tag;
return ListValue.of( return ListValue.of(
@@ -1629,7 +1628,7 @@ public class ShapeDispatcher
} }
@Override @Override
public Value decode(Tag tag) public Value decode(Tag tag, Level level)
{ {
ListTag ltag = (ListTag)tag; ListTag ltag = (ListTag)tag;
List<Value> points = new ArrayList<>(); List<Value> points = new ArrayList<>();
@@ -1671,7 +1670,7 @@ public class ShapeDispatcher
} }
@Override @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 @Override
public Tag toTag(Value value) { return IntTag.valueOf(NumericValue.asNumber(value, id).getInt()); } public Tag toTag(Value value) { return IntTag.valueOf(NumericValue.asNumber(value, id).getInt()); }
} }
@@ -1698,7 +1697,7 @@ public class ShapeDispatcher
} }
@Override @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) private static boolean isStraight(Vec3 from, Vec3 to, double density)
@@ -164,7 +164,7 @@ public class ShapesRenderer
public void addShape(CompoundTag tag) public void addShape(CompoundTag tag)
{ {
ShapeDispatcher.ExpiringShape shape = ShapeDispatcher.fromTag(tag); ShapeDispatcher.ExpiringShape shape = ShapeDispatcher.fromTag(tag, client.level);
if (shape == null) return; if (shape == null) return;
BiFunction<Minecraft, ShapeDispatcher.ExpiringShape, RenderedShape<? extends ShapeDispatcher.ExpiringShape >> shapeFactory; BiFunction<Minecraft, ShapeDispatcher.ExpiringShape, RenderedShape<? extends ShapeDispatcher.ExpiringShape >> shapeFactory;
shapeFactory = renderedShapes.get(tag.getString("shape")); 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, super(CommandSource.NULL, original.getPosition(), original.getRotation(), original.getLevel(), CarpetSettings.runPermissionLevel,
original.getTextName(), original.getDisplayName(), original.getServer(), original.getEntity(), false, 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.output = CommandSource.NULL;
this.position = original.getPosition(); this.position = original.getPosition();
this.world = original.getLevel(); this.world = original.getLevel();
@@ -87,7 +87,7 @@ public class SnoopyCommandSource extends CommandSourceStack
) { ) {
super(output, pos, rot, world, level, super(output, pos, rot, world, level,
simpleName, name, server, entity, false, simpleName, name, server, entity, false,
consumer, entityAnchor, context, TaskChainer.IMMEDIATE); consumer, entityAnchor, context, TaskChainer.immediate(server));
this.output = output; this.output = output;
this.position = pos; this.position = pos;
this.rotation = rot; this.rotation = rot;
@@ -15,6 +15,7 @@ import carpet.script.value.StringValue;
import carpet.script.value.Value; import carpet.script.value.Value;
import carpet.script.value.ValueConversions; import carpet.script.value.ValueConversions;
import carpet.api.settings.SettingsManager; import carpet.api.settings.SettingsManager;
import com.mojang.bridge.game.PackType;
import com.sun.management.OperatingSystemMXBean; import com.sun.management.OperatingSystemMXBean;
import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.ModContainer; 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_view_distance", c -> new NumericValue(c.s.getServer().getPlayerList().getViewDistance()));
put("game_mod_name", c -> StringValue.of(c.s.getServer().getServerModName())); put("game_mod_name", c -> StringValue.of(c.s.getServer().getServerModName()));
put("game_version", c -> StringValue.of(c.s.getServer().getServerVersion())); 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_protocol", c -> NumericValue.of(SharedConstants.getProtocolVersion()));
put("game_major_target", c -> { 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); return NumericValue.of((vers.length > 1)?Integer.parseInt(vers[1]):0);
}); });
put("game_minor_target", c -> { 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); return NumericValue.of((vers.length > 2)?Integer.parseInt(vers[2]):0);
}); });
put("game_stable", c -> BooleanValue.of(SharedConstants.getCurrentVersion().isStable())); put("game_stable", c -> BooleanValue.of(SharedConstants.getCurrentVersion().isStable()));
put("game_data_version", c->NumericValue.of(SharedConstants.getCurrentVersion().getWorldVersion())); 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_ip", c -> StringValue.of(c.s.getServer().getLocalIp()));
put("server_whitelisted", c -> BooleanValue.of(c.s.getServer().isEnforceWhitelist())); 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.commands.CommandSourceStack;
import net.minecraft.core.RegistryAccess; import net.minecraft.core.RegistryAccess;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.world.flag.FeatureFlags;
import org.apache.logging.log4j.util.TriConsumer; import org.apache.logging.log4j.util.TriConsumer;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
@@ -207,7 +208,7 @@ public class SettingsManager extends carpet.api.settings.SettingsManager
@Deprecated(forRemoval = true) @Deprecated(forRemoval = true)
public void registerCommand(CommandDispatcher<CommandSourceStack> dispatcher) 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); context.missingTagAccessPolicy(CommandBuildContext.MissingTagAccessPolicy.RETURN_EMPTY);
registerCommand(dispatcher, context); registerCommand(dispatcher, context);
} }
+1 -1
View File
@@ -200,7 +200,7 @@
"PlayerTabOverlayMixin", "PlayerTabOverlayMixin",
"PistonHeadRenderer_movableBEMixin", "PistonHeadRenderer_movableBEMixin",
"StructureBlockRenderer_mixin", "StructureBlockRenderer_mixin",
"LocalPlayer_clientCommandMixin", "ClientPacketListener_clientCommandMixin",
"LevelRenderer_fogOffMixin", "LevelRenderer_fogOffMixin",
"LevelRenderer_creativeNoClipMixin", "LevelRenderer_creativeNoClipMixin",
"ClientPacketListener_customPacketsMixin", "ClientPacketListener_customPacketsMixin",