-
-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4e387fc
commit d028987
Showing
2 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
.../io/izzel/arclight/common/mixin/core/world/level/block/entity/BannerBlockEntityMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package io.izzel.arclight.common.mixin.core.world.level.block.entity; | ||
|
||
import io.izzel.arclight.common.mod.server.ArclightServer; | ||
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.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Overwrite; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
|
||
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 | ||
}); | ||
} | ||
} | ||
|
||
/** | ||
* @author sj-hub9796 | ||
* @reason | ||
*/ | ||
@Overwrite | ||
protected void applyImplicitComponents(BlockEntity.DataComponentInput dataComponentInput) { | ||
super.applyImplicitComponents(dataComponentInput); | ||
this.setPatterns((BannerPatternLayers) dataComponentInput.getOrDefault(DataComponents.BANNER_PATTERNS, BannerPatternLayers.EMPTY)); // CraftBukkit - apply limits | ||
this.name = (Component)dataComponentInput.get(DataComponents.CUSTOM_NAME); | ||
} | ||
|
||
// CraftBukkit start | ||
public void setPatterns(BannerPatternLayers bannerpatternlayers) { | ||
if (bannerpatternlayers.layers().size() > 20) { | ||
bannerpatternlayers = new BannerPatternLayers(List.copyOf(bannerpatternlayers.layers().subList(0, 20))); | ||
} | ||
this.patterns = bannerpatternlayers; | ||
} | ||
// CraftBukkit end | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters