From 2818806cf65c8776415d9981d30e477b4fd261b3 Mon Sep 17 00:00:00 2001 From: aromaa Date: Fri, 13 Oct 2023 02:59:27 +0300 Subject: [PATCH] Add Audience to CommandBlocks --- SpongeAPI | 2 +- .../MinecartCommandBlockMixin_API.java | 4 +- .../entity/CommandBlockEntityMixin_API.java | 9 ++++ ...eMixin.java => BaseCommandBlockMixin.java} | 19 ++++++-- .../entity/CommandBlockEntity_Mixin.java | 43 ------------------- src/mixins/resources/mixins.sponge.core.json | 3 +- 6 files changed, 28 insertions(+), 52 deletions(-) rename src/mixins/java/org/spongepowered/common/mixin/core/world/{entity/vehicle/MinecartCommandBlock_MinecartCommandBaseMixin.java => BaseCommandBlockMixin.java} (67%) delete mode 100644 src/mixins/java/org/spongepowered/common/mixin/core/world/level/block/entity/CommandBlockEntity_Mixin.java diff --git a/SpongeAPI b/SpongeAPI index 46c93012877..35b45d85a1a 160000 --- a/SpongeAPI +++ b/SpongeAPI @@ -1 +1 @@ -Subproject commit 46c93012877a8891bf7b2d3a2a0088766ddebade +Subproject commit 35b45d85a1a1d0d51af7fb9f636d161de5a7085f diff --git a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/entity/vehicle/MinecartCommandBlockMixin_API.java b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/entity/vehicle/MinecartCommandBlockMixin_API.java index d570a2ec8cb..a53afd2da02 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/entity/vehicle/MinecartCommandBlockMixin_API.java +++ b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/entity/vehicle/MinecartCommandBlockMixin_API.java @@ -38,12 +38,12 @@ public abstract class MinecartCommandBlockMixin_API extends AbstractMinecartMixin_API implements CommandBlockMinecart { // @formatter:off - @Shadow public abstract BaseCommandBlock getCommandBlock(); + @Shadow public abstract BaseCommandBlock shadow$getCommandBlock(); // @formatter:on @Override public String identifier() { - return this.getCommandBlock().getName().getString(); + return this.shadow$getCommandBlock().getName().getString(); } @Override diff --git a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/level/block/entity/CommandBlockEntityMixin_API.java b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/level/block/entity/CommandBlockEntityMixin_API.java index b5e3c4becc5..119aece2369 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/level/block/entity/CommandBlockEntityMixin_API.java +++ b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/level/block/entity/CommandBlockEntityMixin_API.java @@ -24,9 +24,13 @@ */ package org.spongepowered.common.mixin.api.minecraft.world.level.block.entity; +import net.kyori.adventure.audience.MessageType; +import net.kyori.adventure.identity.Identity; +import net.kyori.adventure.text.Component; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import net.minecraft.world.level.BaseCommandBlock; import net.minecraft.world.level.block.entity.CommandBlockEntity; +import org.checkerframework.checker.nullness.qual.NonNull; import org.spongepowered.api.block.entity.CommandBlock; import org.spongepowered.api.data.persistence.DataContainer; import org.spongepowered.api.data.value.Value; @@ -84,4 +88,9 @@ public DataContainer toContainer() { public String identifier() { return this.shadow$getCommandBlock().getName().getString(); } + + @Override + public void sendMessage(final @NonNull Identity identity, final @NonNull Component message, final @NonNull MessageType type) { + this.shadow$getCommandBlock().sendSystemMessage(SpongeAdventure.asVanilla(message)); + } } diff --git a/src/mixins/java/org/spongepowered/common/mixin/core/world/entity/vehicle/MinecartCommandBlock_MinecartCommandBaseMixin.java b/src/mixins/java/org/spongepowered/common/mixin/core/world/BaseCommandBlockMixin.java similarity index 67% rename from src/mixins/java/org/spongepowered/common/mixin/core/world/entity/vehicle/MinecartCommandBlock_MinecartCommandBaseMixin.java rename to src/mixins/java/org/spongepowered/common/mixin/core/world/BaseCommandBlockMixin.java index 2d399b32d19..da95a861ee5 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/core/world/entity/vehicle/MinecartCommandBlock_MinecartCommandBaseMixin.java +++ b/src/mixins/java/org/spongepowered/common/mixin/core/world/BaseCommandBlockMixin.java @@ -22,20 +22,27 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.common.mixin.core.world.entity.vehicle; +package org.spongepowered.common.mixin.core.world; +import net.kyori.adventure.audience.Audience; +import net.kyori.adventure.audience.MessageType; +import net.kyori.adventure.identity.Identity; +import net.kyori.adventure.text.Component; import net.minecraft.commands.CommandSourceStack; -import net.minecraft.world.entity.vehicle.MinecartCommandBlock; +import net.minecraft.world.level.BaseCommandBlock; +import org.checkerframework.checker.nullness.qual.NonNull; import org.spongepowered.api.event.Cause; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.common.adventure.SpongeAdventure; import org.spongepowered.common.bridge.commands.CommandSourceProviderBridge; -@Mixin(MinecartCommandBlock.MinecartCommandBase.class) -public abstract class MinecartCommandBlock_MinecartCommandBaseMixin implements CommandSourceProviderBridge { +@Mixin(BaseCommandBlock.class) +public abstract class BaseCommandBlockMixin implements CommandSourceProviderBridge, Audience { // @formatter:off @Shadow public abstract CommandSourceStack shadow$createCommandSourceStack(); + @Shadow public abstract void shadow$sendSystemMessage(net.minecraft.network.chat.Component $$0); // @formatter:on @Override @@ -43,4 +50,8 @@ public abstract class MinecartCommandBlock_MinecartCommandBaseMixin implements C return this.shadow$createCommandSourceStack(); } + @Override + public void sendMessage(final @NonNull Identity identity, final @NonNull Component message, final @NonNull MessageType type) { + this.shadow$sendSystemMessage(SpongeAdventure.asVanilla(message)); + } } diff --git a/src/mixins/java/org/spongepowered/common/mixin/core/world/level/block/entity/CommandBlockEntity_Mixin.java b/src/mixins/java/org/spongepowered/common/mixin/core/world/level/block/entity/CommandBlockEntity_Mixin.java deleted file mode 100644 index 9b0bab09eb0..00000000000 --- a/src/mixins/java/org/spongepowered/common/mixin/core/world/level/block/entity/CommandBlockEntity_Mixin.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * This file is part of Sponge, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package org.spongepowered.common.mixin.core.world.level.block.entity; - -import net.minecraft.commands.CommandSourceStack; -import org.spongepowered.api.event.Cause; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.common.bridge.commands.CommandSourceProviderBridge; - -@Mixin(targets = "net.minecraft.world.level.block.entity.CommandBlockEntity$1") -public abstract class CommandBlockEntity_Mixin implements CommandSourceProviderBridge { - - @Shadow public abstract CommandSourceStack shadow$createCommandSourceStack(); - - @Override - public CommandSourceStack bridge$getCommandSource(final Cause cause) { - return this.shadow$createCommandSourceStack(); - } - -} diff --git a/src/mixins/resources/mixins.sponge.core.json b/src/mixins/resources/mixins.sponge.core.json index c17594bd9ed..42ac1dd5c52 100644 --- a/src/mixins/resources/mixins.sponge.core.json +++ b/src/mixins/resources/mixins.sponge.core.json @@ -90,6 +90,7 @@ "service.permission.SubjectMixin", "util.ClassInstanceMultiMapMixin", "util.datafix.schemas.V1125Mixin", + "world.BaseCommandBlockMixin", "world.BossEventMixin", "world.damagesource.DamageSourceMixin", "world.entity.ActiveChunkReferentMixin", @@ -158,7 +159,6 @@ "world.entity.vehicle.AbstractMinecartContainerMixin", "world.entity.vehicle.AbstractMinecartMixin", "world.entity.vehicle.BoatMixin", - "world.entity.vehicle.MinecartCommandBlock_MinecartCommandBaseMixin", "world.entity.vehicle.MinecartCommandBlockMixin", "world.entity.vehicle.MinecartFurnaceMixin", "world.entity.vehicle.MinecartTNTMixin", @@ -199,7 +199,6 @@ "world.level.block.entity.BlockEntityMixin", "world.level.block.entity.BrewingStandBlockEntityMixin", "world.level.block.entity.CampfireBlockEntityMixin", - "world.level.block.entity.CommandBlockEntity_Mixin", "world.level.block.entity.CommandBlockEntityMixin", "world.level.block.entity.EnchantmentTableBlockEntityMixin", "world.level.block.entity.LecternBlockEntityMixin",