Skip to content

Commit 8d862f3

Browse files
committed
modmenu icon impl, fix migrate, don't save shardsets or source, scroll speed 1
1 parent 34f90b1 commit 8d862f3

File tree

12 files changed

+122
-76
lines changed

12 files changed

+122
-76
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ authors=Falkreon, acikek
1717
contributors=Trudle, Tomate0613, afamiliarquiet, FoundationGames, TheEpicBlock, hama
1818
license=MIT
1919
# Mod Version
20-
baseVersion=1.7.0
20+
baseVersion=1.7.1
2121
# Branch Metadata
2222
branch=1.21
2323
tagBranch=1.21

libs.versions.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
loom = "1.7.+"
33
minotaur = "2.+"
44

5-
mc = "1.21"
6-
fl = "0.15.11"
7-
yarn = "1.21+build.9"
8-
fapi = "0.100.7+1.21"
5+
mc = "1.21.1"
6+
fl = "0.16.7"
7+
yarn = "1.21.1+build.3"
8+
fapi = "0.104.0+1.21.1"
99

1010
fpapi = "0.3.1"
1111
libgui = "11.0.0+1.21"

src/main/java/net/modfest/scatteredshards/api/impl/ShardLibraryPersistentState.java

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package net.modfest.scatteredshards.api.impl;
22

33
import net.minecraft.nbt.NbtCompound;
4-
import net.minecraft.nbt.NbtElement;
5-
import net.minecraft.nbt.NbtList;
6-
import net.minecraft.nbt.NbtString;
74
import net.minecraft.registry.RegistryWrapper;
85
import net.minecraft.server.MinecraftServer;
96
import net.minecraft.util.Identifier;
@@ -21,7 +18,6 @@ public class ShardLibraryPersistentState extends PersistentState {
2118
);
2219

2320
public static final String SHARDS_KEY = "Shards";
24-
public static final String SHARD_SETS_KEY = "ShardSets";
2521

2622
public static ShardLibraryPersistentState get(MinecraftServer server) {
2723
return server.getOverworld().getPersistentStateManager().getOrCreate(TYPE, ScatteredShards.ID + "_library");
@@ -53,21 +49,6 @@ public static ShardLibraryPersistentState createFromNbt(NbtCompound tag, Registr
5349
}
5450
}
5551

56-
NbtCompound shardSets = tag.getCompound(SHARD_SETS_KEY);
57-
for (String id : shardSets.getKeys()) {
58-
try {
59-
Identifier setId = Identifier.of(id);
60-
NbtList ids = shardSets.getList(id, NbtElement.STRING_TYPE);
61-
for (NbtElement elem : ids) {
62-
if (elem instanceof NbtString str) {
63-
library.shardSets().put(setId, Identifier.of(str.asString()));
64-
}
65-
}
66-
} catch (Throwable t) {
67-
ScatteredShards.LOGGER.error("Could not load shardSet \"{}\": {}", id, t.getMessage());
68-
}
69-
}
70-
7152
ScatteredShards.LOGGER.info("Loaded {} shards and {} shardSets.", library.shards().size(), library.shardSets().size());
7253

7354
return state;
@@ -80,18 +61,8 @@ public NbtCompound writeNbt(NbtCompound tag, RegistryWrapper.WrapperLookup regis
8061

8162
tag.put(SHARDS_KEY, library.shards().toNbt());
8263

83-
NbtCompound shardSets = new NbtCompound();
84-
library.shardSets().asMap().forEach((id, set) -> {
85-
NbtList list = new NbtList();
86-
for (Identifier i : set) {
87-
list.add(NbtString.of(i.toString()));
88-
}
89-
shardSets.put(id.toString(), list);
90-
});
91-
tag.put(SHARD_SETS_KEY, shardSets);
92-
9364
ScatteredShards.LOGGER.info("ShardLibrary saved.");
9465

9566
return tag;
9667
}
97-
}
68+
}

