-
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.
# Conflicts: # gradle.properties # settings.gradle
- Loading branch information
Showing
10 changed files
with
193 additions
and
24 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
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
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
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
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
60 changes: 60 additions & 0 deletions
60
src/main/java/folk/sisby/switchy/api/modules/CardinalCopyableCompat.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,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; | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
src/main/java/folk/sisby/switchy/api/modules/CardinalSerializerCompat.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,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; | ||
} | ||
} |