-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e7b881a
commit c7b07c6
Showing
11 changed files
with
133 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/java/com/starfish_studios/hamsters/entity/common/SleepGoal.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.starfish_studios.hamsters.entity.common; | ||
|
||
import net.minecraft.world.entity.PathfinderMob; | ||
import net.minecraft.world.entity.ai.goal.Goal; | ||
|
||
import java.util.EnumSet; | ||
|
||
public class SleepGoal<E extends PathfinderMob & SleepingAnimal> extends Goal { | ||
public final E mob; | ||
|
||
public SleepGoal(E mob) { | ||
this.setFlags(EnumSet.of(Flag.MOVE, Flag.LOOK, Flag.JUMP)); | ||
this.mob = mob; | ||
} | ||
|
||
@Override | ||
public void start() { | ||
// After the goal is activated, makes the mob stop jumping, start sleeping, and stop moving. | ||
mob.setJumping(false); | ||
mob.setSleeping(true); | ||
mob.getNavigation().stop(); | ||
mob.getMoveControl().setWantedPosition(mob.getX(), mob.getY(), mob.getZ(), 0.0D); | ||
} | ||
|
||
@Override | ||
public boolean canUse() { | ||
// If the mob is not moving and can sleep or is already sleeping, return true | ||
if (mob.xxa == 0.0F && mob.yya == 0.0F && mob.zza == 0.0F) { | ||
return mob.canSleep() || mob.isSleeping(); | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
@Override | ||
public boolean canContinueToUse() { | ||
return mob.canSleep(); | ||
} // Allows the mob to continue sleeping if it can sleep (i.e., if it is not interrupted) | ||
|
||
@Override | ||
public void stop() { | ||
mob.setSleeping(false); | ||
} // Wakes up the mob when the goal ends | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/com/starfish_studios/hamsters/entity/common/SleepingAnimal.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.starfish_studios.hamsters.entity.common; | ||
|
||
public interface SleepingAnimal { | ||
boolean canSleep(); | ||
void setSleeping(boolean sleeping); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"parent": "item/generated", | ||
"textures": { | ||
"layer0": "hamsters:item/seed_mix" | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
{ | ||
"values": [ | ||
"minecraft:wheat_seeds", | ||
"minecraft:beetroot_seeds", | ||
"minecraft:pumpkin_seeds" | ||
"hamsters:seed_mix" | ||
] | ||
} |