5
5
import com .crystalneko .tonekofabric .api .NekoEntityEvents ;
6
6
import com .crystalneko .tonekofabric .entity .ai .FollowAndAttackPlayerGoal ;
7
7
import com .crystalneko .tonekofabric .libs .base ;
8
+ import net .minecraft .entity .Entity ;
8
9
import net .minecraft .entity .EntityType ;
9
10
import net .minecraft .entity .LivingEntity ;
10
11
import net .minecraft .entity .MovementType ;
11
- import net .minecraft .entity .ai .goal .AnimalMateGoal ;
12
- import net .minecraft .entity .ai .goal .LookAtEntityGoal ;
13
- import net .minecraft .entity .ai .goal .SwimGoal ;
14
- import net .minecraft .entity .ai .goal .TemptGoal ;
12
+ import net .minecraft .entity .ai .goal .*;
13
+ import net .minecraft .entity .attribute .EntityAttribute ;
15
14
import net .minecraft .entity .attribute .EntityAttributes ;
16
15
import net .minecraft .entity .effect .StatusEffectInstance ;
17
16
import net .minecraft .entity .effect .StatusEffects ;
49
48
<li><code>{@link nekoEntity#nekoEntity}</code></li>
50
49
</ul>
51
50
</li>
51
+ <li>实体属性
52
+ <ul>
53
+ <li><code>{@link nekoEntity#getAttributeValue}</code></li>
54
+ </ul>
55
+ </li>
52
56
<li>繁殖
53
57
<ul>
54
58
<li>判断繁殖物品是否有效:<code>{@link nekoEntity#isBreedingItem(ItemStack)}</code></li>
63
67
</li>
64
68
<li>玩家操作
65
69
<ul>
70
+ <li>攻击时的操作: <code>{@link nekoEntity#handleAttack(Entity)}</code></li>
66
71
<li>右键点击操作:<code>{@link nekoEntity#interactMob(PlayerEntity, Hand)}</code></li>
67
72
<li>骑行:
68
73
<ul>
@@ -145,6 +150,7 @@ public class nekoEntity extends AnimalEntity implements GeoEntity {
145
150
public nekoEntity (EntityType <? extends AnimalEntity > entityType , World world ) {
146
151
super (entityType , world );
147
152
Objects .requireNonNull (this .getAttributeInstance (EntityAttributes .GENERIC_MOVEMENT_SPEED )).setBaseValue (0.6D );
153
+ this .speed = 0.6F ;
148
154
//设置碰撞箱
149
155
if (this .isBaby ()){
150
156
//如果是baby,则为成体的一半
@@ -153,6 +159,15 @@ public nekoEntity(EntityType<? extends AnimalEntity> entityType, World world) {
153
159
this .setBoundingBox (this .boundingBox );
154
160
}
155
161
}
162
+ // ---------------------------------------------------------属性-------------------------------------------------
163
+ @ Override
164
+ public double getAttributeValue (EntityAttribute attribute ) {
165
+ if (attribute == EntityAttributes .GENERIC_MAX_HEALTH ){
166
+ // 最大生命值
167
+ return 15.0 ;
168
+ }
169
+ return this .getAttributes ().getValue (attribute );
170
+ }
156
171
157
172
// --------------------------------------------------------繁殖-----------------------------------------------------
158
173
@ Override
@@ -184,9 +199,26 @@ protected void initGoals() {
184
199
this .goalSelector .add (2 , temptGoal );
185
200
this .goalSelector .add (12 , new LookAtEntityGoal (this , PlayerEntity .class , 10.0F ));
186
201
this .goalSelector .add (3 , new AnimalMateGoal (this , 0.8 ));
202
+ this .goalSelector .add (10 ,new EscapeDangerGoal (this , this .speed *0.5 ));
187
203
}
188
204
189
205
// -----------------------------------------------------玩家操作----------------------------------------------------
206
+ // 玩家攻击实体时
207
+ @ Override
208
+ public boolean handleAttack (Entity entity ){
209
+ // 注册监听事件
210
+ boolean result = NekoEntityEvents .ON_ATTACK .invoker ().onAttack (this , entity );
211
+ if (result ){
212
+ return true ;
213
+ }
214
+ if (entity instanceof PlayerEntity player ){
215
+ // 添加仇恨
216
+ this .increaseHatred (player ,100 );
217
+ return false ;
218
+ }
219
+ return super .handleAttack (entity );
220
+ }
221
+
190
222
// 玩家右键点击
191
223
@ Override
192
224
public ActionResult interactMob (PlayerEntity player , Hand hand ) {
@@ -250,7 +282,7 @@ public void increaseHatred(LivingEntity target, int amount) {
250
282
int currentHatred = hatredMap .getOrDefault (target , 0 );
251
283
if (target instanceof PlayerEntity targetPlayer ){
252
284
//让实体尝试跟随目标
253
- neko .goalSelector .add (1 ,new FollowAndAttackPlayerGoal (neko ,targetPlayer ,0.8D ,0.1F ,100.0F ));
285
+ neko .goalSelector .add (1 ,new FollowAndAttackPlayerGoal (neko ,targetPlayer ,this . speed * 2 ,0.1F ,100.0F , 2 .0F ));
254
286
}
255
287
hatredMap .put (target , currentHatred + amount );
256
288
}
0 commit comments