Skip to content

Commit

Permalink
Add Audience to CommandBlocks
Browse files Browse the repository at this point in the history
  • Loading branch information
aromaa committed Oct 12, 2023
1 parent d0210fc commit 2818806
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,36 @@
* 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
public CommandSourceStack bridge$getCommandSource(final Cause cause) {
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));
}
}

This file was deleted.

3 changes: 1 addition & 2 deletions src/mixins/resources/mixins.sponge.core.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"service.permission.SubjectMixin",
"util.ClassInstanceMultiMapMixin",
"util.datafix.schemas.V1125Mixin",
"world.BaseCommandBlockMixin",
"world.BossEventMixin",
"world.damagesource.DamageSourceMixin",
"world.entity.ActiveChunkReferentMixin",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 2818806

Please sign in to comment.