4
4
import cn .zbx1425 .minopp .block .BlockEntityMinoTable ;
5
5
import cn .zbx1425 .minopp .block .BlockMinoTable ;
6
6
import cn .zbx1425 .minopp .game .*;
7
+ import cn .zbx1425 .minopp .gui .AutoPlayerScreen ;
7
8
import cn .zbx1425 .minopp .item .ItemHandCards ;
9
+ import cn .zbx1425 .minopp .network .S2CAutoPlayerScreenPacket ;
8
10
import com .mojang .authlib .GameProfile ;
11
+ import net .minecraft .client .Minecraft ;
9
12
import net .minecraft .commands .arguments .EntityAnchorArgument ;
10
13
import net .minecraft .core .BlockPos ;
11
14
import net .minecraft .core .NonNullList ;
12
15
import net .minecraft .nbt .CompoundTag ;
13
16
import net .minecraft .network .syncher .EntityDataAccessor ;
14
17
import net .minecraft .network .syncher .EntityDataSerializers ;
15
18
import net .minecraft .network .syncher .SynchedEntityData ;
19
+ import net .minecraft .world .InteractionHand ;
20
+ import net .minecraft .world .InteractionResult ;
16
21
import net .minecraft .world .damagesource .DamageSource ;
17
22
import net .minecraft .world .entity .EntityType ;
18
23
import net .minecraft .world .entity .EquipmentSlot ;
28
33
import net .minecraft .world .level .block .state .BlockState ;
29
34
import net .minecraft .world .phys .Vec3 ;
30
35
import org .jetbrains .annotations .NotNull ;
36
+ import net .minecraft .server .level .ServerPlayer ;
31
37
32
38
import java .util .List ;
33
39
import java .util .Optional ;
@@ -52,7 +58,7 @@ public EntityAutoPlayer(EntityType<? extends LivingEntity> entityType, Level lev
52
58
private long thinkingFinishTime = 0 ;
53
59
private long gameEndTime = 0 ;
54
60
55
- private final AutoPlayer autoPlayer = new AutoPlayer ();
61
+ public final AutoPlayer autoPlayer = new AutoPlayer ();
56
62
57
63
public CompletableFuture <Optional <GameProfile >> clientSkinGameProfile = CompletableFuture .completedFuture (Optional .empty ());
58
64
public String clientSkinGameProfileValidFor = "" ;
@@ -198,6 +204,21 @@ public boolean hurt(DamageSource source, float amount) {
198
204
return super .hurt (source , amount );
199
205
}
200
206
207
+ @ Override
208
+ public @ NotNull InteractionResult interact (Player player , InteractionHand hand ) {
209
+ if (level ().isClientSide ) {
210
+ if (player .hasPermissions (2 ) && player .isShiftKeyDown ()) {
211
+ return InteractionResult .SUCCESS ;
212
+ }
213
+ } else {
214
+ if (player instanceof ServerPlayer serverPlayer && player .hasPermissions (2 ) && player .isShiftKeyDown ()) {
215
+ S2CAutoPlayerScreenPacket .sendS2C (serverPlayer , this );
216
+ return InteractionResult .SUCCESS ;
217
+ }
218
+ }
219
+ return super .interact (player , hand );
220
+ }
221
+
201
222
@ Override
202
223
public @ NotNull Iterable <ItemStack > getArmorSlots () {
203
224
return armorItems ;
@@ -233,16 +254,7 @@ public void addAdditionalSaveData(CompoundTag compound) {
233
254
if (tablePos != null ) compound .putLong ("TablePos" , tablePos .asLong ());
234
255
if (cardPlayer != null ) compound .put ("CardPlayer" , cardPlayer .toTag ());
235
256
if (!entityData .get (HAND_STACK ).isEmpty ()) compound .put ("HandStack" , entityData .get (HAND_STACK ).save (level ().registryAccess (), new CompoundTag ()));
236
- compound .putBoolean ("Active" , entityData .get (ACTIVE ));
237
- compound .putString ("Skin" , entityData .get (SKIN ));
238
- CompoundTag aiConfig = new CompoundTag ();
239
- aiConfig .putBoolean ("NoWin" , autoPlayer .aiNoWin );
240
- aiConfig .putBoolean ("NoPlayerDraw" , autoPlayer .aiNoPlayerDraw );
241
- aiConfig .putBoolean ("NoForget" , autoPlayer .aiNoForget );
242
- aiConfig .putByte ("NoDelay" , autoPlayer .aiNoDelay );
243
- aiConfig .putBoolean ("StartGame" , autoPlayer .aiStartGame );
244
- compound .put ("AI" , aiConfig );
245
- if (noPush ) compound .putBoolean ("NoPush" , true );
257
+ writeConfigToTag (compound ); // Write config values directly to maintain backward compatibility
246
258
}
247
259
248
260
@ Override
@@ -258,23 +270,7 @@ public void readAdditionalSaveData(CompoundTag compound) {
258
270
} else {
259
271
cardPlayer = null ;
260
272
}
261
- if (compound .contains ("Active" , CompoundTag .TAG_BYTE )) {
262
- entityData .set (ACTIVE , compound .getBoolean ("Active" ));
263
- }
264
- if (compound .contains ("Skin" , CompoundTag .TAG_STRING )) {
265
- entityData .set (SKIN , compound .getString ("Skin" ));
266
- }
267
- if (compound .contains ("AI" , CompoundTag .TAG_COMPOUND )) {
268
- CompoundTag aiConfig = compound .getCompound ("AI" );
269
- autoPlayer .aiNoWin = aiConfig .getBoolean ("NoWin" );
270
- autoPlayer .aiNoPlayerDraw = aiConfig .getBoolean ("NoPlayerDraw" );
271
- autoPlayer .aiNoForget = aiConfig .getBoolean ("NoForget" );
272
- autoPlayer .aiNoDelay = aiConfig .getByte ("NoDelay" );
273
- autoPlayer .aiStartGame = aiConfig .getBoolean ("StartGame" );
274
- }
275
- if (compound .contains ("NoPush" , CompoundTag .TAG_BYTE )) {
276
- noPush = compound .getBoolean ("NoPush" );
277
- }
273
+ readConfigFromTag (compound ); // Read config values directly from root tag
278
274
279
275
// Try fix hand stack
280
276
if (tablePos != null && cardPlayer != null ) {
@@ -308,5 +304,56 @@ public static AttributeSupplier createAttributes() {
308
304
.add (Attributes .KNOCKBACK_RESISTANCE , 1.0D )
309
305
.build ();
310
306
}
307
+
308
+ public boolean getActive () {
309
+ return entityData .get (ACTIVE );
310
+ }
311
+
312
+ public void setActive (boolean active ) {
313
+ entityData .set (ACTIVE , active );
314
+ }
315
+
316
+ public boolean getNoPush () {
317
+ return noPush ;
318
+ }
319
+
320
+ public void setNoPush (boolean noPush ) {
321
+ this .noPush = noPush ;
322
+ }
323
+
324
+ public String getSkin () {
325
+ return entityData .get (SKIN );
326
+ }
327
+
328
+ public void setSkin (String skin ) {
329
+ entityData .set (SKIN , skin );
330
+ }
331
+
332
+ public CompoundTag writeConfigToTag () {
333
+ CompoundTag tag = new CompoundTag ();
334
+ writeConfigToTag (tag );
335
+ return tag ;
336
+ }
337
+
338
+ public void writeConfigToTag (CompoundTag tag ) {
339
+ tag .putBoolean ("Active" , getActive ());
340
+ tag .putBoolean ("NoPush" , getNoPush ());
341
+ tag .putString ("Skin" , getSkin ());
342
+ tag .put ("AI" , autoPlayer .toConfigNbt ());
343
+ }
344
+
345
+ public void readConfigFromTag (CompoundTag tag ) {
346
+ setActive (tag .getBoolean ("Active" ));
347
+ setNoPush (tag .getBoolean ("NoPush" ));
348
+ setSkin (tag .getString ("Skin" ));
349
+ autoPlayer .useConfigNbt (tag .getCompound ("AI" ));
350
+ }
351
+
352
+ private static class Client {
353
+
354
+ public static void openAutoPlayerScreen (EntityAutoPlayer autoPlayer ) {
355
+ Minecraft .getInstance ().setScreen (AutoPlayerScreen .create (autoPlayer , Minecraft .getInstance ().screen ));
356
+ }
357
+ }
311
358
}
312
359
0 commit comments