src/main/java/net/modfest/scatteredshards/api/shard/Shard.java

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ public class Shard {
3030
TextCodecs.CODEC.fieldOf("name").forGetter(Shard::name),
3131
TextCodecs.CODEC.fieldOf("lore").forGetter(Shard::lore),
3232
TextCodecs.CODEC.fieldOf("hint").forGetter(Shard::hint),
33-
TextCodecs.CODEC.fieldOf("source").forGetter(Shard::source),
3433
Identifier.CODEC.fieldOf("source_id").forGetter(Shard::sourceId),
3534
ICON_CODEC.fieldOf("icon").forGetter(Shard::icon)
3635
).apply(instance, Shard::new));
@@ -40,23 +39,21 @@ public class Shard {
4039
public static final Identifier MISSING_ICON_ID = ScatteredShards.id("textures/gui/shards/missing_icon.png");
4140
public static final Either<ItemStack, Identifier> MISSING_ICON = Either.right(MISSING_ICON_ID);
4241
public static final Identifier MISSING_SHARD_SOURCE = ScatteredShards.id("missing");
43-
public static final Shard MISSING_SHARD = new Shard(ShardType.MISSING_ID, Text.of("Missing"), Text.of(""), Text.of(""), Text.of("None"), MISSING_SHARD_SOURCE, MISSING_ICON);
42+
public static final Shard MISSING_SHARD = new Shard(ShardType.MISSING_ID, Text.of("Missing"), Text.of(""), Text.of(""), MISSING_SHARD_SOURCE, MISSING_ICON);
4443

4544
protected Identifier shardTypeId;
4645
protected Text name;
4746
protected Text lore;
4847
protected Text hint;
49-
protected Text source;
5048
protected Identifier sourceId;
5149
protected Either<ItemStack, Identifier> icon;
5250

53-
public Shard(Identifier shardTypeId, Text name, Text lore, Text hint, Text source, Identifier sourceId, Either<ItemStack, Identifier> icon) {
54-
Stream.of(name, lore, hint, source, icon).forEach(Objects::requireNonNull);
51+
public Shard(Identifier shardTypeId, Text name, Text lore, Text hint, Identifier sourceId, Either<ItemStack, Identifier> icon) {
52+
Stream.of(name, lore, hint, icon).forEach(Objects::requireNonNull);
5553
this.shardTypeId = shardTypeId;
5654
this.name = name;
5755
this.lore = lore;
5856
this.hint = hint;
59-
this.source = source;
6057
this.sourceId = sourceId;
6158
this.icon = icon;
6259
}
@@ -77,10 +74,6 @@ public Text hint() {
7774
return hint;
7875
}
7976

80-
public Text source() {
81-
return source;
82-
}
83-
8477
public Identifier sourceId() {
8578
return sourceId;
8679
}
@@ -124,11 +117,6 @@ public Shard setIcon(Identifier textureValue) {
124117
return this;
125118
}
126119

127-
public Shard setSource(Text source) {
128-
this.source = source;
129-
return this;
130-
}
131-
132120
public Shard setSourceId(Identifier id) {
133121
this.sourceId = id;
134122
return this;
@@ -148,7 +136,7 @@ public JsonObject toJson() {
148136

149137
public Shard copy() {
150138
Either<ItemStack, Identifier> icon = icon().mapBoth(stack -> stack, id -> id);
151-
return new Shard(shardTypeId, name.copy(), lore.copy(), hint.copy(), source.copy(), sourceId, icon);
139+
return new Shard(shardTypeId, name.copy(), lore.copy(), hint.copy(), sourceId, icon);
152140
}
153141

154142
@Override
@@ -157,11 +145,7 @@ public String toString() {
157145
}
158146

159147
public static Shard emptyOfType(Identifier id) {
160-
return MISSING_SHARD.copy().setShardType(id);
161-
}
162-
163-
public static Text getSourceForNamespace(String namespace) {
164-
return Text.translatable("shard_pack." + namespace + ".name");
148+
return MISSING_SHARD.copy().setShardType(id).setName(Text.of(""));
165149
}
166150

167151
public static Text getSourceForMod(ModContainer mod) {
@@ -180,8 +164,4 @@ public static Text getSourceForSourceId(Identifier id) {
180164
return getSourceForModId(id.getNamespace())
181165
.orElse(Text.translatable("shard_pack." + id.getNamespace() + ".name"));
182166
}
183-
184-
public static Identifier getSourceIdForNamespace(String namespace) {
185-
return Identifier.of(namespace, "shard_pack");
186-
}
187167
}

src/main/java/net/modfest/scatteredshards/client/render/ShardBlockEntityRenderer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import net.modfest.scatteredshards.api.shard.Shard;
1919
import net.modfest.scatteredshards.api.shard.ShardType;
2020
import net.modfest.scatteredshards.block.ShardBlockEntity;
21+
import net.modfest.scatteredshards.util.ModMetaUtil;
2122
import org.joml.AxisAngle4f;
2223
import org.joml.Quaternionf;
2324
import org.joml.Vector3f;
@@ -43,6 +44,7 @@ public void render(ShardBlockEntity entity, float tickDelta, MatrixStack matrice
4344
shard = Shard.MISSING_SHARD;
4445
}
4546

47+
shard.icon().ifRight(ModMetaUtil::touchIconTexture);
4648
ShardType shardType = ScatteredShardsAPI.getClientLibrary().shardTypes().get(shard.shardTypeId()).orElse(ShardType.MISSING);
4749

4850
float angle = entity.getAnimations().getAngle(tickDelta);

src/main/java/net/modfest/scatteredshards/client/screen/ShardCreatorGuiDescription.java

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import io.github.cottonmc.cotton.gui.widget.data.HorizontalAlignment;
1616
import io.github.cottonmc.cotton.gui.widget.data.Insets;
1717
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
18-
import net.fabricmc.loader.api.FabricLoader;
1918
import net.minecraft.client.MinecraftClient;
2019
import net.minecraft.component.ComponentChanges;
2120
import net.minecraft.component.ComponentMap;
@@ -32,6 +31,7 @@
3231
import net.modfest.scatteredshards.client.screen.widget.WProtectableField;
3332
import net.modfest.scatteredshards.client.screen.widget.WShardPanel;
3433
import net.modfest.scatteredshards.networking.C2SModifyShard;
34+
import net.modfest.scatteredshards.util.ModMetaUtil;
3535

3636
import java.util.Objects;
3737

@@ -163,19 +163,7 @@ public ShardCreatorGuiDescription(Identifier shardId, Shard shard, String modId)
163163
this(shardId);
164164
this.shard = shard;
165165

166-
this.modIcon = FabricLoader.getInstance().getModContainer(modId)
167-
.flatMap(it -> it.getMetadata().getIconPath(16))
168-
.filter(it -> it.startsWith("assets/"))
169-
.map(it -> it.substring("assets/".length()))
170-
.map(it -> {
171-
int firstSlash = it.indexOf("/");
172-
String namespace = it.substring(0, firstSlash);
173-
String path = it.substring(firstSlash + 1);
174-
175-
return Identifier.of(namespace, path);
176-
})
177-
.orElse(Shard.MISSING_ICON.right().get()); //TODO: Deal with non-resource icons here.
178-
Shard.getSourceForModId(modId).ifPresent(shard::setSource);
166+
this.modIcon = ModMetaUtil.touchModIcon(modId);
179167
shard.setSourceId(Identifier.of(modId, "shard_pack"));
180168

181169
// Initialize field values

src/main/java/net/modfest/scatteredshards/client/screen/ShardTabletGuiDescription.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public ShardTabletGuiDescription(ShardCollection collection, ShardLibrary librar
4646
ids.sort(Comparator.comparing(Identifier::getNamespace));
4747

4848
shardSelector = new WListPanel<>(ids, WShardSetPanel::new, this::configurePanel);
49+
shardSelector.getScrollBar().setScrollingSpeed(1);
4950
selectorPanel.setInsets(Insets.ROOT_PANEL);
5051

5152
WLeftRightPanel root = new WLeftRightPanel(selectorPanel, shardPanel);

src/main/java/net/modfest/scatteredshards/client/screen/widget/WMiniShard.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import net.modfest.scatteredshards.api.shard.ShardIconOffsets;
1818
import net.modfest.scatteredshards.api.shard.ShardType;
1919
import net.modfest.scatteredshards.client.ScatteredShardsClient;
20+
import net.modfest.scatteredshards.util.ModMetaUtil;
2021

2122
import java.util.function.Consumer;
2223

@@ -35,6 +36,7 @@ public WMiniShard() {
3536
}
3637

3738
public WMiniShard setShard(Shard shard, boolean collected, Identifier shardId) {
39+
shard.icon().ifRight(ModMetaUtil::touchIconTexture);
3840
this.shard = shard;
3941
this.shardType = ScatteredShardsAPI.getClientLibrary().shardTypes().get(shard.shardTypeId()).orElse(ShardType.MISSING);
4042
this.isCollected = collected;

src/main/java/net/modfest/scatteredshards/client/screen/widget/WShardPanel.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import net.modfest.scatteredshards.client.screen.widget.scalable.WScaledLabel;
2727
import net.modfest.scatteredshards.client.screen.widget.scalable.WScaledText;
2828
import net.modfest.scatteredshards.client.screen.widget.scalable.WShardIcon;
29+
import net.modfest.scatteredshards.util.ModMetaUtil;
2930

3031
import java.util.List;
3132
import java.util.function.IntSupplier;
@@ -50,7 +51,7 @@ public class WShardPanel extends WPlainPanel {
5051
.setShadow(true)
5152
.setHorizontalAlignment(HorizontalAlignment.CENTER)
5253
.setColor(() -> shardType.textColor());
53-
private final WScaledLabel source = new WScaledLabel(shard::source, 0.9f)
54+
private final WScaledLabel source = new WScaledLabel(() -> Shard.getSourceForSourceId(shard.sourceId()), 0.9f)
5455
.setShadow(true)
5556
.setHorizontalAlignment(HorizontalAlignment.CENTER);
5657
private final WScaledText lore = new WScaledText(shard::lore, 0.8f)
@@ -111,13 +112,14 @@ public WShardPanel setHint(Supplier<Text> text, IntSupplier color) {
111112
}
112113

113114
public WShardPanel setShard(Shard shard) {
115+
shard.icon().ifRight(ModMetaUtil::touchIconTexture);
114116
this.shard = shard;
115117
this.isHidden = false;
116118

117119
setType(shard.shardTypeId(), ScatteredShardsAPI.getClientLibrary().shardTypes().get(shard.shardTypeId()).orElse(ShardType.MISSING));
118120
icon.setIcon(shard::icon);
119121
setName(shard::name, WHITE);
120-
setSource(shard::source, WHITE);
122+
setSource(() -> Shard.getSourceForSourceId(shard.sourceId()), WHITE);
121123
setLore(shard::lore, WHITE);
122124
setHint(shard::hint, WHITE);
123125

src/main/java/net/modfest/scatteredshards/command/LibraryCommand.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public static int migrate(CommandContext<ServerCommandSource> ctx) throws Comman
7272
Shard shard = library.shards().get(shardId).orElseThrow(() -> ShardCommand.INVALID_SHARD.create(shardId));
7373

7474
library.shards().remove(shardId);
75+
library.shardSets().values().removeIf(i -> i.equals(shardId));
7576
shard.setShardType(shardTypeId);
7677
library.shards().put(newShardId, shard);
7778

0 commit comments

Comments
 (0)