-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathScriptEntity.java
More file actions
977 lines (824 loc) · 28.9 KB
/
Copy pathScriptEntity.java
File metadata and controls
977 lines (824 loc) · 28.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
package noppes.npcs.scripted.entity;
import net.minecraft.block.material.Material;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.entity.passive.EntityAnimal;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTBase.NBTPrimitive;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagIntArray;
import net.minecraft.nbt.NBTTagString;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.MathHelper;
import net.minecraft.world.WorldServer;
import noppes.npcs.NoppesUtilServer;
import noppes.npcs.api.INbt;
import noppes.npcs.api.IParticle;
import noppes.npcs.api.IPos;
import noppes.npcs.api.IWorld;
import noppes.npcs.api.entity.IEntity;
import noppes.npcs.api.item.IItemStack;
import noppes.npcs.controllers.ServerCloneController;
import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.scripted.CustomNPCsException;
import noppes.npcs.scripted.NpcAPI;
import noppes.npcs.scripted.ScriptParticle;
import noppes.npcs.scripted.constants.EntityType;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
public class ScriptEntity<T extends Entity> implements IEntity {
protected T entity;
private Map<String, Object> tempData = new HashMap<>();
public ScriptEntity(T entity) {
this.entity = entity;
}
@Deprecated
public void spawnParticle(String directory, int HEXColor, int amount, int maxAge,
double x, double y, double z,
double motionX, double motionY, double motionZ, float gravity,
float scale1, float scale2, float scaleRate, int scaleRateStart,
float alpha1, float alpha2, float alphaRate, int alphaRateStart,
float rotation1, float rotation2, float rotationRate, int rotationRateStart,
float rotationX1, float rotationX2, float rotationXRate, int rotationXRateStart,
float rotationY1, float rotationY2, float rotationYRate, int rotationYRateStart,
float rotationZ1, float rotationZ2, float rotationZRate, int rotationZRateStart
) {
int entityID = entity.getEntityId();
ScriptParticle particle = new ScriptParticle(directory);
particle.HEXColor = HEXColor;
particle.HEXColor2 = HEXColor;
particle.HEXColorRate = 0;
particle.HEXColorStart = 0;
particle.amount = amount;
particle.maxAge = maxAge;
particle.x = x;
particle.y = y;
particle.z = z;
particle.motionX = motionX;
particle.motionY = motionY;
particle.motionZ = motionZ;
particle.gravity = gravity;
particle.scaleX1 = particle.scaleY1 = scale1;
particle.scaleX2 = particle.scaleY2 = scale2;
particle.scaleXRate = particle.scaleYRate = scaleRate;
particle.scaleXRateStart = particle.scaleYRateStart = scaleRateStart;
particle.alpha1 = alpha1;
particle.alpha2 = alpha2;
particle.alphaRate = alphaRate;
particle.alphaRateStart = alphaRateStart;
particle.rotationX1 = rotationX1;
particle.rotationX2 = rotationX2;
particle.rotationXRate = rotationXRate;
particle.rotationXRateStart = rotationXRateStart;
particle.rotationY1 = rotationY1;
particle.rotationY2 = rotationY2;
particle.rotationYRate = rotationYRate;
particle.rotationYRateStart = rotationYRateStart;
particle.rotationZ1 = rotationZ1;
particle.rotationZ2 = rotationZ2;
particle.rotationZRate = rotationZRate;
particle.rotationZRateStart = rotationZRateStart;
NBTTagCompound compound = particle.writeToNBT();
compound.setInteger("EntityID", entityID);
NoppesUtilServer.spawnScriptedParticle(compound, this.getWorld().getDimensionID());
}
@Deprecated
public void spawnParticle(String directory, int HEXColor, int amount, int maxAge,
double x, double y, double z,
double motionX, double motionY, double motionZ, float gravity,
float scale1, float scale2, float scaleRate, int scaleRateStart,
float alpha1, float alpha2, float alphaRate, int alphaRateStart
) {
int entityID = entity.getEntityId();
ScriptParticle particle = new ScriptParticle(directory);
particle.HEXColor = HEXColor;
particle.HEXColor2 = HEXColor;
particle.HEXColorRate = 0;
particle.HEXColorStart = 0;
particle.amount = amount;
particle.maxAge = maxAge;
particle.x = x;
particle.y = y;
particle.z = z;
particle.motionX = motionX;
particle.motionY = motionY;
particle.motionZ = motionZ;
particle.gravity = gravity;
particle.scaleX1 = particle.scaleY1 = scale1;
particle.scaleX2 = particle.scaleY2 = scale2;
particle.scaleXRate = particle.scaleYRate = scaleRate;
particle.scaleXRateStart = particle.scaleYRateStart = scaleRateStart;
particle.alpha1 = alpha1;
particle.alpha2 = alpha2;
particle.alphaRate = alphaRate;
particle.alphaRateStart = alphaRateStart;
NBTTagCompound compound = particle.writeToNBT();
compound.setInteger("EntityID", entityID);
NoppesUtilServer.spawnScriptedParticle(compound, this.getWorld().getDimensionID());
}
@Deprecated
public void spawnParticle(String directory, int HEXColor, int amount, int maxAge,
double x, double y, double z,
double motionX, double motionY, double motionZ, float gravity,
float scale1, float scale2, float scaleRate, int scaleRateStart
) {
int entityID = entity.getEntityId();
ScriptParticle particle = new ScriptParticle(directory);
particle.HEXColor = HEXColor;
particle.HEXColor2 = HEXColor;
particle.HEXColorRate = 0;
particle.HEXColorStart = 0;
particle.amount = amount;
particle.maxAge = maxAge;
particle.x = x;
particle.y = y;
particle.z = z;
particle.motionX = motionX;
particle.motionY = motionY;
particle.motionZ = motionZ;
particle.gravity = gravity;
particle.scaleX1 = particle.scaleY1 = scale1;
particle.scaleX2 = particle.scaleY2 = scale2;
particle.scaleXRate = particle.scaleYRate = scaleRate;
particle.scaleXRateStart = particle.scaleYRateStart = scaleRateStart;
NBTTagCompound compound = particle.writeToNBT();
compound.setInteger("EntityID", entityID);
NoppesUtilServer.spawnScriptedParticle(compound, this.getWorld().getDimensionID());
}
@Deprecated
public void spawnParticle(String directory, int HEXColor, int amount, int maxAge,
double x, double y, double z,
double motionX, double motionY, double motionZ, float gravity
) {
int entityID = entity.getEntityId();
ScriptParticle particle = new ScriptParticle(directory);
particle.HEXColor = HEXColor;
particle.HEXColor2 = HEXColor;
particle.HEXColorRate = 0;
particle.HEXColorStart = 0;
particle.amount = amount;
particle.maxAge = maxAge;
particle.x = x;
particle.y = y;
particle.z = z;
particle.motionX = motionX;
particle.motionY = motionY;
particle.motionZ = motionZ;
particle.gravity = gravity;
NBTTagCompound compound = particle.writeToNBT();
compound.setInteger("EntityID", entityID);
NoppesUtilServer.spawnScriptedParticle(compound, this.getWorld().getDimensionID());
}
@Deprecated
public void spawnParticle(String directory, int HEXColor, int amount, int maxAge,
double x, double y, double z
) {
int entityID = entity.getEntityId();
ScriptParticle particle = new ScriptParticle(directory);
particle.HEXColor = HEXColor;
particle.HEXColor2 = HEXColor;
particle.HEXColorRate = 0;
particle.HEXColorStart = 0;
particle.amount = amount;
particle.maxAge = maxAge;
particle.x = x;
particle.y = y;
particle.z = z;
NBTTagCompound compound = particle.writeToNBT();
compound.setInteger("EntityID", entityID);
NoppesUtilServer.spawnScriptedParticle(compound, this.getWorld().getDimensionID());
}
@Deprecated
public void spawnParticle(String directory, int HEXColor, int amount, int maxAge
) {
int entityID = entity.getEntityId();
ScriptParticle particle = new ScriptParticle(directory);
particle.HEXColor = HEXColor;
particle.HEXColor2 = HEXColor;
particle.HEXColorRate = 0;
particle.HEXColorStart = 0;
particle.amount = amount;
particle.maxAge = maxAge;
NBTTagCompound compound = particle.writeToNBT();
compound.setInteger("EntityID", entityID);
NoppesUtilServer.spawnScriptedParticle(compound, this.getWorld().getDimensionID());
}
public void spawnParticle(IParticle entityParticle) {
entityParticle.spawn(this);
}
public int getEntityId() {
return entity.getEntityId();
}
public String getUniqueID() {
return entity.getUniqueID().toString();
}
public double getYOffset() {
return entity.getYOffset();
}
/**
* @return The entities width
*/
public double getWidth() {
return entity.width;
}
/**
* @return The entities height
*/
public double getHeight() {
return entity.height;
}
/**
* @return The entities x position
*/
public double getX() {
return entity.posX;
}
/**
* @param x The entities x position
*/
public void setX(double x) {
entity.setPosition(x, entity.posY, entity.posZ);
;
}
/**
* @return The entities y position
*/
public double getY() {
return entity.posY;
}
/**
* @param y The entities y position
*/
public void setY(double y) {
entity.setPosition(entity.posX, y, entity.posZ);
}
/**
* @return The entities x position
*/
public double getZ() {
return entity.posZ;
}
/**
* @param z The entities x position
*/
public void setZ(double z) {
entity.setPosition(entity.posX, entity.posY, z);
;
}
/**
* @return The entities z motion
*/
public double getMotionX() {
return entity.motionX;
}
/**
* @param x The entities x motion
*/
public void setMotionX(double x) {
entity.motionX = x;
entity.velocityChanged = true;
}
/**
* @return The entities x motion
*/
public double getMotionY() {
return entity.motionY;
}
/**
* @param y The entities y motion
*/
public void setMotionY(double y) {
entity.motionY = y;
entity.velocityChanged = true;
}
/**
* @return The entities y motion
*/
public double getMotionZ() {
return entity.motionZ;
}
/**
* @param z The entities z motion
*/
public void setMotionZ(double z) {
entity.motionZ = z;
entity.velocityChanged = true;
}
public void setMotion(double x, double y, double z) {
this.setMotionX(x);
this.setMotionY(y);
this.setMotionZ(z);
}
public void setMotion(IPos pos) {
this.setMotion(pos.getXD(), pos.getYD(), pos.getZD());
}
public IPos getMotion() {
return NpcAPI.Instance().getIPos(entity.motionX, entity.motionY, entity.motionZ);
}
public boolean isAirborne() {
return entity.isAirBorne;
}
/**
* @return The block x position
*/
public int getBlockX() {
return MathHelper.floor_double(entity.posX);
}
/**
* @return The block y position
*/
public int getBlockY() {
return MathHelper.floor_double(entity.posY);
}
/**
* @return The block z position
*/
public int getBlockZ() {
return MathHelper.floor_double(entity.posZ);
}
/**
* @param x The x position
* @param y The y position
* @param z The z position
*/
public void setPosition(double x, double y, double z) {
entity.setPosition(x, y, z);
}
public IPos getPos() {
return NpcAPI.Instance().getIPos(entity.posX, entity.posY, entity.posZ);
}
public IPos getPosition() {
return getPos();
}
public void setPos(IPos pos) {
this.entity.setPosition(pos.getXD(), pos.getYD(), pos.getZD());
}
public void setPosition(IPos pos) {
this.setPos(pos);
}
public int getDimension() {
return entity.dimension;
}
public void setDimension(int dimensionId) {
IWorld world = NpcAPI.Instance().getIWorld(dimensionId);
if (world != null) {
WorldServer mcWorld = world.getMCWorld();
if (this.entity.riddenByEntity != null) {
this.entity.riddenByEntity.mountEntity((Entity) null);
}
if (this.entity.ridingEntity != null) {
this.entity.mountEntity((Entity) null);
}
WorldServer prevWorld = ((WorldServer) this.entity.worldObj);
prevWorld.unloadEntities(new ArrayList<Entity>(Collections.singleton(this.entity)));
prevWorld.resetUpdateEntityTick();
prevWorld.onEntityRemoved(this.entity);
this.entity.worldObj = mcWorld;
this.entity.dimension = dimensionId;
mcWorld.addLoadedEntities(new ArrayList<Entity>(Collections.singleton(this.entity)));
mcWorld.resetUpdateEntityTick();
mcWorld.updateEntityWithOptionalForce(this.entity, false);
if (this.entity instanceof EntityNPCInterface) {
((EntityNPCInterface) this.entity).updateClient();
}
mcWorld.spawnEntityInWorld(this.entity);
this.entity.velocityChanged = true;
}
}
@Override
public IEntity[] getCollidingEntities() {
AxisAlignedBB axisalignedbb;
boolean isPl = entity instanceof EntityPlayer;
if (entity.ridingEntity != null && entity.ridingEntity.isEntityAlive()) {
axisalignedbb = entity.boundingBox.func_111270_a(entity.ridingEntity.boundingBox).expand(isPl ? 0 : 1.0D, 0.0D, isPl ? 0 : 1.0D);
} else {
axisalignedbb = entity.boundingBox.expand(isPl ? 0 : 1.0D, isPl ? 0 : 0.5D, isPl ? 0 : 1.0D);
}
List<Entity> entities = (List<Entity>) entity.worldObj.getEntitiesWithinAABBExcludingEntity(entity, axisalignedbb);
List<IEntity> list = new ArrayList<>();
for (Entity living : entities) {
if (living.isEntityAlive())
list.add(NpcAPI.Instance().getIEntity(living));
}
return list.toArray(new IEntity[list.size()]);
}
/**
* @param range The search range for entities around this entity
* @return Array of entities within range
*/
public IEntity[] getSurroundingEntities(int range) {
List<Entity> entities = entity.worldObj.getEntitiesWithinAABB(Entity.class, entity.boundingBox.expand(range, range, range));
List<IEntity> list = new ArrayList<IEntity>();
for (Entity living : entities) {
if (living != entity)
list.add(NpcAPI.Instance().getIEntity(living));
}
return list.toArray(new IEntity[list.size()]);
}
/**
* @param range The search range for entities around this entity
* @param type The EntityType you want to find
* @return Array of entities within range
*/
public IEntity[] getSurroundingEntities(int range, int type) {
Class cls = Entity.class;
if (type == EntityType.LIVING)
cls = EntityLivingBase.class;
else if (type == EntityType.PLAYER)
cls = EntityPlayer.class;
else if (type == EntityType.ANIMAL)
cls = EntityAnimal.class;
else if (type == EntityType.MONSTER)
cls = EntityMob.class;
else if (type == EntityType.NPC)
cls = EntityNPCInterface.class;
List<Entity> entities = entity.worldObj.getEntitiesWithinAABB(cls, entity.boundingBox.expand(range, range, range));
List<IEntity> list = new ArrayList<IEntity>();
for (Entity living : entities) {
if (living != entity)
list.add(NpcAPI.Instance().getIEntity(living));
}
return list.toArray(new IEntity[list.size()]);
}
/**
* @return Whether the entity is alive or not
*/
public boolean isAlive() {
return entity.isEntityAlive();
}
/**
* @param key Get temp data for this key
* @return Returns the stored temp data
*/
public Object getTempData(String key) {
return tempData.get(key);
}
public void copyTempData(IEntity<?> scriptEntity) {
if (scriptEntity != null) {
this.tempData = ((ScriptEntity<?>) scriptEntity).tempData;
}
}
/**
* Tempdata gets cleared when the entity gets unloaded or the world restarts
*
* @param key The key for the data stored
* @param value The data stored
*/
public void setTempData(String key, Object value) {
tempData.put(key, value);
}
/**
* @param key The key thats going to be tested against the temp data
* @return Whether or not temp data containes the key
*/
public boolean hasTempData(String key) {
return tempData.containsKey(key);
}
/**
* @param key The key for the temp data to be removed
*/
public void removeTempData(String key) {
tempData.remove(key);
}
/**
* Remove all tempdata
*/
public void clearTempData() {
tempData.clear();
}
public String[] getTempDataKeys() {
return tempData.keySet().toArray(new String[0]);
}
/**
* @param key The key of the data to be returned
* @return Returns the stored data
*/
public Object getStoredData(String key) {
NBTTagCompound compound = getStoredCompound();
if (!compound.hasKey(key))
return null;
NBTBase base = compound.getTag(key);
if (base instanceof NBTPrimitive)
return ((NBTPrimitive) base).func_150286_g();
else if (base instanceof NBTTagIntArray)
return ((NBTTagIntArray) base).func_150302_c();
return ((NBTTagString) base).func_150285_a_();
}
/**
* Stored data persists through world restart. Unlike tempdata only Strings and Numbers can be saved
*
* @param key The key for the data stored
* @param value The data stored. This data can be either a Number or a String. Other data is not stored
*/
public void setStoredData(String key, Object value) {
NBTTagCompound compound = getStoredCompound();
if (value instanceof Number) {
compound.setDouble(key, ((Number) value).doubleValue());
} else if (value instanceof String)
compound.setString(key, (String) value);
saveStoredCompound(compound);
}
public void setStoredData(String key, int[] array) {
NBTTagCompound compound = getStoredCompound();
compound.setIntArray(key, array);
saveStoredCompound(compound);
}
/**
* @param key The key of the data to be checked
* @return Returns whether or not the stored data contains the key
*/
public boolean hasStoredData(String key) {
return getStoredCompound().hasKey(key);
}
/**
* @param key The key of the data to be removed
*/
public void removeStoredData(String key) {
NBTTagCompound compound = getStoredCompound();
compound.removeTag(key);
saveStoredCompound(compound);
}
/**
* Remove all stored data
*/
public void clearStoredData() {
entity.getEntityData().removeTag("CNPCStoredData");
}
public String[] getStoredDataKeys() {
NBTTagCompound compound = getStoredCompound();
Set strings = compound.func_150296_c();
ArrayList<String> stringList = new ArrayList<>();
for (Object o : strings) {
stringList.add((String) o);
}
return stringList.toArray(new String[0]);
}
private NBTTagCompound getStoredCompound() {
NBTTagCompound compound = entity.getEntityData().getCompoundTag("CNPCStoredData");
if (compound == null)
entity.getEntityData().setTag("CNPCStoredData", compound = new NBTTagCompound());
return compound;
}
private void saveStoredCompound(NBTTagCompound compound) {
entity.getEntityData().setTag("CNPCStoredData", compound);
}
/**
* @return The age of this entity in ticks
*/
public long getAge() {
return entity.ticksExisted;
}
/**
* Despawns this entity. Removes it permanently
*/
public void despawn() {
entity.isDead = true;
}
/**
* @return Return whether or not this entity is standing in water
*/
public boolean inWater() {
return entity.isInsideOfMaterial(Material.water);
}
/**
* @return Return whether or not this entity is standing in lava
*/
public boolean inLava() {
return entity.isInsideOfMaterial(Material.lava);
}
/**
* @return Return whether or not this entity is standing in fire
*/
public boolean inFire() {
return entity.isInsideOfMaterial(Material.fire);
}
/**
* @return Return whether or not this entity is on fire
*/
public boolean isBurning() {
return entity.isBurning();
}
/**
* @param ticks Amount of world ticks this entity will burn. 20 ticks equals 1 second
*/
public void setBurning(int ticks) {
entity.setFire(ticks);
}
/**
* Removes fire from this entity
*/
public void extinguish() {
entity.extinguish();
}
/**
* @return Name as which it's registered in minecraft
*/
public String getTypeName() {
return EntityList.getEntityString(entity);
}
public void playSound(String name, float volume, float pitch) {
entity.playSound(name, volume, pitch);
}
/**
* @param item Item to be dropped
*/
public void dropItem(IItemStack item) {
entity.entityDropItem(item.getMCItemStack(), 0);
}
/**
* @return Return the rider
*/
public IEntity getRider() {
return NpcAPI.Instance().getIEntity(entity.riddenByEntity);
}
/**
* @param entity The entity to ride this entity
*/
public void setRider(IEntity entity) {
if (entity != null) {
entity.getMCEntity().mountEntity(this.entity);
;
} else if (this.entity.riddenByEntity != null)
this.entity.riddenByEntity.mountEntity(null);
}
/**
* @return Return the entity, this entity is riding
*/
public IEntity getMount() {
return NpcAPI.Instance().getIEntity(entity.ridingEntity);
}
/**
* @param entity The entity this entity will mount
*/
public void setMount(IEntity entity) {
if (entity == null)
this.entity.mountEntity(null);
else
this.entity.mountEntity(entity.getMCEntity());
}
/**
* @return Returns the EntityType of this entity
* @see noppes.npcs.scripted.constants.EntityType
*/
public int getType() {
return EntityType.UNKNOWN;
}
/**
* @param type @EntityType to check
* @return Returns whether the entity is type of the given @EntityType
* @since 1.7.10c
*/
public boolean typeOf(int type) {
return type == EntityType.UNKNOWN;
}
/**
* @param rotation The rotation to be set (0-360)
*/
public void setRotation(float rotation) {
entity.rotationYaw = rotation;
}
public void setRotation(float rotationYaw, float rotationPitch) {
entity.rotationYaw = rotationYaw;
entity.rotationPitch = rotationPitch;
}
/**
* @return Current rotation of the entity
*/
public float getRotation() {
return entity.rotationYaw;
}
public void setPitch(float pitch) {
entity.rotationPitch = pitch;
}
public float getPitch() {
return entity.rotationPitch;
}
/**
* @param power How strong the knockback is
* @param direction The direction in which he flies back (0-360). Usually based on getRotation()
*/
@Override
public void knockback(int power, float direction) {
float v = direction * (float) Math.PI / 180.0F;
entity.addVelocity(-MathHelper.sin(v) * (float) power, power, MathHelper.cos(v) * (float) power);
entity.velocityChanged = true;
}
public void knockback(double xpower, double ypower, double zpower, float direction) {
float v = direction * (float) Math.PI / 180.0F;
entity.addVelocity(-MathHelper.sin(v) * xpower, ypower, MathHelper.cos(v) * zpower);
entity.velocityChanged = true;
}
public void knockback(IPos pos, float direction) {
this.knockback(pos.getXD(), pos.getYD(), pos.getZD(), direction);
}
public void setImmune(int ticks) {
entity.hurtResistantTime = ticks;
}
public void setInvisible(boolean invisible) {
entity.setInvisible(invisible);
}
public void setSneaking(boolean sneaking) {
entity.setSneaking(sneaking);
}
public void setSprinting(boolean sprinting) {
entity.setSprinting(sprinting);
}
public boolean hasCollided() {
return entity.isCollided;
}
public boolean hasCollidedVertically() {
return entity.isCollidedVertically;
}
public boolean hasCollidedHorizontally() {
return entity.isCollidedHorizontally;
}
public boolean capturesDrops() {
return entity.captureDrops;
}
public void setCapturesDrops(boolean capture) {
entity.captureDrops = capture;
}
public void setCapturedDrops(IEntity[] capturedDrops) {
entity.capturedDrops.clear();
for (IEntity<?> iEntity : capturedDrops) {
if (iEntity.getMCEntity() instanceof EntityItem) {
entity.capturedDrops.add((EntityItem) iEntity.getMCEntity());
}
}
}
public IEntity<?>[] getCapturedDrops() {
ArrayList<IEntity<?>> iEntityList = new ArrayList<>();
for (EntityItem entityItem : entity.capturedDrops) {
iEntityList.add(NpcAPI.Instance().getIEntity(entityItem));
}
return iEntityList.toArray(new IEntity[0]);
}
/**
* @return Returns whether or not this entity is sneaking
* @since 1.7.10c
*/
public boolean isSneaking() {
return entity.isSneaking();
}
/**
* @return Returns whether or not this entity is sprinting
* @since 1.7.10c
*/
public boolean isSprinting() {
return entity.isSprinting();
}
/**
* @return Returns minecrafts entity
* @since 1.7.10c
* Expert users only
*/
public T getMCEntity() {
return entity;
}
public INbt getNbt() {
return NpcAPI.Instance().getINbt(this.entity.getEntityData());
}
public INbt getAllNbt() {
NBTTagCompound compound = new NBTTagCompound();
this.entity.writeToNBT(compound);
return NpcAPI.Instance().getINbt(compound);
}
public void setNbt(INbt nbt) {
this.entity.readFromNBT(nbt.getMCNBT());
}
public INbt getNbtOptional() {
NBTTagCompound compound = new NBTTagCompound();
return this.entity.writeToNBTOptional(compound) ? NpcAPI.Instance().getINbt(compound) : null;
}
public void storeAsClone(int tab, String name) {
NBTTagCompound compound = new NBTTagCompound();
if (!this.entity.writeToNBTOptional(compound)) {
throw new CustomNPCsException("Cannot store dead entities", new Object[0]);
} else {
ServerCloneController.Instance.addClone(compound, name, tab);
}
}
public IWorld getWorld() {
return NpcAPI.Instance().getIWorld(entity.worldObj);
}
public boolean equals(Object object) {
return object instanceof IEntity && ((IEntity<?>) object).getMCEntity().equals(this.entity);
}
@Override
public int hashCode() {
return Objects.hash(entity, tempData);
}
public void updateEntity() {
IWorld world = NpcAPI.Instance().getIWorld(entity.worldObj);
entity.dimension = world.getDimensionID();
}
}