|
1 | 1 | package com.aetherteam.nitrogen.attachment;
|
2 | 2 |
|
3 |
| -import com.aetherteam.nitrogen.network.packet.SyncPacket; |
4 |
| -import net.minecraft.network.protocol.common.custom.CustomPacketPayload; |
5 |
| -import net.minecraft.resources.ResourceKey; |
6 |
| -import net.minecraft.server.level.ServerLevel; |
7 |
| -import net.minecraft.server.level.ServerPlayer; |
8 |
| -import net.minecraft.world.level.Level; |
9 |
| -import net.neoforged.neoforge.network.PacketDistributor; |
10 |
| -import org.apache.commons.lang3.tuple.Triple; |
11 |
| -import oshi.util.tuples.Quintet; |
12 |
| - |
13 |
| -import javax.annotation.Nullable; |
14 |
| -import java.util.Map; |
15 |
| -import java.util.function.Consumer; |
16 |
| -import java.util.function.Supplier; |
17 |
| - |
18 |
| -public interface INBTSynchable { |
19 |
| - /** |
20 |
| - * Sets a value to be synced to the given direction. |
21 |
| - * |
22 |
| - * @param direction The network {@link Direction} to send the packet. |
23 |
| - * @param key The {@link String} key for the field to sync. |
24 |
| - * @param value The {@link Object} value to sync to the field. |
25 |
| - */ |
26 |
| - default void setSynched(int entityID, Direction direction, String key, Object value) { |
27 |
| - this.setSynched(entityID, direction, key, value, null); |
28 |
| - } |
29 |
| - |
30 |
| - /** |
31 |
| - * Sets a value to be synced to the given direction.<br><br> |
32 |
| - * Warning for "unchecked" is suppressed because casting from wildcards to classes inside type bounds is fine. |
33 |
| - * |
34 |
| - * @param direction The network {@link Direction} to send the packet. |
35 |
| - * @param key The {@link String} key for the field to sync. |
36 |
| - * @param value The {@link Object} value to sync to the field. |
37 |
| - * @param extra An extra value if necessary. The type of class that needs to be given depends on the direction.<br><br> |
38 |
| - * {@link Direction#SERVER} - None.<br><br> |
39 |
| - * {@link Direction#CLIENT} - None.<br><br> |
40 |
| - * {@link Direction#NEAR} - {@link Quintet}<{@link Double}, {@link Double}, {@link Double}, {@link Double}, {@link ServerLevel}>. This represents the 5 values needed for {@link PacketExecution#sendToNear(CustomPacketPayload, double, double, double, double, ResourceKey)}.<br><br> |
41 |
| - * {@link Direction#PLAYER} - {@link ServerPlayer}.<br><br> |
42 |
| - * {@link Direction#DIMENSION} - {@link ResourceKey}<{@link Level}>>. This represents the dimension to send the packet to. |
43 |
| - */ |
44 |
| - @SuppressWarnings("unchecked") |
45 |
| - default void setSynched(int entityID, Direction direction, String key, Object value, @Nullable Object extra) { |
46 |
| - switch (direction) { |
47 |
| - case SERVER -> |
48 |
| - PacketDistributor.sendToServer(this.getSyncPacket(entityID, key, this.getSynchableFunctions().get(key).getLeft(), value)); |
49 |
| - case CLIENT -> |
50 |
| - PacketDistributor.sendToAllPlayers(this.getSyncPacket(entityID, key, this.getSynchableFunctions().get(key).getLeft(), value)); |
51 |
| - case NEAR -> { |
52 |
| - if (extra instanceof Quintet<?, ?, ?, ?, ?> quintet) { |
53 |
| - Quintet<Double, Double, Double, Double, ServerLevel> nearValues = (Quintet<Double, Double, Double, Double, ServerLevel>) quintet; |
54 |
| - PacketDistributor.sendToPlayersNear(nearValues.getE(), null, nearValues.getA(), nearValues.getB(), nearValues.getC(), nearValues.getD(), this.getSyncPacket(entityID, key, this.getSynchableFunctions().get(key).getLeft(), value)); |
55 |
| - } |
56 |
| - } |
57 |
| - case PLAYER -> { |
58 |
| - if (extra instanceof ServerPlayer serverPlayer) { |
59 |
| - PacketDistributor.sendToPlayer(serverPlayer, this.getSyncPacket(entityID, key, this.getSynchableFunctions().get(key).getLeft(), value)); |
60 |
| - } |
61 |
| - } |
62 |
| - case DIMENSION -> { |
63 |
| - if (extra instanceof ServerLevel serverLevel) { |
64 |
| - PacketDistributor.sendToPlayersInDimension(serverLevel, this.getSyncPacket(entityID, key, this.getSynchableFunctions().get(key).getLeft(), value)); |
65 |
| - } |
66 |
| - } |
67 |
| - } |
68 |
| - this.getSynchableFunctions().get(key).getMiddle().accept(value); |
69 |
| - } |
70 |
| - |
71 |
| - /** |
72 |
| - * Forces all synchable capability values to sync to the given direction. |
73 |
| - * |
74 |
| - * @param direction The network {@link Direction} to send the packet. |
75 |
| - */ |
76 |
| - default void forceSync(int entityID, Direction direction) { |
77 |
| - this.forceSync(entityID, direction, null); |
78 |
| - } |
79 |
| - |
80 |
| - /** |
81 |
| - * Forces all synchable capability values to sync to the given direction. |
82 |
| - * |
83 |
| - * @param direction The network {@link Direction} to send the packet. |
84 |
| - * @param extra An extra value if necessary. The type of class that needs to be given depends on the direction.<br><br> |
85 |
| - * {@link Direction#SERVER} - None.<br><br> |
86 |
| - * {@link Direction#CLIENT} - None.<br><br> |
87 |
| - * {@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 PacketExecution#sendToNear(CustomPacketPayload, double, double, double, double, ResourceKey)}.<br><br> |
88 |
| - * {@link Direction#PLAYER} - {@link ServerPlayer}.<br><br> |
89 |
| - * {@link Direction#DIMENSION} - {@link ResourceKey}<{@link Level}>>. This represents the dimension to send the packet to. |
90 |
| - */ |
91 |
| - default void forceSync(int entityID, Direction direction, @Nullable Object extra) { |
92 |
| - for (Map.Entry<String, Triple<Type, Consumer<Object>, Supplier<Object>>> entry : this.getSynchableFunctions().entrySet()) { |
93 |
| - this.setSynched(entityID, direction, entry.getKey(), entry.getValue().getRight().get(), extra); |
94 |
| - } |
95 |
| - } |
96 |
| - |
97 |
| - /** |
98 |
| - * @return A {@link Map} of {@link String}s (representing the name of a field), and {@link Triple}s, containing |
99 |
| - * {@link Type}s (representing the data type), |
100 |
| - * {@link Consumer}<{@link Object}>s (representing setter methods), and |
101 |
| - * {@link Supplier}<{@link Object}>s (representing getter methods). |
102 |
| - */ |
103 |
| - Map<String, Triple<Type, Consumer<Object>, Supplier<Object>>> getSynchableFunctions(); |
104 |
| - |
105 |
| - /** |
106 |
| - * Creates the packet used for syncing. |
107 |
| - * |
108 |
| - * @param key The {@link String} key for the field to sync. |
109 |
| - * @param type The {@link Type} for the field's data type. |
110 |
| - * @param value The {@link Object} value to sync to the field. |
111 |
| - * @return The {@link SyncPacket} for syncing. |
112 |
| - */ |
113 |
| - SyncPacket getSyncPacket(int entityID, String key, INBTSynchable.Type type, Object value); |
114 |
| - |
115 |
| - enum Direction { |
116 |
| - SERVER, |
117 |
| - CLIENT, |
118 |
| - NEAR, |
119 |
| - PLAYER, |
120 |
| - DIMENSION |
121 |
| - } |
122 |
| - |
123 |
| - enum Type { |
124 |
| - INT, |
125 |
| - FLOAT, |
126 |
| - DOUBLE, |
127 |
| - BOOLEAN, |
128 |
| - UUID, |
129 |
| - ITEM_STACK, |
130 |
| - COMPOUND_TAG |
131 |
| - } |
132 |
| -} |
| 3 | +//import com.aetherteam.nitrogen.network.packet.SyncPacket; |
| 4 | +//import net.minecraft.network.protocol.common.custom.CustomPacketPayload; |
| 5 | +//import net.minecraft.resources.ResourceKey; |
| 6 | +//import net.minecraft.server.level.ServerLevel; |
| 7 | +//import net.minecraft.server.level.ServerPlayer; |
| 8 | +//import net.minecraft.world.level.Level; |
| 9 | +//import net.neoforged.neoforge.network.PacketDistributor; |
| 10 | +//import org.apache.commons.lang3.tuple.Triple; |
| 11 | +//import oshi.util.tuples.Quintet; |
| 12 | +// |
| 13 | +//import javax.annotation.Nullable; |
| 14 | +//import java.util.Map; |
| 15 | +//import java.util.function.Consumer; |
| 16 | +//import java.util.function.Supplier; |
| 17 | +// |
| 18 | +//public interface INBTSynchable { |
| 19 | +// /** |
| 20 | +// * Sets a value to be synced to the given direction. |
| 21 | +// * |
| 22 | +// * @param direction The network {@link Direction} to send the packet. |
| 23 | +// * @param key The {@link String} key for the field to sync. |
| 24 | +// * @param value The {@link Object} value to sync to the field. |
| 25 | +// */ |
| 26 | +// default void setSynched(int entityID, Direction direction, String key, Object value) { |
| 27 | +// this.setSynched(entityID, direction, key, value, null); |
| 28 | +// } |
| 29 | +// |
| 30 | +// /** |
| 31 | +// * Sets a value to be synced to the given direction.<br><br> |
| 32 | +// * Warning for "unchecked" is suppressed because casting from wildcards to classes inside type bounds is fine. |
| 33 | +// * |
| 34 | +// * @param direction The network {@link Direction} to send the packet. |
| 35 | +// * @param key The {@link String} key for the field to sync. |
| 36 | +// * @param value The {@link Object} value to sync to the field. |
| 37 | +// * @param extra An extra value if necessary. The type of class that needs to be given depends on the direction.<br><br> |
| 38 | +// * {@link Direction#SERVER} - None.<br><br> |
| 39 | +// * {@link Direction#CLIENT} - None.<br><br> |
| 40 | +// * {@link Direction#NEAR} - {@link Quintet}<{@link Double}, {@link Double}, {@link Double}, {@link Double}, {@link ServerLevel}>. This represents the 5 values needed for {@link PacketExecution#sendToNear(CustomPacketPayload, double, double, double, double, ResourceKey)}.<br><br> |
| 41 | +// * {@link Direction#PLAYER} - {@link ServerPlayer}.<br><br> |
| 42 | +// * {@link Direction#DIMENSION} - {@link ResourceKey}<{@link Level}>>. This represents the dimension to send the packet to. |
| 43 | +// */ |
| 44 | +// @SuppressWarnings("unchecked") |
| 45 | +// default void setSynched(int entityID, Direction direction, String key, Object value, @Nullable Object extra) { |
| 46 | +// switch (direction) { |
| 47 | +// case SERVER -> |
| 48 | +// PacketDistributor.sendToServer(this.getSyncPacket(entityID, key, this.getSynchableFunctions().get(key).getLeft(), value)); |
| 49 | +// case CLIENT -> |
| 50 | +// PacketDistributor.sendToAllPlayers(this.getSyncPacket(entityID, key, this.getSynchableFunctions().get(key).getLeft(), value)); |
| 51 | +// case NEAR -> { |
| 52 | +// if (extra instanceof Quintet<?, ?, ?, ?, ?> quintet) { |
| 53 | +// Quintet<Double, Double, Double, Double, ServerLevel> nearValues = (Quintet<Double, Double, Double, Double, ServerLevel>) quintet; |
| 54 | +// PacketDistributor.sendToPlayersNear(nearValues.getE(), null, nearValues.getA(), nearValues.getB(), nearValues.getC(), nearValues.getD(), this.getSyncPacket(entityID, key, this.getSynchableFunctions().get(key).getLeft(), value)); |
| 55 | +// } |
| 56 | +// } |
| 57 | +// case PLAYER -> { |
| 58 | +// if (extra instanceof ServerPlayer serverPlayer) { |
| 59 | +// PacketDistributor.sendToPlayer(serverPlayer, this.getSyncPacket(entityID, key, this.getSynchableFunctions().get(key).getLeft(), value)); |
| 60 | +// } |
| 61 | +// } |
| 62 | +// case DIMENSION -> { |
| 63 | +// if (extra instanceof ServerLevel serverLevel) { |
| 64 | +// PacketDistributor.sendToPlayersInDimension(serverLevel, this.getSyncPacket(entityID, key, this.getSynchableFunctions().get(key).getLeft(), value)); |
| 65 | +// } |
| 66 | +// } |
| 67 | +// } |
| 68 | +// this.getSynchableFunctions().get(key).getMiddle().accept(value); |
| 69 | +// } |
| 70 | +// |
| 71 | +// /** |
| 72 | +// * Forces all synchable capability values to sync to the given direction. |
| 73 | +// * |
| 74 | +// * @param direction The network {@link Direction} to send the packet. |
| 75 | +// */ |
| 76 | +// default void forceSync(int entityID, Direction direction) { |
| 77 | +// this.forceSync(entityID, direction, null); |
| 78 | +// } |
| 79 | +// |
| 80 | +// /** |
| 81 | +// * Forces all synchable capability values to sync to the given direction. |
| 82 | +// * |
| 83 | +// * @param direction The network {@link Direction} to send the packet. |
| 84 | +// * @param extra An extra value if necessary. The type of class that needs to be given depends on the direction.<br><br> |
| 85 | +// * {@link Direction#SERVER} - None.<br><br> |
| 86 | +// * {@link Direction#CLIENT} - None.<br><br> |
| 87 | +// * {@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 PacketExecution#sendToNear(CustomPacketPayload, double, double, double, double, ResourceKey)}.<br><br> |
| 88 | +// * {@link Direction#PLAYER} - {@link ServerPlayer}.<br><br> |
| 89 | +// * {@link Direction#DIMENSION} - {@link ResourceKey}<{@link Level}>>. This represents the dimension to send the packet to. |
| 90 | +// */ |
| 91 | +// default void forceSync(int entityID, Direction direction, @Nullable Object extra) { |
| 92 | +// for (Map.Entry<String, Triple<Type, Consumer<Object>, Supplier<Object>>> entry : this.getSynchableFunctions().entrySet()) { |
| 93 | +// this.setSynched(entityID, direction, entry.getKey(), entry.getValue().getRight().get(), extra); |
| 94 | +// } |
| 95 | +// } |
| 96 | +// |
| 97 | +// /** |
| 98 | +// * @return A {@link Map} of {@link String}s (representing the name of a field), and {@link Triple}s, containing |
| 99 | +// * {@link Type}s (representing the data type), |
| 100 | +// * {@link Consumer}<{@link Object}>s (representing setter methods), and |
| 101 | +// * {@link Supplier}<{@link Object}>s (representing getter methods). |
| 102 | +// */ |
| 103 | +// Map<String, Triple<Type, Consumer<Object>, Supplier<Object>>> getSynchableFunctions(); |
| 104 | +// |
| 105 | +// /** |
| 106 | +// * Creates the packet used for syncing. |
| 107 | +// * |
| 108 | +// * @param key The {@link String} key for the field to sync. |
| 109 | +// * @param type The {@link Type} for the field's data type. |
| 110 | +// * @param value The {@link Object} value to sync to the field. |
| 111 | +// * @return The {@link SyncPacket} for syncing. |
| 112 | +// */ |
| 113 | +// SyncPacket getSyncPacket(int entityID, String key, INBTSynchable.Type type, Object value); |
| 114 | +// |
| 115 | +// enum Direction { |
| 116 | +// SERVER, |
| 117 | +// CLIENT, |
| 118 | +// NEAR, |
| 119 | +// PLAYER, |
| 120 | +// DIMENSION |
| 121 | +// } |
| 122 | +// |
| 123 | +// enum Type { |
| 124 | +// INT, |
| 125 | +// FLOAT, |
| 126 | +// DOUBLE, |
| 127 | +// BOOLEAN, |
| 128 | +// UUID, |
| 129 | +// ITEM_STACK, |
| 130 | +// COMPOUND_TAG |
| 131 | +// } |
| 132 | +//} |
0 commit comments