-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
API breakages to make this good soon - but this is a good PoC.
- Loading branch information
1 parent
1b77105
commit 9611f3f
Showing
21 changed files
with
358 additions
and
62 deletions.
There are no files selected for viewing
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
6 changes: 6 additions & 0 deletions
6
client/src/main/java/folk/sisby/switchy/client/api/SwitchyClientModInitializer.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,6 @@ | ||
package folk.sisby.switchy.client.api; | ||
|
||
@FunctionalInterface | ||
public interface SwitchyClientModInitializer { | ||
void onInitialize(); | ||
} |
16 changes: 16 additions & 0 deletions
16
client/src/main/java/folk/sisby/switchy/client/api/SwitchyScreenExtensions.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,16 @@ | ||
package folk.sisby.switchy.client.api; | ||
|
||
import folk.sisby.switchy.client.presets.SwitchyDisplayPreset; | ||
import folk.sisby.switchy.client.screen.SwitchScreen.ComponentPosition; | ||
import io.wispforest.owo.ui.core.Component; | ||
import net.minecraft.util.Identifier; | ||
|
||
import java.util.function.Function; | ||
|
||
import static folk.sisby.switchy.client.screen.SwitchScreen.registerPresetDisplayComponent; | ||
|
||
public class SwitchyScreenExtensions { | ||
public static void registerQuickSwitchDisplayComponent(Identifier id, ComponentPosition pos, Function<SwitchyDisplayPreset, Component> componentFunction) { | ||
registerPresetDisplayComponent(id, pos, componentFunction); | ||
} | ||
} |
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
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 |
---|---|---|
@@ -1,15 +1,17 @@ | ||
dependencies { | ||
implementation(project(path: ':core', configuration: 'namedElements')) | ||
implementation(project(path: ':client', configuration: 'namedElements')) | ||
|
||
// Redo Client Deps (why) | ||
modCompileOnly libs.bundles.client | ||
|
||
// Optional Compatible Mods | ||
modCompileOnly libs.bundles.compat.compile | ||
modLocalRuntime libs.bundles.compat.runtime | ||
modCompileOnly(libs.origins) { | ||
exclude module: 'AdditionalEntityAttributes' | ||
exclude module: 'apoli' | ||
} | ||
modLocalRuntime(libs.origins) { | ||
exclude module: 'calio' | ||
modCompileOnly(libs.apoli) { | ||
exclude module: 'AdditionalEntityAttributes' | ||
} | ||
|
||
} |
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
33 changes: 33 additions & 0 deletions
33
compat/src/main/java/folk/sisby/switchy/SwitchyCompatClient.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,33 @@ | ||
package folk.sisby.switchy; | ||
|
||
import folk.sisby.switchy.client.api.SwitchyClientModInitializer; | ||
import folk.sisby.switchy.modules.DrogtorCompatClient; | ||
import folk.sisby.switchy.modules.FabricTailorCompatClient; | ||
import folk.sisby.switchy.modules.OriginsCompatClient; | ||
import folk.sisby.switchy.modules.StyledNicknamesCompatClient; | ||
import org.quiltmc.loader.api.QuiltLoader; | ||
|
||
public class SwitchyCompatClient implements SwitchyClientModInitializer { | ||
@Override | ||
public void onInitialize() { | ||
// Basically recreate the functionality of every mod because it might not be on the client (ow) | ||
// We can definitely do better than this for API. writing two NBT parsers makes no sense. | ||
|
||
// Resolution: We need to take a path that allows compat modules to be moved into their respective mods | ||
// In this case, this really does mean adding client-side addon functionality to server-sided mods like styled. | ||
// So yes, you may literally need to install styled nicknames onto your client. Patbox is crying. Everyone is crying. | ||
|
||
// If it's serializable or packetable though, we'd be able to parse The module data into something usable on | ||
// the client side *before* sending it. So that's good. | ||
|
||
// I'd say we probably want a Serializer that handles field storage, and an extension of that interface | ||
// Think: DrogtorServerModule extends DrogtorModuleSerializer implements SwitchyModule (<DrogtorModuleSerializer>?) | ||
// interface SwitchyModule extends SwitchyModuleSerializer | ||
// interface SwitchyClientModule extends SwitchyModuleSerializer | ||
|
||
DrogtorCompatClient.touch(); | ||
StyledNicknamesCompatClient.touch(); | ||
FabricTailorCompatClient.touch(); | ||
if (QuiltLoader.isModLoaded("origins")) OriginsCompatClient.touch(); | ||
} | ||
} |
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
34 changes: 34 additions & 0 deletions
34
compat/src/main/java/folk/sisby/switchy/modules/DrogtorCompatClient.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,34 @@ | ||
package folk.sisby.switchy.modules; | ||
|
||
import folk.sisby.switchy.client.api.SwitchyScreenExtensions; | ||
import folk.sisby.switchy.client.screen.SwitchScreen.ComponentPosition; | ||
import io.wispforest.owo.ui.component.Components; | ||
import net.minecraft.nbt.NbtCompound; | ||
import net.minecraft.text.HoverEvent; | ||
import net.minecraft.text.Style; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.Formatting; | ||
import net.minecraft.util.Identifier; | ||
|
||
public class DrogtorCompatClient { | ||
public static final Identifier ID = new Identifier("switchy", "drogtor"); | ||
|
||
public static final String KEY_NICKNAME = "nickname"; | ||
public static final String KEY_NAME_COLOR = "nameColor"; | ||
public static final String KEY_BIO = "bio"; | ||
|
||
|
||
public static void touch() {} | ||
|
||
static { | ||
SwitchyScreenExtensions.registerQuickSwitchDisplayComponent(ID, ComponentPosition.RIGHT, displayPreset -> { | ||
if (!displayPreset.modules.containsKey(ID)) return null; | ||
NbtCompound nbt = displayPreset.modules.get(ID); | ||
if (!nbt.contains(KEY_NICKNAME)) return null; | ||
Style style = Style.EMPTY; | ||
if (nbt.contains(KEY_NAME_COLOR)) style = style.withColor(Formatting.byName(nbt.getString(KEY_NAME_COLOR))); | ||
if (nbt.contains(KEY_BIO)) style = style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.literal(nbt.getString(KEY_BIO)))); | ||
return Components.label(Text.literal(nbt.getString(KEY_NICKNAME)).setStyle(style)); | ||
}); | ||
} | ||
} |
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
55 changes: 55 additions & 0 deletions
55
compat/src/main/java/folk/sisby/switchy/modules/FabricTailorCompatClient.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,55 @@ | ||
package folk.sisby.switchy.modules; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.GsonBuilder; | ||
import com.mojang.authlib.minecraft.MinecraftProfileTexture; | ||
import com.mojang.authlib.yggdrasil.response.MinecraftTexturesPayload; | ||
import com.mojang.util.UUIDTypeAdapter; | ||
import folk.sisby.switchy.client.api.SwitchyScreenExtensions; | ||
import folk.sisby.switchy.client.screen.SwitchScreen; | ||
import io.wispforest.owo.ui.component.Components; | ||
import io.wispforest.owo.ui.component.EntityComponent; | ||
import io.wispforest.owo.ui.core.Sizing; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.network.AbstractClientPlayerEntity; | ||
import net.minecraft.nbt.NbtCompound; | ||
import net.minecraft.util.Identifier; | ||
|
||
import java.util.Base64; | ||
import java.util.UUID; | ||
|
||
public class FabricTailorCompatClient { | ||
public static final Identifier ID = new Identifier("switchy", "fabric_tailor"); | ||
|
||
public static final String KEY_SKIN_VALUE = "skinValue"; | ||
public static final String KEY_SKIN_SIGNATURE = "skinSignature"; | ||
|
||
public static void touch() {} | ||
|
||
static { | ||
SwitchyScreenExtensions.registerQuickSwitchDisplayComponent(ID, SwitchScreen.ComponentPosition.SIDE_RIGHT, displayPreset -> { | ||
if (!displayPreset.modules.containsKey(ID)) return null; | ||
NbtCompound nbt = displayPreset.modules.get(ID); | ||
if (!nbt.contains(KEY_SKIN_VALUE) || !nbt.contains(KEY_SKIN_SIGNATURE)) return null; | ||
MinecraftClient client = MinecraftClient.getInstance(); | ||
|
||
String value = nbt.getString(KEY_SKIN_VALUE); | ||
Gson gson = new GsonBuilder().registerTypeAdapter(UUID.class, new UUIDTypeAdapter()).create(); | ||
MinecraftTexturesPayload payload = gson.fromJson(new String(Base64.getDecoder().decode(value)), MinecraftTexturesPayload.class); | ||
MinecraftProfileTexture skinTexture = payload.getTextures().get(MinecraftProfileTexture.Type.SKIN); | ||
|
||
Identifier skinId = client.getSkinProvider().loadSkin(skinTexture, MinecraftProfileTexture.Type.SKIN); | ||
|
||
EntityComponent<AbstractClientPlayerEntity> skinPreview = Components.entity(Sizing.fixed(60), new AbstractClientPlayerEntity(client.world, client.getSession().getProfile(), null) { | ||
@Override | ||
public Identifier getSkinTexture() { | ||
return skinId; | ||
} | ||
}); | ||
|
||
skinPreview.scale(0.5F); | ||
|
||
return skinPreview; | ||
}); | ||
} | ||
} |
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
Oops, something went wrong.