Skip to content

Commit a861809

Browse files
committed
Don't add glowing layer component if empty
1 parent 2931393 commit a861809

File tree

3 files changed

+9
-14
lines changed

3 files changed

+9
-14
lines changed

src/main/java/dev/trigam/field/impl/FieldBannerBlockEntity.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ public interface FieldBannerBlockEntity {
88

99
void field$setLayerGlowing( int layerIndex, boolean glowing );
1010

11+
boolean field$isEmpty ();
12+
1113
}

src/main/java/dev/trigam/field/item/ModifyItemInit.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
package dev.trigam.field.item;
22

3-
import dev.trigam.field.component.GlowingLayersComponent;
4-
import dev.trigam.field.component.ItemComponentInit;
53
import dev.trigam.field.config.FieldConfig;
64
import net.fabricmc.fabric.api.item.v1.DefaultItemComponentEvents;
75
import net.minecraft.component.DataComponentTypes;
86
import net.minecraft.component.type.EquippableComponent;
97
import net.minecraft.entity.EquipmentSlot;
108
import net.minecraft.item.Item;
119
import net.minecraft.item.Items;
12-
1310
import java.util.Arrays;
1411
import java.util.List;
1512

@@ -47,15 +44,6 @@ public static void init() {
4744
);
4845
}
4946
}
50-
// Glowing Banners
51-
for ( Item banner : BANNERS ) {
52-
context.modify( banner, builder ->
53-
builder.add(
54-
ItemComponentInit.GLOWING_LAYERS,
55-
GlowingLayersComponent.DEFAULT
56-
)
57-
);
58-
}
5947
});
6048
}
6149
}

src/main/java/dev/trigam/field/mixin/component/BannerEntityComponents.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ public BannerEntityComponents( BlockEntityType<?> type, BlockPos pos, BlockState
3939
this.glowingLayers.setLayerGlowing( layerIndex, glowing );
4040
}
4141

42+
@Override
43+
public boolean field$isEmpty () {
44+
return this.glowingLayers.glowingLayers.isEmpty();
45+
}
46+
4247
@Inject(
4348
method = "readComponents",
4449
at = @At( value = "TAIL" )
@@ -52,7 +57,7 @@ private void readComponents( BlockEntity.ComponentsAccess components, CallbackIn
5257
at = @At( value = "TAIL" )
5358
)
5459
private void addComponents( ComponentMap.Builder builder, CallbackInfo ci ) {
55-
builder.add( ItemComponentInit.GLOWING_LAYERS, this.glowingLayers );
60+
if ( !this.field$isEmpty() ) builder.add( ItemComponentInit.GLOWING_LAYERS, this.glowingLayers );
5661
}
5762

5863
@Inject(
@@ -77,7 +82,7 @@ private void readNbt( NbtCompound nbt, RegistryWrapper.WrapperLookup registries,
7782
at = @At( value = "TAIL" )
7883
)
7984
private void writeNbt( NbtCompound nbt, RegistryWrapper.WrapperLookup registries, CallbackInfo ci ) {
80-
if ( this.glowingLayers != null ) {
85+
if ( this.glowingLayers != null && !this.field$isEmpty() ) {
8186
nbt.put( "glowing_layers",
8287
GlowingLayersComponent.CODEC.encodeStart(
8388
registries.getOps( NbtOps.INSTANCE ),

0 commit comments

Comments
 (0)