diff --git a/build.gradle b/build.gradle index 83c4f837..bb46a7a2 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ 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 'maven-publish' } diff --git a/docs/scarpet/api/Inventories.md b/docs/scarpet/api/Inventories.md index fc8a93ee..d8c66e31 100644 --- a/docs/scarpet/api/Inventories.md +++ b/docs/scarpet/api/Inventories.md @@ -53,18 +53,6 @@ stack_limit('ender_pearl') => 16 stack_limit('stone') => 64 -### `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. - -
-item_category('wooden_axe') => tools
-item_category('ender_pearl') => misc
-item_category('stone') => building_blocks
-
- ### `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 diff --git a/docs/scarpet/resources/editors/idea/2.txt b/docs/scarpet/resources/editors/idea/2.txt index 3d7c5b4c..d90729fd 100644 --- a/docs/scarpet/resources/editors/idea/2.txt +++ b/docs/scarpet/resources/editors/idea/2.txt @@ -56,7 +56,6 @@ inventory_get inventory_remove inventory_set inventory_size -item_category item_display_name item_list item_tags diff --git a/docs/scarpet/resources/editors/npp/scarpet.xml b/docs/scarpet/resources/editors/npp/scarpet.xml index 951afa03..7ff2ef02 100644 --- a/docs/scarpet/resources/editors/npp/scarpet.xml +++ b/docs/scarpet/resources/editors/npp/scarpet.xml @@ -77,7 +77,7 @@ 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 diff --git a/gradle.properties b/gradle.properties index 0f313deb..67cef601 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,9 +4,9 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/use # or better: https://modmuss50.me/fabric.html - minecraft_version=1.19.2 - loader_version=0.14.9 - fabric_version=0.58.6+1.19.2 + minecraft_version=22w42a + loader_version=0.14.10 + fabric_version=0.58.0+1.19 # Mod Properties mod_version = 1.4.84 diff --git a/src/main/java/carpet/CarpetSettings.java b/src/main/java/carpet/CarpetSettings.java index 8b04d9cc..a8d7cfc0 100644 --- a/src/main/java/carpet/CarpetSettings.java +++ b/src/main/java/carpet/CarpetSettings.java @@ -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 skipGenerationChecks = ThreadLocal.withInitial(() -> false); public static final ThreadLocal impendingFillSkipUpdates = ThreadLocal.withInitial(() -> false); diff --git a/src/main/java/carpet/commands/MobAICommand.java b/src/main/java/carpet/commands/MobAICommand.java index 6ace00d7..5c4324c9 100644 --- a/src/main/java/carpet/commands/MobAICommand.java +++ b/src/main/java/carpet/commands/MobAICommand.java @@ -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 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; diff --git a/src/main/java/carpet/commands/PerimeterInfoCommand.java b/src/main/java/carpet/commands/PerimeterInfoCommand.java index 41da36fb..6cd3eab3 100644 --- a/src/main/java/carpet/commands/PerimeterInfoCommand.java +++ b/src/main/java/carpet/commands/PerimeterInfoCommand.java @@ -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; } diff --git a/src/main/java/carpet/helpers/ParticleDisplay.java b/src/main/java/carpet/helpers/ParticleDisplay.java index 233c3a08..3be78b7b 100644 --- a/src/main/java/carpet/helpers/ParticleDisplay.java +++ b/src/main/java/carpet/helpers/ParticleDisplay.java @@ -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) { diff --git a/src/main/java/carpet/mixins/LocalPlayer_clientCommandMixin.java b/src/main/java/carpet/mixins/ClientPacketListener_clientCommandMixin.java similarity index 65% rename from src/main/java/carpet/mixins/LocalPlayer_clientCommandMixin.java rename to src/main/java/carpet/mixins/ClientPacketListener_clientCommandMixin.java index 446fb81e..2b98456b 100644 --- a/src/main/java/carpet/mixins/LocalPlayer_clientCommandMixin.java +++ b/src/main/java/carpet/mixins/ClientPacketListener_clientCommandMixin.java @@ -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(); diff --git a/src/main/java/carpet/mixins/ServerPlayer_actionPackMixin.java b/src/main/java/carpet/mixins/ServerPlayer_actionPackMixin.java index 880212c2..07c008fd 100644 --- a/src/main/java/carpet/mixins/ServerPlayer_actionPackMixin.java +++ b/src/main/java/carpet/mixins/ServerPlayer_actionPackMixin.java @@ -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 = "", 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); } diff --git a/src/main/java/carpet/mixins/ServerPlayer_scarpetEventMixin.java b/src/main/java/carpet/mixins/ServerPlayer_scarpetEventMixin.java index 57f38680..ac66c14e 100644 --- a/src/main/java/carpet/mixins/ServerPlayer_scarpetEventMixin.java +++ b/src/main/java/carpet/mixins/ServerPlayer_scarpetEventMixin.java @@ -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(); diff --git a/src/main/java/carpet/patches/EntityPlayerMPFake.java b/src/main/java/carpet/patches/EntityPlayerMPFake.java index 05428cac..0e89a665 100644 --- a/src/main/java/carpet/patches/EntityPlayerMPFake.java +++ b/src/main/java/carpet/patches/EntityPlayerMPFake.java @@ -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; } diff --git a/src/main/java/carpet/script/api/Auxiliary.java b/src/main/java/carpet/script/api/Auxiliary.java index 39a789ee..570c996d 100644 --- a/src/main/java/carpet/script/api/Auxiliary.java +++ b/src/main/java/carpet/script/api/Auxiliary.java @@ -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") ))) diff --git a/src/main/java/carpet/script/api/Inventories.java b/src/main/java/carpet/script/api/Inventories.java index b4dd3b35..c64e00c6 100644 --- a/src/main/java/carpet/script/api/Inventories.java +++ b/src/main/java/carpet/script/api/Inventories.java @@ -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) -> diff --git a/src/main/java/carpet/script/command/CommandArgument.java b/src/main/java/carpet/script/command/CommandArgument.java index 3582c2d4..c17ad044 100644 --- a/src/main/java/carpet/script/command/CommandArgument.java +++ b/src/main/java/carpet/script/command/CommandArgument.java @@ -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 result = ResourceOrTagLocationArgument.getRegistryType(c, "biome", Registry.BIOME_REGISTRY, ERROR_BIOME_INVALID); - Either, TagKey> res = result.unwrap(); + ResourceOrTagArgument.Result result = ResourceOrTagArgument.getResourceOrTag(c, "biome", Registry.BIOME_REGISTRY); + Either, HolderSet.Named> 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 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 examples; protected boolean needsMatching; protected boolean caseSensitive = true; - protected SuggestionProvider suggestionProvider; + protected Function> 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 factory(); + protected abstract Supplier factory(MinecraftServer server); private static class StringArgument extends CommandArgument { @@ -489,7 +488,7 @@ public abstract class CommandArgument } @Override - protected Supplier factory() { return StringArgument::new; } + protected Supplier 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 factory() { return WordArgument::new; } + protected Supplier 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 factory() { return GreedyStringArgument::new; } + protected Supplier factory(MinecraftServer server) { return GreedyStringArgument::new; } } private static class BlockPosArgument extends CommandArgument @@ -542,7 +541,7 @@ public abstract class CommandArgument } @Override - protected Supplier factory() + protected Supplier factory(MinecraftServer server) { return BlockPosArgument::new; } @@ -577,7 +576,7 @@ public abstract class CommandArgument } @Override - protected Supplier factory() + protected Supplier factory(MinecraftServer server) { return LocationArgument::new; } @@ -626,7 +625,7 @@ public abstract class CommandArgument } @Override - protected Supplier factory() + protected Supplier factory(MinecraftServer server) { return EntityArgument::new; } @@ -666,7 +665,7 @@ public abstract class CommandArgument } @Override - protected Supplier factory() + protected Supplier 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 factory() + protected Supplier factory(MinecraftServer server) { return PlayerProfileArgument::new; } @@ -744,7 +743,7 @@ public abstract class CommandArgument } @Override - protected Supplier factory() + protected Supplier factory(MinecraftServer server) { return TagArgument::new; } @@ -777,7 +776,7 @@ public abstract class CommandArgument } @Override - protected Supplier factory() + protected Supplier factory(MinecraftServer server) { return CustomIdentifierArgument::new; } @@ -840,7 +839,7 @@ public abstract class CommandArgument } @Override - protected Supplier factory() + protected Supplier factory(MinecraftServer server) { return FloatArgument::new; } @@ -891,7 +890,7 @@ public abstract class CommandArgument } @Override - protected Supplier factory() + protected Supplier factory(MinecraftServer server) { return IntArgument::new; } @@ -986,7 +985,7 @@ public abstract class CommandArgument } @Override - protected Supplier factory() + protected Supplier 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 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> suggesterGen + ) + { + super(suffix, Collections.emptyList(), false); + this.suggestionProvider = suggesterGen; + this.providesExamples = false; + this.argumentTypeSupplierEx = argumentTypeSupplier; + this.valueExtractor = valueExtractor; + this.argumentTypeSupplier = null; + } + + public VanillaUnconfigurableArgument( + String suffix, + ResourceKey> 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 factory() + protected Supplier 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); } } } diff --git a/src/main/java/carpet/script/utils/Experimental.java b/src/main/java/carpet/script/utils/Experimental.java index fbd185f1..b8ab2e79 100644 --- a/src/main/java/carpet/script/utils/Experimental.java +++ b/src/main/java/carpet/script/utils/Experimental.java @@ -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); } + + */ } diff --git a/src/main/java/carpet/script/utils/ShapeDispatcher.java b/src/main/java/carpet/script/utils/ShapeDispatcher.java index 33770b45..51ee8ec9 100644 --- a/src/main/java/carpet/script/utils/ShapeDispatcher.java +++ b/src/main/java/carpet/script/utils/ShapeDispatcher.java @@ -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 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 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 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 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 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) diff --git a/src/main/java/carpet/script/utils/ShapesRenderer.java b/src/main/java/carpet/script/utils/ShapesRenderer.java index 463cdbfc..4b06c04b 100644 --- a/src/main/java/carpet/script/utils/ShapesRenderer.java +++ b/src/main/java/carpet/script/utils/ShapesRenderer.java @@ -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> shapeFactory; shapeFactory = renderedShapes.get(tag.getString("shape")); diff --git a/src/main/java/carpet/script/utils/SnoopyCommandSource.java b/src/main/java/carpet/script/utils/SnoopyCommandSource.java index 685c60c0..9e770984 100644 --- a/src/main/java/carpet/script/utils/SnoopyCommandSource.java +++ b/src/main/java/carpet/script/utils/SnoopyCommandSource.java @@ -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; diff --git a/src/main/java/carpet/script/utils/SystemInfo.java b/src/main/java/carpet/script/utils/SystemInfo.java index 2a0b782e..abe60e15 100644 --- a/src/main/java/carpet/script/utils/SystemInfo.java +++ b/src/main/java/carpet/script/utils/SystemInfo.java @@ -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())); diff --git a/src/main/java/carpet/settings/SettingsManager.java b/src/main/java/carpet/settings/SettingsManager.java index b18eb5bc..a6f788a9 100644 --- a/src/main/java/carpet/settings/SettingsManager.java +++ b/src/main/java/carpet/settings/SettingsManager.java @@ -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 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); } diff --git a/src/main/resources/carpet.mixins.json b/src/main/resources/carpet.mixins.json index 2ab99cc4..22c3a030 100644 --- a/src/main/resources/carpet.mixins.json +++ b/src/main/resources/carpet.mixins.json @@ -200,7 +200,7 @@ "PlayerTabOverlayMixin", "PistonHeadRenderer_movableBEMixin", "StructureBlockRenderer_mixin", - "LocalPlayer_clientCommandMixin", + "ClientPacketListener_clientCommandMixin", "LevelRenderer_fogOffMixin", "LevelRenderer_creativeNoClipMixin", "ClientPacketListener_customPacketsMixin",