6
6
import net .minecraft .network .syncher .EntityDataAccessor ;
7
7
import net .minecraft .network .syncher .EntityDataSerializers ;
8
8
import net .minecraft .network .syncher .SynchedEntityData ;
9
- import net .minecraft .world . DifficultyInstance ;
9
+ import net .minecraft .server . level . ServerLevel ;
10
10
import net .minecraft .world .InteractionHand ;
11
11
import net .minecraft .world .InteractionResult ;
12
12
import net .minecraft .world .damagesource .DamageSource ;
18
18
import net .minecraft .world .entity .ai .navigation .FlyingPathNavigation ;
19
19
import net .minecraft .world .entity .ai .navigation .PathNavigation ;
20
20
import net .minecraft .world .entity .ambient .AmbientCreature ;
21
+ import net .minecraft .world .entity .animal .Animal ;
21
22
import net .minecraft .world .entity .animal .FlyingAnimal ;
22
23
import net .minecraft .world .entity .player .Player ;
24
+ import net .minecraft .world .item .ItemStack ;
23
25
import net .minecraft .world .level .Level ;
24
- import net .minecraft .world .level .ServerLevelAccessor ;
25
26
import net .minecraft .world .level .block .state .BlockState ;
26
27
import org .jetbrains .annotations .NotNull ;
27
28
import org .jetbrains .annotations .Nullable ;
28
- import org .polaris_bear .wild_wind .WildWindConfig ;
29
+ import org .polaris_bear .wild_wind .WildWindMod ;
29
30
import org .polaris_bear .wild_wind .common .entity .goal .FireflyBaseGoal ;
30
31
import org .polaris_bear .wild_wind .common .entity .goal .FireflyFlyGoal ;
31
32
import org .polaris_bear .wild_wind .common .entity .goal .FireflyRoostGoal ;
33
+ import org .polaris_bear .wild_wind .common .entity .goal .FireflyGlowGoal ;
34
+ import org .polaris_bear .wild_wind .common .init .ModEntities ;
35
+ import org .polaris_bear .wild_wind .common .init .tags .ModItemTags ;
32
36
import software .bernie .geckolib .animatable .GeoEntity ;
33
37
import software .bernie .geckolib .animatable .instance .AnimatableInstanceCache ;
34
38
import software .bernie .geckolib .animation .*;
37
41
38
42
import java .util .List ;
39
43
40
- public class Firefly extends PathfinderMob implements FlyingAnimal , GeoEntity {
44
+ public class Firefly extends Animal implements FlyingAnimal , GeoEntity {
41
45
private final AnimatableInstanceCache cache = GeckoLibUtil .createInstanceCache (this );
42
46
47
+ private static final EntityDimensions BABY_DIMENSIONS = ModEntities .FIREFLY .get ().getDimensions ().scale (0.5f ).withEyeHeight (0.2975F );
48
+
43
49
private static final EntityDataAccessor <Boolean > ROOST = SynchedEntityData .defineId (Firefly .class , EntityDataSerializers .BOOLEAN );
44
- private static final EntityDataAccessor <Integer > BABY = SynchedEntityData .defineId (Firefly .class , EntityDataSerializers .INT );
50
+ private static final EntityDataAccessor <Integer > TICKER = SynchedEntityData .defineId (Firefly .class , EntityDataSerializers .INT );
45
51
46
52
public static final RawAnimation IDLE_RAW = RawAnimation .begin ().thenLoop ("idle" );
47
53
public static final RawAnimation BABY_RAW = RawAnimation .begin ().thenLoop ("baby" );
48
- public Firefly (EntityType <? extends PathfinderMob > type , Level level ) {
54
+ public Firefly (EntityType <? extends Animal > type , Level level ) {
49
55
super (type , level );
50
56
this .moveControl = new FlyingMoveControl (this , 20 , true );
51
57
this .xpReward = getRandom ().nextInt (3 ) + 1 ;
58
+
52
59
}
53
60
54
61
@ Override
55
- protected void defineSynchedData (SynchedEntityData .Builder builder ) {
56
- super .defineSynchedData (builder );
57
- builder .define (ROOST , false );
58
- builder .define (BABY , 0 );
62
+ protected @ NotNull EntityDimensions getDefaultDimensions (@ NotNull Pose pose ) {
63
+ return isBaby () ? BABY_DIMENSIONS : super .getDefaultDimensions (pose );
59
64
}
60
65
61
66
@ Nullable
62
67
@ Override
63
- public SpawnGroupData finalizeSpawn (ServerLevelAccessor level , DifficultyInstance difficulty , MobSpawnType spawnType , @ Nullable SpawnGroupData spawnGroupData ) {
68
+ public AgeableMob getBreedOffspring (@ NotNull ServerLevel serverLevel , @ NotNull AgeableMob ageableMob ) {
69
+ return ModEntities .FIREFLY .get ().create (serverLevel );
70
+ }
71
+
72
+ @ Override
73
+ protected void defineSynchedData (SynchedEntityData .@ NotNull Builder builder ) {
74
+ super .defineSynchedData (builder );
75
+ builder .define (ROOST , false );
76
+ builder .define (TICKER , 0 );
77
+
64
78
65
- return super .finalizeSpawn (level , difficulty , spawnType , spawnGroupData );
66
79
}
67
80
81
+
82
+
68
83
public void setRoost (boolean r ) {
69
84
this .entityData .set (ROOST , r );
70
85
}
71
86
72
- public boolean isRoost () {
73
- return this .entityData .get (ROOST );
74
- }
87
+ public void setTicker (int ticker ) { this .entityData .set (TICKER , ticker ); }
75
88
76
- @ Override
77
- public boolean isBaby () {
78
- return this .entityData .get (BABY ) < WildWindConfig .firefly_age ;
89
+ public int getTicker () { return this .entityData .get (TICKER ); }
90
+
91
+ public boolean isTicker () {
92
+ if (getTicker () < 600 ) {
93
+ addTicker ();
94
+ return true ;
95
+ }
96
+ return false ;
79
97
}
80
98
81
- public int getBaby () {
82
- return this .entityData .get (BABY );
99
+ public void addTicker () { this .entityData .set (TICKER , this .entityData .get (TICKER )+1 ); }
100
+ public void clearTicker () { this .entityData .set (TICKER , 0 ); }
101
+
102
+ public boolean isRoost () {
103
+ return this .entityData .get (ROOST );
83
104
}
84
105
85
- public void setBaby (int b ) {this .entityData .set (BABY , b );}
86
106
87
107
@ Override
88
108
public void tick () {
89
109
super .tick ();
90
- if (isBaby ()) {
91
- setBaby (getBaby ()+1 );
92
- }
93
110
}
94
111
95
112
@ Override
@@ -101,18 +118,23 @@ public boolean canBeLeashed() {
101
118
public void readAdditionalSaveData (@ NotNull CompoundTag compound ) {
102
119
super .readAdditionalSaveData (compound );
103
120
this .setRoost (compound .getBoolean ("roost" ));
104
- this .setBaby (compound .getInt ("baby" ));
121
+ this .setTicker (compound .getInt ("ticker" ));
122
+ }
123
+
124
+ @ Override
125
+ public boolean isFood (ItemStack itemStack ) {
126
+ return itemStack .is (ModItemTags .FIREFLY_FOOD .get ());
105
127
}
106
128
107
129
@ Override
108
- public void addAdditionalSaveData (CompoundTag compound ) {
130
+ public void addAdditionalSaveData (@ NotNull CompoundTag compound ) {
109
131
super .addAdditionalSaveData (compound );
110
132
compound .putBoolean ("roost" , isRoost ());
111
- compound .putInt ("baby " , getBaby ());
133
+ compound .putInt ("ticker " , getTicker ());
112
134
}
113
135
114
136
@ Override
115
- protected PathNavigation createNavigation (Level level ) {
137
+ protected @ NotNull PathNavigation createNavigation (@ NotNull Level level ) {
116
138
FlyingPathNavigation flyingPathNavigation = new FlyingPathNavigation (this , level ) {
117
139
@ Override
118
140
public boolean isStableDestination (BlockPos pos ) {
@@ -143,7 +165,8 @@ protected void checkFallDamage(double y, boolean onGround, BlockState state, Blo
143
165
.of (
144
166
FireflyBaseGoal ::new ,
145
167
FireflyFlyGoal ::new ,
146
- FireflyRoostGoal ::new
168
+ FireflyRoostGoal ::new ,
169
+ FireflyGlowGoal ::new
147
170
);
148
171
@ Override
149
172
protected void registerGoals () {
@@ -153,14 +176,15 @@ protected void registerGoals() {
153
176
}
154
177
155
178
@ Override
156
- protected InteractionResult mobInteract (Player player , InteractionHand hand ) {
179
+ public InteractionResult mobInteract (Player player , InteractionHand hand ) {
157
180
return super .mobInteract (player , hand );
158
181
}
159
182
160
183
public static AttributeSupplier createAttributes () {
161
184
return AmbientCreature .createMobAttributes ()
162
185
.add (Attributes .MAX_HEALTH , 8f )
163
186
.add (Attributes .FLYING_SPEED , 0.6f )
187
+ .add (Attributes .GRAVITY , 0.0f )
164
188
.build ();
165
189
}
166
190
0 commit comments