1515import net .minecraft .core .Direction ;
1616import net .minecraft .core .particles .ParticleTypes ;
1717import net .minecraft .nbt .CompoundTag ;
18- import net .minecraft .nbt .Tag ;
1918import net .minecraft .network .FriendlyByteBuf ;
2019import net .minecraft .network .protocol .Packet ;
2120import net .minecraft .network .protocol .game .ClientGamePacketListener ;
2928import net .minecraft .world .entity .EntityType ;
3029import net .minecraft .world .entity .EquipmentSlot ;
3130import net .minecraft .world .entity .LivingEntity ;
31+ import net .minecraft .world .entity .Mob ;
3232import net .minecraft .world .entity .MobSpawnType ;
3333import net .minecraft .world .entity .PathfinderMob ;
3434import net .minecraft .world .entity .SpawnGroupData ;
3535import net .minecraft .world .entity .ai .attributes .AttributeSupplier ;
3636import net .minecraft .world .entity .ai .attributes .Attributes ;
3737import net .minecraft .world .entity .ai .control .MoveControl ;
38+ import net .minecraft .world .entity .ai .goal .FloatGoal ;
3839import net .minecraft .world .entity .ai .goal .Goal ;
3940import net .minecraft .world .entity .ai .goal .LookAtPlayerGoal ;
4041import net .minecraft .world .entity .ai .goal .MeleeAttackGoal ;
42+ import net .minecraft .world .entity .ai .goal .OpenDoorGoal ;
4143import net .minecraft .world .entity .ai .goal .PanicGoal ;
4244import net .minecraft .world .entity .ai .goal .RandomLookAroundGoal ;
4345import net .minecraft .world .entity .ai .goal .RangedBowAttackGoal ;
4446import net .minecraft .world .entity .ai .goal .target .HurtByTargetGoal ;
45- import net .minecraft .world .entity .ai .goal .target .OwnerHurtTargetGoal ;
4647import net .minecraft .world .entity .ai .goal .target .TargetGoal ;
4748import net .minecraft .world .entity .ai .navigation .GroundPathNavigation ;
49+ import net .minecraft .world .entity .ai .navigation .PathNavigation ;
4850import net .minecraft .world .entity .ai .targeting .TargetingConditions ;
4951import net .minecraft .world .entity .monster .RangedAttackMob ;
5052import net .minecraft .world .entity .player .Player ;
5153import net .minecraft .world .entity .projectile .AbstractArrow ;
52- import net .minecraft .world .entity .projectile .Arrow ;
5354import net .minecraft .world .entity .projectile .ProjectileUtil ;
5455import net .minecraft .world .item .AxeItem ;
5556import net .minecraft .world .item .BowItem ;
6667import net .minecraftforge .items .ItemStackHandler ;
6768import net .minecraftforge .network .NetworkHooks ;
6869import net .minecraftforge .network .PlayMessages ;
69- import net .minecraft .world .entity .TamableAnimal ;
7070
7171public class WorkerEntity extends PathfinderMob implements RangedAttackMob {
7272 // renamed from DATA_GHOST_ITEM → DATA_TARGET_ITEM
@@ -128,8 +128,8 @@ protected void onContentsChanged(int slot) {
128128 public WorkerEntity (EntityType <? extends WorkerEntity > type , Level world ) {
129129 super (type , world );
130130 this .setPersistenceRequired ();
131- this .moveControl = new MoveControl (this );
132- this .navigation = new GroundPathNavigation (this , world );
131+ // this.moveControl = new MoveControl(this);
132+ // this.navigation = new GroundPathNavigation(this, world);
133133 }
134134
135135 public WorkerEntity (PlayMessages .SpawnEntity msg , Level world ) {
@@ -141,6 +141,28 @@ public WorkerEntity(PlayMessages.SpawnEntity msg, Level world) {
141141 public WorkerEntity (FriendlyByteBuf buf , Level world ) {
142142 this (ModEntities .WORKER .get (), world );
143143 }
144+
145+ @ Override
146+ protected void registerGoals () {
147+ super .registerGoals ();
148+
149+ this .goalSelector .addGoal (0 , new FloatGoal (this ));
150+ this .goalSelector .addGoal (0 , new NaturalRegenGoal (this , 20 *10 , 20 ));
151+ this .goalSelector .addGoal (0 , new OpenDoorGoal (this , true ));
152+
153+ this .targetSelector .addGoal (1 , new HurtByTargetGoal (this ).setAlertOthers ());
154+ this .targetSelector .addGoal (1 , new DefendMasterHurtByTargetGoal (this ));
155+ this .goalSelector .addGoal (1 , new WorkerBowAttackGoal (this , 1.2D , 20 , 15.0F ));
156+
157+ this .goalSelector .addGoal (2 , new MeleeAttackGoal (this , 1.5D , true ));
158+ this .targetSelector .addGoal (2 , new DefendMasterHurtTargetGoal (this ));
159+
160+ this .goalSelector .addGoal (3 , new PanicGoal (this , 1.25 ));
161+ this .goalSelector .addGoal (4 , new FollowMasterGoal (this , 1.5D , 5.0F ));
162+ this .goalSelector .addGoal (4 , new CommandMoveToGoal (this , 1.0D ));
163+ this .goalSelector .addGoal (9 , new LookAtPlayerGoal (this , Player .class , 8.0F , 1.0F ));
164+ this .goalSelector .addGoal (10 , new LookAtPlayerGoal (this , Mob .class , 6.0F ));
165+ }
144166
145167 @ Override
146168 public Packet <ClientGamePacketListener > getAddEntityPacket () {
@@ -149,9 +171,8 @@ public Packet<ClientGamePacketListener> getAddEntityPacket() {
149171
150172 private boolean interacting = false ;
151173
152- // called when you open the GUI in your onInteract or NetworkHooks.openGui callback:
153174 public void setInteracting (boolean b ) {
154- System .out .println ("CLIENT: " +b );
175+ // System.out.println("CLIENT: "+b);
155176 this .interacting = b ;
156177 }
157178 public boolean isInteracting () {
@@ -201,37 +222,24 @@ public SpawnGroupData finalizeSpawn(ServerLevelAccessor world, DifficultyInstanc
201222 return super .finalizeSpawn (world , difficulty , reason , data , tag );
202223 }
203224
225+ @ Override
226+ protected PathNavigation createNavigation (Level world ) {
227+ GroundPathNavigation nav = new GroundPathNavigation (this , world );
228+ // allow opening wooden doors
229+ nav .setCanOpenDoors (true );
230+ // allow walking **through** an open door block
231+ nav .setCanPassDoors (true );
232+ // if you want them to swim, too:
233+ nav .setCanFloat (true );
234+ return nav ;
235+ }
236+
204237 // getters for the four indices:
205238 public int getBodyIndex () { return this .entityData .get (DATA_BODY ); }
206239 public int getOutfitIndex () { return this .entityData .get (DATA_OUTFIT ); }
207240 public int getEyesIndex () { return this .entityData .get (DATA_EYES ); }
208241 public int getHairIndex () { return this .entityData .get (DATA_HAIR ); }
209242
210- @ Override
211- protected void registerGoals () {
212- super .registerGoals ();
213-
214- this .goalSelector .addGoal (0 , new NaturalRegenGoal (this , 20 *10 , 20 ));
215- // MELEE first:
216- this .goalSelector .addGoal (2 , new MeleeAttackGoal (this , 1.5D , true ));
217- // then follow master if we have a weapon:
218- this .goalSelector .addGoal (3 , new FollowMasterGoal (this , 1.5D , 5.0F ));
219- // then bow (if bow in hand):
220- this .goalSelector .addGoal (1 , new WorkerBowAttackGoal (this , 1.2D , 20 , 15.0F ));
221- // normal idle/look goals:
222- this .goalSelector .addGoal (4 , new PanicGoal (this , 1.25 ));
223- //this.goalSelector.addGoal(5, new WaterAvoidingRandomStrollGoal(this, 1.0)); // TODO Might re-implement this later, but for now it's just annoying
224- this .goalSelector .addGoal (8 , new RandomLookAroundGoal (this ));
225- this .goalSelector .addGoal (7 , new LookAtPlayerGoal (this , Player .class , 8.0F ));
226- // your move‐to‐listData goal:
227- this .goalSelector .addGoal (9 , new CommandMoveToGoal (this , 1.0D ));
228-
229- // DEFENSIVE target goals:
230- this .targetSelector .addGoal (1 , new HurtByTargetGoal (this ).setAlertOthers ());
231- this .targetSelector .addGoal (1 , new DefendMasterHurtByTargetGoal (this ));
232- this .targetSelector .addGoal (2 , new DefendMasterHurtTargetGoal (this ));
233- }
234-
235243 public static AttributeSupplier .Builder createAttributes () {
236244 return PathfinderMob .createMobAttributes ()
237245 .add (Attributes .MAX_HEALTH , 20.0D )
0 commit comments