-
-
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.
improv: 1.20.1 fabric port finishes (#15)
- Loading branch information
Showing
15 changed files
with
872 additions
and
903 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
38 changes: 0 additions & 38 deletions
38
src/main/java/com/aetherteam/nitrogen/capability/CapabilityProvider.java
This file was deleted.
Oops, something went wrong.
41 changes: 20 additions & 21 deletions
41
src/main/java/com/aetherteam/nitrogen/capability/CapabilityUtil.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 |
---|---|---|
@@ -1,23 +1,22 @@ | ||
package com.aetherteam.nitrogen.capability; | ||
|
||
//import com.aetherteam.nitrogen.network.packet.SyncLevelPacket; | ||
//import net.minecraft.client.Minecraft; | ||
//import net.minecraft.world.entity.player.Player; | ||
//import net.minecraft.world.level.Level; | ||
// | ||
//public class CapabilityUtil { | ||
// /** | ||
// * Used to sync data for level capabilities. This is in its own class to avoid classloading {@link Minecraft} from {@link SyncLevelPacket} on servers. | ||
// * @param syncLevelPacket The {@link SyncLevelPacket}. | ||
// * @param playerEntity The {@link Player} that the level belongs to. | ||
// * @param key The {@link String} key for the field to sync. | ||
// * @param value The {@link Object} value to sync to the field. | ||
// * @param isClientSide Whether the level is clientside, as a {@link Boolean}. | ||
// * @see SyncLevelPacket | ||
// */ | ||
// public static void syncLevelCapability(SyncLevelPacket<?> syncLevelPacket, Player playerEntity, String key, Object value, boolean isClientSide) { | ||
// Level level = isClientSide ? Minecraft.getInstance().level : playerEntity.level(); | ||
// syncLevelPacket.getCapability(level).ifPresent((synchable) -> synchable.getSynchableFunctions().get(key).getMiddle().accept(value)); | ||
// } | ||
//} | ||
// todo CARDINAL COMPONENTS | ||
import com.aetherteam.nitrogen.network.packet.SyncLevelPacket; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.level.Level; | ||
|
||
public class CapabilityUtil { | ||
/** | ||
* Used to sync data for level capabilities. This is in its own class to avoid classloading {@link Minecraft} from {@link SyncLevelPacket} on servers. | ||
* @param syncLevelPacket The {@link SyncLevelPacket}. | ||
* @param playerEntity The {@link Player} that the level belongs to. | ||
* @param key The {@link String} key for the field to sync. | ||
* @param value The {@link Object} value to sync to the field. | ||
* @param isClientSide Whether the level is clientside, as a {@link Boolean}. | ||
* @see SyncLevelPacket | ||
*/ | ||
public static void syncLevelCapability(SyncLevelPacket<?> syncLevelPacket, Player playerEntity, String key, Object value, boolean isClientSide) { | ||
Level level = isClientSide ? Minecraft.getInstance().level : playerEntity.level(); | ||
syncLevelPacket.getCapability(level).ifPresent((synchable) -> synchable.getSynchableFunctions().get(key).getMiddle().accept(value)); | ||
} | ||
} |
258 changes: 129 additions & 129 deletions
258
src/main/java/com/aetherteam/nitrogen/capability/INBTSynchable.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 |
---|---|---|
@@ -1,131 +1,131 @@ | ||
package com.aetherteam.nitrogen.capability; | ||
|
||
//import com.aetherteam.nitrogen.network.BasePacket; | ||
//import com.aetherteam.nitrogen.network.PacketRelay; | ||
//import net.minecraft.nbt.Tag; | ||
//import net.minecraft.resources.ResourceKey; | ||
//import net.minecraft.server.level.ServerPlayer; | ||
//import net.minecraft.world.level.Level; | ||
//import net.minecraftforge.common.util.INBTSerializable; | ||
//import net.minecraftforge.network.simple.SimpleChannel; | ||
//import org.apache.commons.lang3.tuple.Triple; | ||
//import oshi.util.tuples.Quintet; | ||
// | ||
//import org.jetbrains.annotations.Nullable; | ||
//import java.util.Map; | ||
//import java.util.function.Consumer; | ||
//import java.util.function.Supplier; | ||
// | ||
//public interface INBTSynchable<T extends Tag> extends INBTSerializable<T> { | ||
// /** | ||
// * Sets a value to be synced to the given direction. | ||
// * @param direction The network {@link Direction} to send the packet. | ||
// * @param key The {@link String} key for the field to sync. | ||
// * @param value The {@link Object} value to sync to the field. | ||
// */ | ||
// default void setSynched(Direction direction, String key, Object value) { | ||
// this.setSynched(direction, key, value, null); | ||
// } | ||
// | ||
// /** | ||
// * Sets a value to be synced to the given direction.<br><br> | ||
// * Warning for "unchecked" is suppressed because casting from wildcards to classes inside type bounds is fine. | ||
// * @param direction The network {@link Direction} to send the packet. | ||
// * @param key The {@link String} key for the field to sync. | ||
// * @param value The {@link Object} value to sync to the field. | ||
// * @param extra An extra value if necessary. The type of class that needs to be given depends on the direction.<br><br> | ||
// * {@link Direction#SERVER} - None.<br><br> | ||
// * {@link Direction#CLIENT} - None.<br><br> | ||
// * {@link Direction#NEAR} - {@link Quintet}<{@link Double}, {@link Double}, {@link Double}, {@link Double}, {@link ResourceKey}<{@link Level}>>. This represents the 5 values needed for {@link PacketRelay#sendToNear(SimpleChannel, Object, double, double, double, double, ResourceKey)}.<br><br> | ||
// * {@link Direction#PLAYER} - {@link ServerPlayer}.<br><br> | ||
// * {@link Direction#DIMENSION} - {@link ResourceKey}<{@link Level}>>. This represents the dimension to send the packet to. | ||
// */ | ||
// @SuppressWarnings("unchecked") | ||
// default void setSynched(Direction direction, String key, Object value, @Nullable Object extra) { | ||
// switch(direction) { | ||
// case SERVER -> PacketRelay.sendToServer(this.getPacketChannel(), this.getSyncPacket(key, this.getSynchableFunctions().get(key).getLeft(), value)); | ||
// case CLIENT -> PacketRelay.sendToAll(this.getPacketChannel(), this.getSyncPacket(key, this.getSynchableFunctions().get(key).getLeft(), value)); | ||
// case NEAR -> { | ||
// if (extra instanceof Quintet<?,?,?,?,?> quintet) { | ||
// Quintet<Double, Double, Double, Double, ResourceKey<Level>> nearValues = (Quintet<Double, Double, Double, Double, ResourceKey<Level>>) quintet; | ||
// PacketRelay.sendToNear(this.getPacketChannel(), this.getSyncPacket(key, this.getSynchableFunctions().get(key).getLeft(), value), nearValues.getA(), nearValues.getB(), nearValues.getC(), nearValues.getD(), nearValues.getE()); | ||
// } | ||
// } | ||
// case PLAYER -> { | ||
// if (extra instanceof ServerPlayer serverPlayer) { | ||
// PacketRelay.sendToPlayer(this.getPacketChannel(), this.getSyncPacket(key, this.getSynchableFunctions().get(key).getLeft(), value), serverPlayer); | ||
// } | ||
// } | ||
// case DIMENSION -> { | ||
// if (extra instanceof ResourceKey<?> resourceKey) { | ||
// ResourceKey<Level> dimensionValue = (ResourceKey<Level>) resourceKey; | ||
// PacketRelay.sendToDimension(this.getPacketChannel(), this.getSyncPacket(key, this.getSynchableFunctions().get(key).getLeft(), value), dimensionValue); | ||
// } | ||
// } | ||
// } | ||
// this.getSynchableFunctions().get(key).getMiddle().accept(value); | ||
// } | ||
// | ||
// /** | ||
// * Forces all synchable capability values to sync to the given direction. | ||
// * @param direction The network {@link Direction} to send the packet. | ||
// */ | ||
// default void forceSync(Direction direction) { | ||
// this.forceSync(direction, null); | ||
// } | ||
// | ||
// /** | ||
// * Forces all synchable capability values to sync to the given direction. | ||
// * @param direction The network {@link Direction} to send the packet. | ||
// * @param extra An extra value if necessary. The type of class that needs to be given depends on the direction.<br><br> | ||
// * {@link Direction#SERVER} - None.<br><br> | ||
// * {@link Direction#CLIENT} - None.<br><br> | ||
// * {@link Direction#NEAR} - {@link Quintet}<{@link Double}, {@link Double}, {@link Double}, {@link Double}, {@link ResourceKey}<{@link Level}>>. This represents the 5 values needed for {@link PacketRelay#sendToNear(SimpleChannel, Object, double, double, double, double, ResourceKey)}.<br><br> | ||
// * {@link Direction#PLAYER} - {@link ServerPlayer}.<br><br> | ||
// * {@link Direction#DIMENSION} - {@link ResourceKey}<{@link Level}>>. This represents the dimension to send the packet to. | ||
// */ | ||
// default void forceSync(Direction direction, @Nullable Object extra) { | ||
// for (Map.Entry<String, Triple<Type, Consumer<Object>, Supplier<Object>>> entry : this.getSynchableFunctions().entrySet()) { | ||
// this.setSynched(direction, entry.getKey(), entry.getValue().getRight().get(), extra); | ||
// } | ||
// } | ||
// | ||
// /** | ||
// * @return A {@link Map} of {@link String}s (representing the name of a field), and {@link Triple}s, containing | ||
// * {@link Type}s (representing the data type), | ||
// * {@link Consumer}<{@link Object}>s (representing setter methods), and | ||
// * {@link Supplier}<{@link Object}>s (representing getter methods). | ||
// */ | ||
// Map<String, Triple<Type, Consumer<Object>, Supplier<Object>>> getSynchableFunctions(); | ||
// | ||
// /** | ||
// * Creates the packet used for syncing. | ||
// * @param key The {@link String} key for the field to sync. | ||
// * @param type The {@link Type} for the field's data type. | ||
// * @param value The {@link Object} value to sync to the field. | ||
// * @return The {@link BasePacket} for syncing. | ||
// */ | ||
// BasePacket getSyncPacket(String key, INBTSynchable.Type type, Object value); | ||
// | ||
// /** | ||
// * @return The {@link SimpleChannel} to send the packet through. | ||
// */ | ||
// SimpleChannel getPacketChannel(); | ||
// | ||
// enum Direction { | ||
// SERVER, | ||
// CLIENT, | ||
// NEAR, | ||
// PLAYER, | ||
// DIMENSION | ||
// } | ||
// | ||
// enum Type { | ||
// INT, | ||
// FLOAT, | ||
// DOUBLE, | ||
// BOOLEAN, | ||
// UUID | ||
// } | ||
//} | ||
// todo CARDINAL COMPONENTS | ||
import com.aetherteam.nitrogen.network.BasePacket; | ||
import com.aetherteam.nitrogen.network.PacketRelay; | ||
import io.github.fabricators_of_create.porting_lib.core.util.INBTSerializable; | ||
import io.github.fabricators_of_create.porting_lib.util.ServerLifecycleHooks; | ||
import me.pepperbell.simplenetworking.SimpleChannel; | ||
import net.minecraft.nbt.Tag; | ||
import net.minecraft.resources.ResourceKey; | ||
import net.minecraft.server.level.ServerPlayer; | ||
import net.minecraft.world.level.Level; | ||
import org.apache.commons.lang3.tuple.Triple; | ||
import oshi.util.tuples.Quintet; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
import java.util.Map; | ||
import java.util.function.Consumer; | ||
import java.util.function.Supplier; | ||
|
||
public interface INBTSynchable<T extends Tag> extends INBTSerializable<T> { | ||
/** | ||
* Sets a value to be synced to the given direction. | ||
* @param direction The network {@link Direction} to send the packet. | ||
* @param key The {@link String} key for the field to sync. | ||
* @param value The {@link Object} value to sync to the field. | ||
*/ | ||
default void setSynched(Direction direction, String key, Object value) { | ||
this.setSynched(direction, key, value, null); | ||
} | ||
|
||
/** | ||
* Sets a value to be synced to the given direction.<br><br> | ||
* Warning for "unchecked" is suppressed because casting from wildcards to classes inside type bounds is fine. | ||
* @param direction The network {@link Direction} to send the packet. | ||
* @param key The {@link String} key for the field to sync. | ||
* @param value The {@link Object} value to sync to the field. | ||
* @param extra An extra value if necessary. The type of class that needs to be given depends on the direction.<br><br> | ||
* {@link Direction#SERVER} - None.<br><br> | ||
* {@link Direction#CLIENT} - None.<br><br> | ||
* {@link Direction#NEAR} - {@link Quintet}<{@link Double}, {@link Double}, {@link Double}, {@link Double}, {@link ResourceKey}<{@link Level}>>. This represents the 5 values needed for {@link PacketRelay#sendToNear(SimpleChannel, BasePacket, double, double, double, double, ResourceKey)}.<br><br> | ||
* {@link Direction#PLAYER} - {@link ServerPlayer}.<br><br> | ||
* {@link Direction#DIMENSION} - {@link ResourceKey}<{@link Level}>>. This represents the dimension to send the packet to. | ||
*/ | ||
@SuppressWarnings("unchecked") | ||
default void setSynched(Direction direction, String key, Object value, @Nullable Object extra) { | ||
switch(direction) { | ||
case SERVER -> PacketRelay.sendToServer(this.getPacketChannel(), this.getSyncPacket(key, this.getSynchableFunctions().get(key).getLeft(), value)); | ||
case CLIENT -> PacketRelay.sendToAll(this.getPacketChannel(), this.getSyncPacket(key, this.getSynchableFunctions().get(key).getLeft(), value)); | ||
case NEAR -> { | ||
if (extra instanceof Quintet<?,?,?,?,?> quintet) { | ||
Quintet<Double, Double, Double, Double, ResourceKey<Level>> nearValues = (Quintet<Double, Double, Double, Double, ResourceKey<Level>>) quintet; | ||
PacketRelay.sendToNear(this.getPacketChannel(), this.getSyncPacket(key, this.getSynchableFunctions().get(key).getLeft(), value), nearValues.getA(), nearValues.getB(), nearValues.getC(), nearValues.getD(), nearValues.getE()); | ||
} | ||
} | ||
case PLAYER -> { | ||
if (extra instanceof ServerPlayer serverPlayer) { | ||
PacketRelay.sendToPlayer(this.getPacketChannel(), this.getSyncPacket(key, this.getSynchableFunctions().get(key).getLeft(), value), serverPlayer); | ||
} | ||
} | ||
case DIMENSION -> { | ||
if (extra instanceof ResourceKey<?> resourceKey) { | ||
ResourceKey<Level> dimensionValue = (ResourceKey<Level>) resourceKey; | ||
PacketRelay.sendToDimension(this.getPacketChannel(), this.getSyncPacket(key, this.getSynchableFunctions().get(key).getLeft(), value), dimensionValue); | ||
} | ||
} | ||
} | ||
this.getSynchableFunctions().get(key).getMiddle().accept(value); | ||
} | ||
|
||
/** | ||
* Forces all synchable capability values to sync to the given direction. | ||
* @param direction The network {@link Direction} to send the packet. | ||
*/ | ||
default void forceSync(Direction direction) { | ||
this.forceSync(direction, null); | ||
} | ||
|
||
/** | ||
* Forces all synchable capability values to sync to the given direction. | ||
* @param direction The network {@link Direction} to send the packet. | ||
* @param extra An extra value if necessary. The type of class that needs to be given depends on the direction.<br><br> | ||
* {@link Direction#SERVER} - None.<br><br> | ||
* {@link Direction#CLIENT} - None.<br><br> | ||
* {@link Direction#NEAR} - {@link Quintet}<{@link Double}, {@link Double}, {@link Double}, {@link Double}, {@link ResourceKey}<{@link Level}>>. This represents the 5 values needed for {@link PacketRelay#sendToNear(SimpleChannel, Object, double, double, double, double, ResourceKey)}.<br><br> | ||
* {@link Direction#PLAYER} - {@link ServerPlayer}.<br><br> | ||
* {@link Direction#DIMENSION} - {@link ResourceKey}<{@link Level}>>. This represents the dimension to send the packet to. | ||
*/ | ||
default void forceSync(Direction direction, @Nullable Object extra) { | ||
for (Map.Entry<String, Triple<Type, Consumer<Object>, Supplier<Object>>> entry : this.getSynchableFunctions().entrySet()) { | ||
this.setSynched(direction, entry.getKey(), entry.getValue().getRight().get(), extra); | ||
} | ||
} | ||
|
||
/** | ||
* @return A {@link Map} of {@link String}s (representing the name of a field), and {@link Triple}s, containing | ||
* {@link Type}s (representing the data type), | ||
* {@link Consumer}<{@link Object}>s (representing setter methods), and | ||
* {@link Supplier}<{@link Object}>s (representing getter methods). | ||
*/ | ||
Map<String, Triple<Type, Consumer<Object>, Supplier<Object>>> getSynchableFunctions(); | ||
|
||
/** | ||
* Creates the packet used for syncing. | ||
* @param key The {@link String} key for the field to sync. | ||
* @param type The {@link Type} for the field's data type. | ||
* @param value The {@link Object} value to sync to the field. | ||
* @return The {@link BasePacket} for syncing. | ||
*/ | ||
BasePacket getSyncPacket(String key, INBTSynchable.Type type, Object value); | ||
|
||
/** | ||
* @return The {@link SimpleChannel} to send the packet through. | ||
*/ | ||
SimpleChannel getPacketChannel(); | ||
|
||
enum Direction { | ||
SERVER, | ||
CLIENT, | ||
NEAR, | ||
PLAYER, | ||
DIMENSION | ||
} | ||
|
||
enum Type { | ||
INT, | ||
FLOAT, | ||
DOUBLE, | ||
BOOLEAN, | ||
UUID | ||
} | ||
} |
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.