Skip to content

Commit

Permalink
Merge branch '1.18' into 1.19
Browse files Browse the repository at this point in the history
# Conflicts:
#	gradle.properties
#	settings.gradle
  • Loading branch information
sisby-folk committed Aug 24, 2022
2 parents 9630b15 + 4762642 commit a1c3cc3
Show file tree
Hide file tree
Showing 10 changed files with 193 additions and 24 deletions.
62 changes: 49 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,64 @@ Works in singleplayer and on server-side.</p>
---

Commands:
- `/switchy help`
- `/switchy list` - list your created presets, and the current one.
- `/switchy new [name]` - create a new preset from your active customizations.
- `/switchy set [name]` - switch to another preset.
- `/switch [name]` - alias for `/switchy set`
- `/switchy delete [name]` - delete a preset.
- `/switchy help`
- `/switchy list` - list your created presets, and the current one.
- `/switchy new [name]` - create a new preset from your active customizations.
- `/switchy set [name]` - switch to another preset.
- `/switch [name]` - alias for `/switchy set`
- `/switchy rename [name] [name]` - rename a preset.
- `/switchy delete [name]` - delete a preset.
- `/switchy module enable [name]` - enable a module for you.
- `/switchy delete disable [name]` - disable a module for you.

On its own, supports player customization from:
- [Drogtor The Nickinator](https://modrinth.com/mod/drogtor) - player `nickname`, `bio`, and `color`
- [Fabric Tailor](https://modrinth.com/mod/fabrictailor) - set skin
- [Origins](https://modrinth.com/mod/origins/versions) - current origins (includes all layers, e.g. [Statures](https://modrinth.com/mod/tinkerers-statures) for player height)
Comes packaged with modules for:
- [Drogtor The Nickinator](https://modrinth.com/mod/drogtor) - player `nickname`, `bio`, and `color`
- [Fabric Tailor](https://modrinth.com/mod/fabrictailor) - set skin
- [Origins](https://modrinth.com/mod/origins/versions) - current origins (includes all layers, e.g. [Statures](https://modrinth.com/mod/tinkerers-statures) for player height)

## Design
Further modules can be added from these addons:
- [Switchy Inventories](https://modrinth.com/mod/switchy-inventories) - Addon for minecraft. Gives each preset a separate inventory.
- Highly recommended - Comes disabled by default and can be enabled on a per-player basis.

Switchy handles all of its interactions with other mods using a **Compatibility Module** system. Any mod can add new compatibility modules to switchy, and it will work without any changes. Switchy's mod compatibility for the mods above are made in this format, and can be used as reference.
## Showcase

Only loaded modules will load and save data - Note that this means that removing a compatible mod will cause its data to be removed from presets.
<iframe width="896" height="504" src="https://www.youtube.com/embed/_hXYjbNfd7Y" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>

## Design - Modules

Switchy, at its core, is a mod that gives you a list of empty presets. You can add to the list, set what preset is "current", and so on, but none of these presets *do* anything.

> At its core - Switchy is a mod that **does nothing** - and that's key to its design.
Switchy modules provide switchy with all of its practical functionality, but despite this, they're only required to do four things:
- Save themselves to an NBT Compound.
- Load themselves from an NBT Compound.
- Read data to themselves from the player.
- Apply data from themselves to the player.

Because mods, and minecraft itself, often have to do these things already, compatibility modules are often extremely simple to write (the *Switchy Inventories* module took **[5 lines of code](https://github.com/sisby-folk/switchy-inventories/blob/1.18/src/main/java/folk/sisby/switchy_inventories/compat/InventoryCompat.java)**.)

We hope players and developers find this useful.

## Developing Addons

If you'd like to develop your own addon module, feel free to fork the [Inventories Module](https://github.com/sisby-folk/switchy-inventories) to get started.

Otherwise, all an addon mod needs to do is create a module class that implements `api.PresetModule` and registers itself using the `api.PresetModuleRegistry` - Go wild!

## Further Info

All mods are built on the work of many others.

![Created for ModFest: Singularity](https://blob.jortage.com/blobs/5/d4d/5d4d14d96db2e2024d87cf5606cb7ce6421633a002e328947f85d210ba250ecb9f86de8df210dd031be2d4eafb0980494e7a1e8e99590a550abaa42d82768b9f)

We made this mod (up to v1.2.1) for Modfest: Singularity! However, we intend to maintain this mod into the future.

This mod is included in [Tinkerer's Quilt](https://modrinth.com/modpack/tinkerers-quilt) - our modpack all about ease of play and ease of expression.

This mod is primarily motivated for improving game accessibility for [plural systems](https://morethanone.info).
We support the [Plural Respect Document](https://bit.ly/pluralrespect) - its perspectives largely reflect our own.

We're primarily modpack developers - not mod developers! If you want to port this mod, do it yourself!

Though feel free to let us know if we can spruce anything on the implementation side - PRs and issues with code snippets are welcome as long as you can help us understand them.
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ repositories {

// Origins
maven {
name = "Ladysnake Libs"
name = 'Ladysnake Mods'
url = 'https://ladysnake.jfrog.io/artifactory/mods'
}
maven {
Expand Down Expand Up @@ -85,6 +85,10 @@ dependencies {
modLocalRuntime files('/build/libs/player-pronouns-1.6.0+1.19.jar')
modLocalRuntime "eu.pb4:placeholder-api:2.0.0-beta.7+1.19"
modLocalRuntime files('/build/libs/more-codecs-0.2.2+1.18.jar')

// Cardinal Components
modCompileOnly libs.cardinal
modCompileOnly libs.cardinalEntity
}

processResources {
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ org.gradle.jvmargs = -Xmx1G
org.gradle.parallel = true

# Mod Properties
version = 1.2.1+1.19
version = 1.2.2+1.18
maven_group = folk.sisby
archives_base_name = switchy

# Dependencies
minecraft_version=1.19.2
quilt_mappings=3
quilt_mappings=6
3 changes: 3 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@ dependencyResolutionManagement {
// Compat
version('fabrictailor', "1.9.0")
version('origins', "v1.6.2")
version('cardinal', "5.0.1")

library('fabrictailor', 'com.github.samolego', 'FabricTailor').versionRef('fabrictailor')
library('origins', 'com.github.apace100', 'origins-fabric').versionRef('origins')
library('cardinal', 'dev.onyxstudios.cardinal-components-api', 'cardinal-components-base').versionRef('cardinal')
library('cardinalEntity', 'dev.onyxstudios.cardinal-components-api', 'cardinal-components-entity').versionRef('cardinal')
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/folk/sisby/switchy/Switchy.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ public void onInitialize(ModContainer mod) {
if (QuiltLoader.isModLoaded("fabrictailor")) FabricTailorCompat.touch();
if (QuiltLoader.isModLoaded("origins")) OriginsCompat.touch();

LOGGER.info("Switchy: Initialized! Registered Base Modules: " + COMPAT_REGISTRY.keySet());
LOGGER.info("Switchy: Initialized! Already Registered Modules: " + COMPAT_REGISTRY.keySet());
}
}
4 changes: 4 additions & 0 deletions src/main/java/folk/sisby/switchy/SwitchyCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ private static int setPreset(ServerPlayerEntity player, SwitchyPresets presets,
tellInvalid(player, "That preset doesn't exist! Try ", "/switchy list");
return 0;
}
if (presetName.equalsIgnoreCase(Objects.toString(presets.getCurrentPreset(), null))) {
tellInvalid(player, "You can't swap to your current preset! Try ", "/switchy list");
return 0;
}

String oldPresetName = Objects.toString(presets.getCurrentPreset(), "<None>");
presets.setCurrentPreset(presetName, true);
Expand Down
8 changes: 2 additions & 6 deletions src/main/java/folk/sisby/switchy/SwitchyPresets.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import net.minecraft.nbt.NbtList;
import net.minecraft.nbt.NbtString;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -105,18 +104,15 @@ public boolean setCurrentPreset(String presetName, Boolean performSwitch) {
}

private void switchPreset(SwitchyPreset oldPreset, SwitchyPreset newPreset) {
if (oldPreset != null) {
// Preserve current values into preset before swapping
oldPreset.updateFromPlayer(player);
}
oldPreset.updateFromPlayer(player);
newPreset.applyToPlayer(player);
}

public void saveCurrentPreset() {
if (this.currentPreset != null) this.currentPreset.updateFromPlayer(player);
}

public @Nullable SwitchyPreset getCurrentPreset() {
public SwitchyPreset getCurrentPreset() {
return currentPreset;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.util.function.Supplier;

public class PresetModuleRegistry {
public static void registerModule(Identifier moduleId, Supplier<? extends PresetModule> moduleConstructor) {
public static void registerModule(Identifier moduleId, Supplier<PresetModule> moduleConstructor) {
Switchy.registerModule(moduleId, moduleConstructor);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package folk.sisby.switchy.api.modules;

import dev.onyxstudios.cca.api.v3.component.ComponentKey;
import dev.onyxstudios.cca.api.v3.component.CopyableComponent;
import folk.sisby.switchy.api.PresetModule;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.Identifier;

import java.util.function.Supplier;

public class CardinalCopyableCompat<T1 extends CopyableComponent<T1>> implements PresetModule {
private final Identifier ID;
private final boolean isDefault;

// Generic Fields
private final ComponentKey<T1> registryKey;

// Module Data
private final T1 component;

@Override
public void updateFromPlayer(PlayerEntity player) {
this.component.copyFrom(registryKey.get(player));
}

@Override
public void applyToPlayer(PlayerEntity player) {
registryKey.get(player).copyFrom(this.component);
}

@Override
public NbtCompound toNbt() {
NbtCompound outNbt = new NbtCompound();
this.component.writeToNbt(outNbt);
return outNbt;
}

@Override
public void fillFromNbt(NbtCompound nbt) {
this.component.readFromNbt(nbt);
}

@Override
public Identifier getId() {
return ID;
}

@Override
public boolean isDefault() {
return isDefault;
}

public CardinalCopyableCompat(Identifier id, ComponentKey<T1> registryKey, Supplier<T1> componentFactory, Boolean isDefault) {
this.ID = id;
this.registryKey = registryKey;
this.component = componentFactory.get();
this.isDefault = isDefault;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package folk.sisby.switchy.api.modules;

import dev.onyxstudios.cca.api.v3.component.ComponentKey;
import dev.onyxstudios.cca.api.v3.component.ComponentV3;
import folk.sisby.switchy.api.PresetModule;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.Identifier;

import java.util.function.BiConsumer;

public class CardinalSerializerCompat<T1 extends ComponentV3> implements PresetModule {
private final Identifier ID;
private final boolean isDefault;

// Generic Fields
private final ComponentKey<T1> registryKey;
private final BiConsumer<T1, PlayerEntity> preApplyClear;
private final BiConsumer<T1, PlayerEntity> postApplySync;

// Module Data
private NbtCompound componentTag = new NbtCompound();

@Override
public void updateFromPlayer(PlayerEntity player) {
T1 component = registryKey.get(player);
this.componentTag = new NbtCompound();
component.writeToNbt(componentTag);
}

@Override
public void applyToPlayer(PlayerEntity player) {
T1 component = registryKey.get(player);
preApplyClear.accept(component, player);
component.readFromNbt(componentTag);
postApplySync.accept(component, player);
}

@Override
public NbtCompound toNbt() {
return componentTag.copy();
}

@Override
public void fillFromNbt(NbtCompound nbt) {
this.componentTag.copyFrom(nbt);
}

@Override
public Identifier getId() {
return ID;
}

@Override
public boolean isDefault() {
return isDefault;
}

public CardinalSerializerCompat(Identifier id, ComponentKey<T1> registryKey, BiConsumer<T1, PlayerEntity> preApplyClear, BiConsumer<T1, PlayerEntity> postApplySync, Boolean isDefault) {
this.registryKey = registryKey;
this.ID = id;
this.preApplyClear = preApplyClear;
this.postApplySync = postApplySync;
this.isDefault = isDefault;
}
}

0 comments on commit a1c3cc3

Please sign in to comment.