1
1
package pl .asie .computronics .integration .forestry .entity ;
2
2
3
+ import com .mojang .authlib .GameProfile ;
3
4
import cpw .mods .fml .relauncher .Side ;
4
5
import cpw .mods .fml .relauncher .SideOnly ;
5
6
import forestry .api .apiculture .BeeManager ;
7
+ import forestry .api .apiculture .DefaultBeeListener ;
8
+ import forestry .api .apiculture .DefaultBeeModifier ;
9
+ import forestry .api .apiculture .IBeeGenome ;
10
+ import forestry .api .apiculture .IBeeHousing ;
11
+ import forestry .api .apiculture .IBeeHousingInventory ;
12
+ import forestry .api .apiculture .IBeeListener ;
13
+ import forestry .api .apiculture .IBeeModifier ;
14
+ import forestry .api .apiculture .IBeekeepingLogic ;
15
+ import forestry .api .core .EnumHumidity ;
16
+ import forestry .api .core .EnumTemperature ;
17
+ import forestry .api .core .ForestryAPI ;
18
+ import forestry .api .core .IErrorLogic ;
6
19
import net .minecraft .block .material .Material ;
7
20
import net .minecraft .entity .Entity ;
8
21
import net .minecraft .entity .EntityLivingBase ;
9
22
import net .minecraft .entity .SharedMonsterAttributes ;
10
23
import net .minecraft .entity .player .EntityPlayer ;
24
+ import net .minecraft .item .ItemStack ;
11
25
import net .minecraft .nbt .NBTTagCompound ;
12
26
import net .minecraft .potion .PotionEffect ;
13
27
import net .minecraft .util .ChatComponentTranslation ;
28
+ import net .minecraft .util .ChunkCoordinates ;
14
29
import net .minecraft .util .DamageSource ;
15
30
import net .minecraft .util .IChatComponent ;
16
31
import net .minecraft .util .MathHelper ;
23
38
import pl .asie .computronics .integration .forestry .nanomachines .SwarmProvider ;
24
39
25
40
import java .util .Arrays ;
41
+ import java .util .Collections ;
26
42
import java .util .List ;
27
43
28
44
/**
29
45
* @author Vexatos
30
46
*/
31
- public class EntitySwarm extends EntityFlyingCreature {
47
+ public class EntitySwarm extends EntityFlyingCreature implements IBeeHousing {
32
48
33
49
public static final DamageSource beeDamageSource = new BeeDamageSource ("computronics.sting" , 5 );
34
50
public static final DamageSource beeDamageSourceSelf = new BeeDamageSource ("computronics.sting.self" , 1 );
@@ -38,10 +54,13 @@ public class EntitySwarm extends EntityFlyingCreature {
38
54
public EntitySwarm (World world ) {
39
55
super (world );
40
56
this .setSize (1.0F , 1.0F );
57
+ this .inventory = new SwarmHousingInventory (null );
41
58
}
42
59
43
- public EntitySwarm (World world , double x , double y , double z ) {
44
- this (world );
60
+ public EntitySwarm (World world , double x , double y , double z , ItemStack queen ) {
61
+ super (world );
62
+ this .setSize (1.0F , 1.0F );
63
+ this .inventory = new SwarmHousingInventory (queen );
45
64
this .setPosition (x , y , z );
46
65
this .prevPosX = x ;
47
66
this .prevPosY = y ;
@@ -70,6 +89,9 @@ public void onEntityUpdate() {
70
89
this .setDead ();
71
90
}
72
91
}
92
+ if (beeLogic .canWork ()) {
93
+ beeLogic .doWork ();
94
+ }
73
95
} else {
74
96
/*ArrayList<Entity> toKeep = new ArrayList<Entity>();
75
97
for(Entity member : swarmMembers) {
@@ -441,4 +463,169 @@ public Entity getEntity() {
441
463
return this.entity;
442
464
}*/
443
465
}
466
+
467
+ private final IBeekeepingLogic beeLogic = BeeManager .beeRoot .createBeekeepingLogic (this );
468
+ private final IErrorLogic errorLogic = ForestryAPI .errorStateRegistry .createErrorLogic ();
469
+ private final IBeeHousingInventory inventory ;
470
+ private final IBeeListener beeListener = new SwarmBeeListener ();
471
+
472
+ @ Override
473
+ public Iterable <IBeeModifier > getBeeModifiers () {
474
+ return Collections .singletonList (SwarmBeeModifier .instance );
475
+ }
476
+
477
+ @ Override
478
+ public Iterable <IBeeListener > getBeeListeners () {
479
+ return Collections .singletonList (beeListener );
480
+ }
481
+
482
+ @ Override
483
+ public IBeeHousingInventory getBeeInventory () {
484
+ return inventory ;
485
+ }
486
+
487
+ @ Override
488
+ public IBeekeepingLogic getBeekeepingLogic () {
489
+ return beeLogic ;
490
+ }
491
+
492
+ @ Override
493
+ public EnumTemperature getTemperature () {
494
+ return EnumTemperature .getFromBiome (getBiome (), getX (), getY (), getZ ());
495
+ }
496
+
497
+ @ Override
498
+ public EnumHumidity getHumidity () {
499
+ return EnumHumidity .getFromValue (getBiome ().rainfall );
500
+ }
501
+
502
+ @ Override
503
+ public int getBlockLightValue () {
504
+ return worldObj .getBlockLightValue (getX (), getY (), getZ ());
505
+ }
506
+
507
+ @ Override
508
+ public boolean canBlockSeeTheSky () {
509
+ return worldObj .canBlockSeeTheSky (getX (), getY () + 1 , getZ ());
510
+ }
511
+
512
+ @ Override
513
+ public World getWorld () {
514
+ return worldObj ;
515
+ }
516
+
517
+ @ Override
518
+ public BiomeGenBase getBiome () {
519
+ return worldObj .getBiomeGenForCoords (getX (), getZ ());
520
+ }
521
+
522
+ @ Override
523
+ public GameProfile getOwner () {
524
+ return player != null ? player .getGameProfile () : null ;
525
+ }
526
+
527
+ @ Override
528
+ public Vec3 getBeeFXCoordinates () {
529
+ return Vec3 .createVectorHelper (posX , posY + 0.25 , posZ );
530
+ }
531
+
532
+ @ Override
533
+ public IErrorLogic getErrorLogic () {
534
+ return errorLogic ;
535
+ }
536
+
537
+ @ Override
538
+ public ChunkCoordinates getCoordinates () {
539
+ return new ChunkCoordinates (getX (), getY (), getZ ());
540
+ }
541
+
542
+ public int getX () {
543
+ return MathHelper .floor_double (posX );
544
+ }
545
+
546
+ public int getY () {
547
+ return MathHelper .floor_double (posY );
548
+ }
549
+
550
+ public int getZ () {
551
+ return MathHelper .floor_double (posZ );
552
+ }
553
+
554
+ public static class SwarmHousingInventory implements IBeeHousingInventory {
555
+
556
+ private ItemStack queenStack ;
557
+
558
+ public SwarmHousingInventory (ItemStack queenStack ) {
559
+ this .queenStack = queenStack ;
560
+ }
561
+
562
+ @ Override
563
+ public ItemStack getQueen () {
564
+ return queenStack ;
565
+ }
566
+
567
+ @ Override
568
+ public ItemStack getDrone () {
569
+ return null ;
570
+ }
571
+
572
+ @ Override
573
+ public void setQueen (ItemStack stack ) {
574
+ this .queenStack = stack ;
575
+ }
576
+
577
+ @ Override
578
+ public void setDrone (ItemStack stack ) {
579
+ // NO-OP
580
+ }
581
+
582
+ @ Override
583
+ public boolean addProduct (ItemStack product , boolean all ) {
584
+ return true ; // Consume all products without doing anything.
585
+ }
586
+ }
587
+
588
+ public class SwarmBeeListener extends DefaultBeeListener {
589
+
590
+ @ Override
591
+ public void onQueenDeath () {
592
+ super .onQueenDeath ();
593
+ setDead ();
594
+ }
595
+ }
596
+
597
+ public static class SwarmBeeModifier extends DefaultBeeModifier {
598
+
599
+ public static final IBeeModifier instance = new SwarmBeeModifier ();
600
+
601
+ @ Override
602
+ public float getTerritoryModifier (IBeeGenome genome , float currentModifier ) {
603
+ return 0.5f ;
604
+ }
605
+
606
+ @ Override
607
+ public float getMutationModifier (IBeeGenome genome , IBeeGenome mate , float currentModifier ) {
608
+ return 0.0f ;
609
+ }
610
+
611
+ @ Override
612
+ public float getLifespanModifier (IBeeGenome genome , IBeeGenome mate , float currentModifier ) {
613
+ return 1.1f ;
614
+ }
615
+
616
+ @ Override
617
+ public float getProductionModifier (IBeeGenome genome , float currentModifier ) {
618
+ return 0.0f ;
619
+ }
620
+
621
+ @ Override
622
+ public float getFloweringModifier (IBeeGenome genome , float currentModifier ) {
623
+ return 0.0f ;
624
+ }
625
+
626
+ @ Override
627
+ public float getGeneticDecay (IBeeGenome genome , float currentModifier ) {
628
+ return 100f ;
629
+ }
630
+ }
444
631
}
0 commit comments