Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions bc23-shards/assets/bc23/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"shard_type.bc23.visitor.description": "Visitor Shard",
"shard_type.bc23.challenge.description": "Challenge Shard",
"shard_type.bc23.secret.description": "Secret Shard",
"shard_type.bc23.missing.description": "Missing Shard"
}
31 changes: 31 additions & 0 deletions bc23-shards/data/bc23/shard_type/bc23_types.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"bc23:visitor": {
"text_color": "#6de851",
"glow_color": "#00ff48",
"collect_particle": "minecraft:totem_of_undying",
"collect_sound": {
"sound_id": "scattered_shards:collect_visitor"
},
"list_order": 1
},

"bc23:challenge": {
"text_color": "#5174e8",
"glow_color": "#0026ff",
"collect_particle": "minecraft:glow",
"collect_sound": {
"sound_id": "scattered_shards:collect_challenge"
},
"list_order": 2
},

"bc23:secret": {
"text_color": "#eb4034",
"glow_color": "#f08",
"collect_particle": "minecraft:witch",
"collect_sound": {
"sound_id": "scattered_shards:collect_secret"
},
"list_order": 3
}
}
6 changes: 6 additions & 0 deletions bc23-shards/pack.mcmeta
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"pack": {
"pack_format": 10,
"description": "Scattered Shards assets used at BlanketCon '23"
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package net.modfest.scatteredshards;

import net.modfest.scatteredshards.api.ScatteredShardsAPI;
import net.modfest.scatteredshards.load.ShardTypeLoader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -28,14 +30,11 @@ public static String permission(String path) {

@Override
public void onInitialize() {
//ScatteredShardsAPI.init();
ShardType.register();
//ShardTypeLoader.register();
//ShardSetLoader.register();
ShardTypeLoader.register();
ShardCommand.register();
ScatteredShardsNetworking.register();
ScatteredShardsContent.register();
FabricLoader.getInstance().getModContainer(ID).ifPresent(mod -> {
ResourceManagerHelper.registerBuiltinResourcePack(ScatteredShards.id("test"), mod, ResourcePackActivationType.NORMAL);
});
}
}
10 changes: 10 additions & 0 deletions src/main/java/net/modfest/scatteredshards/api/MiniRegistry.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package net.modfest.scatteredshards.api;

import java.util.Collection;
import java.util.Map;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.stream.Stream;
Expand Down Expand Up @@ -47,10 +49,18 @@ public Stream<Identifier> streamKeys() {
public void put(Identifier id, T value) {
data.put(id, value);
}

public void putAll(Map<Identifier, T> values) {
data.putAll(values);
}

public void remove(Identifier id) {
data.remove(id);
}

public void removeAll(Collection<Identifier> ids) {
data.keySet().removeAll(ids);
}

public void clear() {
data.clear();
Expand Down
59 changes: 59 additions & 0 deletions src/main/java/net/modfest/scatteredshards/api/impl/ColorCodec.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package net.modfest.scatteredshards.api.impl;

import com.mojang.serialization.Codec;

public class ColorCodec {

public static Codec<Integer> CODEC = Codec.STRING.xmap(ColorCodec::parseColor, ColorCodec::valueOf);

public static int parseColor(String str) {
if (str.startsWith("#")) str = str.substring(1);
if (str.length() == 3) {
int r = hexDigit(str.charAt(0)); r = r | (r << 4);
int g = hexDigit(str.charAt(1)); g = g | (g << 4);
int b = hexDigit(str.charAt(2)); b = b | (b << 4);
return (r << 16) | (g << 8) | b;
} else if (str.length() == 6) {
int r = hexDigit(str.charAt(0)) << 4 | hexDigit(str.charAt(1));
int g = hexDigit(str.charAt(2)) << 4 | hexDigit(str.charAt(3));
int b = hexDigit(str.charAt(4)) << 4 | hexDigit(str.charAt(5));
return (r << 16) | (g << 8) | b;
} else {
return 0xFFFFFF;
}
}

public static String valueOf(int col) {
col = col & 0xFFFFFF;
int r = (col >> 16) & 0xFF;
int g = (col >> 8) & 0xFF;
int b = col & 0xFF;

String rs = Integer.toHexString(r);
String gs = Integer.toHexString(g);
String bs = Integer.toHexString(b);
while (rs.length()<2) rs = "0" + rs;
while (gs.length()<2) gs = "0" + gs;
while (bs.length()<2) bs = "0" + bs;

boolean shortR = (rs.charAt(0) == rs.charAt(1));
boolean shortG = (gs.charAt(0) == gs.charAt(1));
boolean shortB = (bs.charAt(0) == bs.charAt(1));
if (shortR && shortG && shortB) {
return "#" + rs.charAt(0) + gs.charAt(0) + bs.charAt(0);
} else {
return "#" + rs + gs + bs;
}
}

private static final char[] HEX_DIGITS = {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
};
private static final int hexDigit(char ch) {
ch = Character.toLowerCase(ch);
for(int i=0; i<HEX_DIGITS.length; i++) {
if (HEX_DIGITS[i] == ch) return i;
}
return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import net.modfest.scatteredshards.api.ScatteredShardsAPI;
import net.modfest.scatteredshards.api.ShardLibrary;
import net.modfest.scatteredshards.api.shard.Shard;
import net.modfest.scatteredshards.api.shard.ShardType;

public class ShardLibraryPersistentState extends PersistentState {
public static PersistentState.Type<ShardLibraryPersistentState> TYPE = new PersistentState.Type<>(
Expand All @@ -20,7 +19,6 @@ public class ShardLibraryPersistentState extends PersistentState {
null
);

public static final String SHARD_TYPES_KEY = "ShardTypes";
public static final String SHARDS_KEY = "Shards";
public static final String SHARD_SETS_KEY = "ShardSets";

Expand All @@ -31,15 +29,6 @@ public static ShardLibraryPersistentState get(MinecraftServer server) {
}

public ShardLibraryPersistentState() {
addDefaultShardTypes();
}

private static void addDefaultShardTypes() {
ShardLibrary library = ScatteredShardsAPI.getServerLibrary();
library.shardTypes().put(ScatteredShards.id("visitor"), ShardType.VISITOR);
library.shardTypes().put(ScatteredShards.id("challenge"), ShardType.CHALLENGE);
library.shardTypes().put(ScatteredShards.id("secret"), ShardType.SECRET);
library.shardTypes().put(ShardType.MISSING_ID, ShardType.MISSING);
}

public static ShardLibraryPersistentState createFromNbt(NbtCompound tag) {
Expand All @@ -48,27 +37,8 @@ public static ShardLibraryPersistentState createFromNbt(NbtCompound tag) {
// This is just a placeholder - all the data lives in the serverLibrary below

ShardLibrary library = ScatteredShardsAPI.getServerLibrary();
library.clearAll();

NbtCompound shardTypes = tag.getCompound(SHARD_TYPES_KEY);
if (shardTypes.isEmpty() || (shardTypes.getSize() == 1 && shardTypes.contains(ShardType.MISSING_ID.toString()))) {
//Either the ShardTypes were completely empty, or the only ShardType present is the missing type.

//TODO: Load shardTypes from resources
//For now, we're preloading with the default types if none are present.
addDefaultShardTypes();
state.markDirty();
} else {
for(String id : shardTypes.getKeys()) {
try {
NbtCompound shardNbt = shardTypes.getCompound(id);
library.shardTypes().put(new Identifier(id), ShardType.fromNbt(shardNbt));

} catch (Throwable t) {
ScatteredShards.LOGGER.error("Could not load shardType \""+id+"\": " + t.getMessage());
}
}
}
library.shards().clear();
library.shardSets().clear();

NbtCompound shards = tag.getCompound(SHARDS_KEY);
for(String id : shards.getKeys()) {
Expand Down Expand Up @@ -99,11 +69,7 @@ public static ShardLibraryPersistentState createFromNbt(NbtCompound tag) {
}
}

if (library.shardTypes().size() == 1 && library.shardTypes().streamKeys().findFirst().get().equals(ShardType.MISSING_ID)) {

}

ScatteredShards.LOGGER.info("Loaded " + library.shardTypes().size() + " shard types, " + library.shards().size() + " shards, and " + library.shardSets().size() + " shardSets.");
ScatteredShards.LOGGER.info("Loaded " + library.shards().size() + " shards and " + library.shardSets().size() + " shardSets.");

return state;
}
Expand All @@ -112,9 +78,8 @@ public static ShardLibraryPersistentState createFromNbt(NbtCompound tag) {
@Override
public NbtCompound writeNbt(NbtCompound tag) {
ShardLibrary library = ScatteredShardsAPI.getServerLibrary();
ScatteredShards.LOGGER.info("Saving the ShardLibrary with " + library.shardTypes().size() + " shard types, " + library.shards().size() + " shards, and " + library.shardSets().size() + " shardSets...");
ScatteredShards.LOGGER.info("Saving the ShardLibrary with " + library.shards().size() + " shards and " + library.shardSets().size() + " shardSets...");

tag.put(SHARD_TYPES_KEY, library.shardTypes().toNbt());
tag.put(SHARDS_KEY, library.shards().toNbt());

NbtCompound shardSets = new NbtCompound();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ public class Shard {
public static final Codec<Either<ItemStack, Identifier>> ICON_CODEC = Codec.either(ItemStack.CODEC, Identifier.CODEC);

public static final Codec<Shard> CODEC = RecordCodecBuilder.create(instance -> instance.group(
Identifier.CODEC.fieldOf("shardTypeId").forGetter(Shard::shardTypeId),
Identifier.CODEC.fieldOf("shard_type_id").forGetter(Shard::shardTypeId),
TextCodecs.CODEC.fieldOf("name").forGetter(Shard::name),
TextCodecs.CODEC.fieldOf("lore").forGetter(Shard::lore),
TextCodecs.CODEC.fieldOf("hint").forGetter(Shard::hint),
TextCodecs.CODEC.fieldOf("source").forGetter(Shard::source),
Identifier.CODEC.fieldOf("sourceId").forGetter(Shard::sourceId),
Identifier.CODEC.fieldOf("source_id").forGetter(Shard::sourceId),
ICON_CODEC.fieldOf("icon").forGetter(Shard::icon)
).apply(instance, Shard::new));

Expand Down
23 changes: 10 additions & 13 deletions src/main/java/net/modfest/scatteredshards/api/shard/ShardType.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,29 @@
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtOps;
import net.minecraft.particle.ParticleType;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.sound.SoundEvent;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.modfest.scatteredshards.ScatteredShards;
import net.modfest.scatteredshards.api.impl.ColorCodec;

public record ShardType(int textColor, int glowColor, Optional<ParticleType<?>> collectParticle, Optional<SoundEvent> collectSound) {
public record ShardType(int textColor, int glowColor, Optional<ParticleType<?>> collectParticle, Optional<SoundEvent> collectSound, int listOrder) {

public static final Codec<ShardType> CODEC = RecordCodecBuilder.create(instance -> instance.group(
Codec.INT.fieldOf("textColor").forGetter(ShardType::textColor),
Codec.INT.fieldOf("glowColor").forGetter(ShardType::glowColor),
Codec.optionalField("collectParticle", Registries.PARTICLE_TYPE.getCodec()).forGetter(ShardType::collectParticle),
Codec.optionalField("collectSound", SoundEvent.CODEC).forGetter(ShardType::collectSound)
ColorCodec.CODEC.fieldOf("text_color").forGetter(ShardType::textColor),
ColorCodec.CODEC.fieldOf("glow_color").forGetter(ShardType::glowColor),
Codec.optionalField("collect_particle", Registries.PARTICLE_TYPE.getCodec()).forGetter(ShardType::collectParticle),
Codec.optionalField("collect_sound", SoundEvent.CODEC).forGetter(ShardType::collectSound),
Codec.INT.fieldOf("list_order").forGetter(ShardType::listOrder)
).apply(instance, ShardType::new));

public static final SoundEvent COLLECT_VISITOR_SOUND = SoundEvent.of(ScatteredShards.id("collect_visitor"));
public static final SoundEvent COLLECT_CHALLENGE_SOUND = SoundEvent.of(ScatteredShards.id("collect_challenge"));
public static final SoundEvent COLLECT_SECRET_SOUND = SoundEvent.of(ScatteredShards.id("collect_secret"));

public static final ShardType VISITOR = new ShardType(0x6DE851, 0x00FF48, Optional.of(ParticleTypes.TOTEM_OF_UNDYING), Optional.of(COLLECT_VISITOR_SOUND));
public static final ShardType CHALLENGE = new ShardType(0x5174E8, 0x0026FF, Optional.of(ParticleTypes.GLOW), Optional.of(COLLECT_CHALLENGE_SOUND));
public static final ShardType SECRET = new ShardType(0xEB4034, 0xFF0088, Optional.of(ParticleTypes.WITCH), Optional.of(COLLECT_SECRET_SOUND));
public static final ShardType MISSING = new ShardType(0xFFFFFF, 0xFF00FF, Optional.empty(), Optional.empty());

public static final ShardType MISSING = new ShardType(0xFFFFFF, 0xFF00FF, Optional.empty(), Optional.empty(), -1);
public static final Identifier MISSING_ID = ScatteredShards.id("missing");

public static Identifier createModId(Identifier shardTypeId, String modId) {
Expand All @@ -58,8 +55,8 @@ public static Identifier getMiniFrontTexture(Identifier id) {
return getTexture(id, "mini_front");
}

public static Identifier getMiniBackTexture(Identifier id) {
return getTexture(id, "mini_back");
public static Identifier getMiniBackingTexture(Identifier id) {
return getTexture(id, "mini_backing");
}

public static Text getDescription(Identifier id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.minecraft.client.toast.SystemToast;
import net.minecraft.client.toast.Toast;

import net.minecraft.sound.SoundEvents;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.modfest.scatteredshards.ScatteredShards;
Expand All @@ -14,6 +15,7 @@
import net.modfest.scatteredshards.api.ScatteredShardsAPI;
import net.modfest.scatteredshards.api.shard.Shard;
import net.modfest.scatteredshards.api.shard.ShardType;
import net.modfest.scatteredshards.client.screen.ShardTabletGuiDescription;
import net.modfest.scatteredshards.networking.ScatteredShardsNetworking;

public class ScatteredShardsClient implements ClientModInitializer {
Expand Down Expand Up @@ -56,8 +58,19 @@ public static void triggerShardModificationToast(Identifier shardId, boolean suc
var toast = new SystemToast(
SystemToast.Type.PERIODIC_NOTIFICATION,
Text.translatable(SHARD_MODIFY_TOAST_KEY + ".title"),
Text.translatable(SHARD_MODIFY_TOAST_KEY + "." + (success ? "success" : "fail"), shardId)
Text.stringifiedTranslatable(SHARD_MODIFY_TOAST_KEY + "." + (success ? "success" : "fail"), shardId)
);
MinecraftClient.getInstance().getToastManager().add(toast);
}

public static void openShardTablet() {
final var client = MinecraftClient.getInstance();
client.send(() -> {
final var library = ScatteredShardsAPI.getClientLibrary();
final var collection = ScatteredShardsAPI.getClientCollection();

client.setScreen(new ShardTabletGuiDescription.Screen(collection, library));
client.getSoundManager().play(PositionedSoundInstance.master(SoundEvents.ITEM_BOOK_PAGE_TURN, 1.0f, 1.0f));
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,11 @@ public class ClientShardCommand {

private static DynamicCommandExceptionType createInvalidException(String item) {
return new DynamicCommandExceptionType(
obj -> Text.translatable("error.scattered_shards.invalid_" + item, obj)
obj -> Text.stringifiedTranslatable("error.scattered_shards.invalid_" + item, obj)
);
}

private static final DynamicCommandExceptionType INVALID_SET_ID = createInvalidException("set_id");
//We've removed checks for invalid modid's so people can use shards not related to them
//private static final DynamicCommandExceptionType INVALID_MOD_ID = createInvalidException("mod_id");
private static final DynamicCommandExceptionType INVALID_SHARD_TYPE = createInvalidException("shard_type");
private static final DynamicCommandExceptionType INVALID_SHARD_ID = createInvalidException("shard_id");

Expand Down Expand Up @@ -94,7 +92,9 @@ public static CompletableFuture<Suggestions> suggestShards(CommandContext<Fabric

public static CompletableFuture<Suggestions> suggestShardTypes(CommandContext<FabricClientCommandSource> context, SuggestionsBuilder builder) {
ScatteredShardsAPI.getClientLibrary().shardTypes().forEach((id, shardSet) -> {
builder.suggest(id.toString());
if (!id.equals(ShardType.MISSING_ID)) {
builder.suggest(id.toString());
}
});
return builder.buildFuture();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public WMiniShard setShardConsumer(Consumer<Shard> onClick) {
@Environment(EnvType.CLIENT)
@Override
public void paint(DrawContext context, int x, int y, int mouseX, int mouseY) {
Identifier tex = (isCollected) ? ShardType.getMiniFrontTexture(shard.shardTypeId()) : ShardType.getMiniBackTexture(shard.shardTypeId());
Identifier tex = (isCollected) ? ShardType.getMiniFrontTexture(shard.shardTypeId()) : ShardType.getMiniBackingTexture(shard.shardTypeId());
int color = (isCollected) ? 0xFF_FFFFFF : 0xFF_668866;
float opacity = (isCollected) ? 1.0f : 0.6f;
ScreenDrawing.texturedRect(context, x, y, 12, 16, tex, color, opacity);
Expand Down
Loading