1
1
package net .modfest .scatteredshards .networking ;
2
2
3
- import me .lucko .fabric .api .permissions .v0 .Permissions ;
4
3
import net .fabricmc .fabric .api .networking .v1 .ServerPlayNetworking ;
4
+ import net .minecraft .item .ItemStack ;
5
5
import net .minecraft .network .RegistryByteBuf ;
6
6
import net .minecraft .network .codec .PacketCodec ;
7
7
import net .minecraft .network .packet .CustomPayload ;
8
- import net .minecraft .server .MinecraftServer ;
9
- import net .minecraft .server .network .ServerPlayerEntity ;
10
8
import net .minecraft .util .Identifier ;
11
9
import net .modfest .scatteredshards .ScatteredShards ;
12
10
import net .modfest .scatteredshards .api .ScatteredShardsAPI ;
13
- import net .modfest .scatteredshards .api .impl . ShardLibraryPersistentState ;
11
+ import net .modfest .scatteredshards .api .ShardLibrary ;
14
12
import net .modfest .scatteredshards .api .shard .Shard ;
15
13
import net .modfest .scatteredshards .block .ShardBlock ;
16
14
@@ -22,36 +20,16 @@ public record C2SCreateShardInstant(Identifier shardId, Shard shard) implements
22
20
public static final PacketCodec <RegistryByteBuf , C2SCreateShardInstant > PACKET_CODEC = PacketCodec .tuple (Identifier .PACKET_CODEC , C2SCreateShardInstant ::shardId , Shard .PACKET_CODEC , C2SCreateShardInstant ::shard , C2SCreateShardInstant ::new );
23
21
24
22
public static void receive (C2SCreateShardInstant payload , ServerPlayNetworking .Context context ) {
25
- // TODO: This is mostly identical to C2SModifyShard, no need for so much duplicate code
23
+ boolean success = C2SModifyShard . modify ( context . player (), payload . shardId , payload . shard );
26
24
27
- MinecraftServer server = context . player (). getServer ();
28
- server . execute (() -> {
29
- boolean success = server . isSingleplayer () || Permissions . check ( context . player (), ScatteredShardsAPI . MODIFY_SHARD_PERMISSION , 1 );
25
+ if (! success ) {
26
+ return ;
27
+ }
30
28
31
- //Let the sender know of success or failure before a shard update comes through
32
- ServerPlayNetworking .send (context .player (), new S2CModifyShardResult (payload .shardId (), success ));
29
+ ShardLibrary library = ScatteredShardsAPI .getServerLibrary ();
33
30
34
- if (!success ) {
35
- return ;
36
- }
37
-
38
- //Update our serverside library
39
- var library = ScatteredShardsAPI .getServerLibrary ();
40
- library .shards ().put (payload .shardId (), payload .shard ());
41
- library .shardSets ().put (payload .shard ().sourceId (), payload .shardId ());
42
-
43
- //Make sure the NBT gets written on next world-save
44
- ShardLibraryPersistentState .get (server ).markDirty ();
45
-
46
- //Update everyone's client libraries with the new shard
47
- S2CSyncShard syncShard = new S2CSyncShard (payload .shardId (), payload .shard ());
48
- for (ServerPlayerEntity otherPlayer : server .getPlayerManager ().getPlayerList ()) {
49
- ServerPlayNetworking .send (otherPlayer , syncShard );
50
- }
51
-
52
- var itemStack = ShardBlock .createShardBlock (library , payload .shardId (), false , 0.5f , 0.5f );
53
- context .player ().getInventory ().offerOrDrop (itemStack );
54
- });
31
+ ItemStack itemStack = ShardBlock .createShardBlock (library , payload .shardId (), false , 0.5f , 0.5f );
32
+ context .player ().getInventory ().offerOrDrop (itemStack );
55
33
}
56
34
57
35
@ Override
0 commit comments