Skip to content

Commit

Permalink
migrate to Decorate
Browse files Browse the repository at this point in the history
  • Loading branch information
sj-hub9796 committed Jan 31, 2025
1 parent d028987 commit bba99c4
Showing 1 changed file with 8 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -1,62 +1,37 @@
package io.izzel.arclight.common.mixin.core.world.level.block.entity;

import io.izzel.arclight.common.mod.server.ArclightServer;
import io.izzel.arclight.mixin.Decorate;
import net.minecraft.core.BlockPos;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.component.DataComponents;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtOps;
import net.minecraft.network.chat.Component;
import net.minecraft.world.level.block.entity.BannerBlockEntity;
import net.minecraft.world.level.block.entity.BannerPatternLayers;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import org.objectweb.asm.Opcodes;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;

import java.util.List;

@Mixin(BannerBlockEntity.class)
public abstract class BannerBlockEntityMixin extends BlockEntity {

@Shadow private BannerPatternLayers patterns;
@Shadow private Component name;

public BannerBlockEntityMixin(BlockEntityType<?> blockEntityType, BlockPos blockPos, BlockState blockState) {
super(blockEntityType, blockPos, blockState);
}

/**
* @author sj-hub9796
* @reason
*/
@Overwrite
protected void loadAdditional(CompoundTag compoundTag, HolderLookup.Provider provider) {
super.loadAdditional(compoundTag, provider);
if (compoundTag.contains("CustomName", 8)) {
this.name = parseCustomNameSafe(compoundTag.getString("CustomName"), provider);
}

if (compoundTag.contains("patterns")) {
BannerPatternLayers.CODEC.parse(provider.createSerializationContext(NbtOps.INSTANCE), compoundTag.get("patterns")).resultOrPartial((string) -> {
ArclightServer.LOGGER.error("Failed to parse banner patterns: '{}'", string);
}).ifPresent((bannerPatternLayers) -> {
this.setPatterns(bannerPatternLayers); // CraftBukkit - apply limits
});
}
@Decorate(method = "method_58121", at = @At(value = "FIELD", target = "Lnet/minecraft/world/level/block/entity/BannerBlockEntity;patterns:Lnet/minecraft/world/level/block/entity/BannerPatternLayers;", opcode = Opcodes.PUTFIELD))
private void arclight$setPatterns(BannerBlockEntity instance, BannerPatternLayers layers) {
this.setPatterns(layers);
}

/**
* @author sj-hub9796
* @reason
*/
@Overwrite
protected void applyImplicitComponents(BlockEntity.DataComponentInput dataComponentInput) {
super.applyImplicitComponents(dataComponentInput);
@Decorate(method = "applyImplicitComponents", inject = true, at = @At(value = "FIELD", target = "Lnet/minecraft/world/level/block/entity/BannerBlockEntity;patterns:Lnet/minecraft/world/level/block/entity/BannerPatternLayers;", opcode = Opcodes.PUTFIELD))
private void arclight$applyLimits(BlockEntity.DataComponentInput dataComponentInput) {
this.setPatterns((BannerPatternLayers) dataComponentInput.getOrDefault(DataComponents.BANNER_PATTERNS, BannerPatternLayers.EMPTY)); // CraftBukkit - apply limits
this.name = (Component)dataComponentInput.get(DataComponents.CUSTOM_NAME);
}

// CraftBukkit start
Expand Down

0 comments on commit bba99c4

Please sign in to comment.