1
1
package com .github .alexthe666 .iceandfire .entity .tile ;
2
2
3
- import java .util .UUID ;
4
- import java .util .concurrent .ThreadLocalRandom ;
5
-
6
- import javax .annotation .Nullable ;
7
-
8
3
import com .github .alexthe666 .iceandfire .IafConfig ;
9
4
import com .github .alexthe666 .iceandfire .entity .EntityDragonEgg ;
10
5
import com .github .alexthe666 .iceandfire .entity .EntityIceDragon ;
11
6
import com .github .alexthe666 .iceandfire .entity .IafEntityRegistry ;
12
7
import com .github .alexthe666 .iceandfire .enums .EnumDragonEgg ;
13
-
14
8
import net .minecraft .block .BlockState ;
15
9
import net .minecraft .block .Blocks ;
16
10
import net .minecraft .nbt .CompoundNBT ;
20
14
import net .minecraft .tileentity .ITickableTileEntity ;
21
15
import net .minecraft .tileentity .TileEntity ;
22
16
17
+ import javax .annotation .Nullable ;
18
+ import java .util .UUID ;
19
+ import java .util .concurrent .ThreadLocalRandom ;
20
+
23
21
public class TileEntityEggInIce extends TileEntity implements ITickableTileEntity {
24
22
public EnumDragonEgg type ;
25
23
public int age ;
@@ -35,6 +33,7 @@ public TileEntityEggInIce() {
35
33
36
34
@ Override
37
35
public CompoundNBT write (CompoundNBT tag ) {
36
+ super .write (tag );
38
37
if (type != null ) {
39
38
tag .putByte ("Color" , (byte ) type .ordinal ());
40
39
} else {
@@ -44,43 +43,58 @@ public CompoundNBT write(CompoundNBT tag) {
44
43
if (ownerUUID == null ) {
45
44
tag .putString ("OwnerUUID" , "" );
46
45
} else {
47
- tag .putString ("OwnerUUID" , ownerUUID . toString () );
46
+ tag .putUniqueId ("OwnerUUID" , ownerUUID );
48
47
}
49
-
50
- return super .write (tag );
48
+ return tag ;
51
49
}
52
50
53
51
@ Override
54
52
public void read (BlockState state , CompoundNBT tag ) {
55
53
super .read (state ,tag );
56
54
type = EnumDragonEgg .values ()[tag .getByte ("Color" )];
57
- age = tag .getByte ("Age" );
58
- UUID s ;
55
+ age = tag .getInt ("Age" );
56
+ UUID s = null ;
59
57
60
58
if (tag .hasUniqueId ("OwnerUUID" )) {
61
59
s = tag .getUniqueId ("OwnerUUID" );
62
60
} else {
63
- String s1 = tag .getString ("OwnerUUID" );
64
- s = PreYggdrasilConverter .convertMobOwnerIfNeeded (this .world .getServer (), s1 );
61
+ try {
62
+ String s1 = tag .getString ("OwnerUUID" );
63
+ s = PreYggdrasilConverter .convertMobOwnerIfNeeded (this .world .getServer (), s1 );
64
+ }
65
+ catch (Exception ignored ) { }
65
66
}
66
67
if (s != null ) {
67
68
ownerUUID = s ;
68
69
}
69
70
}
70
71
71
72
@ Override
72
- public SUpdateTileEntityPacket getUpdatePacket () {
73
- return new SUpdateTileEntityPacket (pos , 1 , getUpdateTag ());
73
+ public void handleUpdateTag (BlockState blockState , CompoundNBT parentNBTTagCompound )
74
+ {
75
+ this .read (blockState , parentNBTTagCompound );
76
+ }
77
+
78
+ public CompoundNBT getUpdateTag ()
79
+ {
80
+ CompoundNBT nbtTagCompound = new CompoundNBT ();
81
+ write (nbtTagCompound );
82
+ return nbtTagCompound ;
74
83
}
75
84
76
85
@ Override
77
- public void onDataPacket (NetworkManager net , SUpdateTileEntityPacket packet ) {
78
- read (this .getBlockState (), packet .getNbtCompound ());
86
+ @ Nullable
87
+ public SUpdateTileEntityPacket getUpdatePacket ()
88
+ {
89
+ CompoundNBT nbtTagCompound = new CompoundNBT ();
90
+ write (nbtTagCompound );
91
+ return new SUpdateTileEntityPacket (this .pos , -1 , nbtTagCompound );
79
92
}
80
93
81
94
@ Override
82
- public CompoundNBT getUpdateTag () {
83
- return this .write (new CompoundNBT ());
95
+ public void onDataPacket (NetworkManager net , SUpdateTileEntityPacket pkt ) {
96
+ BlockState blockState = world .getBlockState (pos );
97
+ read (blockState , pkt .getNbtCompound ()); // read from the nbt in the packet
84
98
}
85
99
86
100
public void spawnEgg () {
@@ -99,18 +113,18 @@ public void spawnEgg() {
99
113
public void tick () {
100
114
age ++;
101
115
if (age >= IafConfig .dragonEggTime && type != null && !spawned ) {
102
- world .destroyBlock (pos , false );
103
- world .setBlockState (pos , Blocks .WATER .getDefaultState ());
104
- EntityIceDragon dragon = new EntityIceDragon (world );
105
- dragon .setPosition (pos .getX () + 0.5 , pos .getY () + 1 , pos .getZ () + 0.5 );
106
- dragon .setVariant (type .ordinal () - 4 );
107
- dragon .setGender (ThreadLocalRandom .current ().nextBoolean ());
108
- dragon .setTamed (true );
109
- dragon .setHunger (50 );
110
- dragon .setOwnerId (ownerUUID );
111
116
if (!world .isRemote ) {
117
+ EntityIceDragon dragon = new EntityIceDragon (world );
118
+ dragon .setPosition (pos .getX () + 0.5 , pos .getY () + 1 , pos .getZ () + 0.5 );
119
+ dragon .setVariant (type .ordinal () - 4 );
120
+ dragon .setGender (ThreadLocalRandom .current ().nextBoolean ());
121
+ dragon .setTamed (true );
122
+ dragon .setHunger (50 );
123
+ dragon .setOwnerId (ownerUUID );
112
124
world .addEntity (dragon );
113
125
spawned = true ;
126
+ world .destroyBlock (pos , false );
127
+ world .setBlockState (pos , Blocks .WATER .getDefaultState ());
114
128
}
115
129
116
130
}
0 commit comments