Roll out the redesigned Arrakis jerboa
Some checks failed
Arrakis Jerboa Redesign Build / jerboa (push) Failing after 1m0s
DuneRealms Plugin CI / plugins (push) Failing after 2m21s

This commit is contained in:
unimatrixgit 2026-11-30 20:53:15 +01:00
commit bcc768a751

View file

@ -18,12 +18,13 @@ import net.kyori.adventure.text.format.NamedTextColor;
final class JerboaMobs implements Listener {
static final NamespacedKey KIND=new NamespacedKey("dunerealms","jerboa"),ROLLED=new NamespacedKey("dunerealms","jerboa_mother_rolled");
private static final NamespacedKey EI=new NamespacedKey("executableitems","ei-id");
static final double SPEED=.225, MOTHER_CHANCE=.005;
static final double SPEED=.34, MOTHER_CHANCE=.005;
private final Plugin plugin;
private final ArrakisEcology.Items items;
private final java.util.function.DoubleSupplier random;
private final Set<UUID> replacing=new HashSet<>();
private final Map<UUID,UUID> retaliation=new HashMap<>();
private final Map<UUID,Long> lastHurt=new HashMap<>();
private final Map<UUID,Long> instantFeeds=new HashMap<>();
private final FaunaModels models;
private long ticks;
@ -52,7 +53,13 @@ final class JerboaMobs implements Listener {
if(entity instanceof Cat cat&&isJerboa(cat)){migrate(cat);continue;}
if(isJerboa(entity)){
valid.add(entity.getUniqueId());entity.setSilent(true);boolean curled=entity instanceof Armadillo a&&a.getState()!=Armadillo.State.IDLE;
String model=curled?"jerboa_curled":entity.getVelocity().lengthSquared()>.001?(entity.getTicksLived()/4%2==0?"jerboa_walk_left":"jerboa_walk_right"):"jerboa";
String model=curled?"jerboa_curled":entity.getVelocity().lengthSquared()>.001?(ticks/4%2==0?"jerboa_walk_left":"jerboa_walk_right"):"jerboa";
if(entity instanceof Armadillo armadillo){
var speed=armadillo.getAttribute(Attribute.MOVEMENT_SPEED);
if(speed!=null&&speed.getBaseValue()==.225)speed.setBaseValue(SPEED);
if(curled&&!recentlyHurt(armadillo))armadillo.rollOut();
if(!curled&&armadillo.getLoveModeTicks()==0)scurry(armadillo);
}
models.track(entity,model,entity instanceof Armadillo c&&!c.isAdult()?.48:mother(entity)?2:1);
if(!curled&&random.getAsDouble()<.01)entity.getWorld().playSound(entity.getLocation(),"dunerealms:jerboa.idle",SoundCategory.NEUTRAL,.35f,mother(entity)?.8f:1.1f);
if(entity instanceof Armadillo cat){if(cat.isAdult()&&!cat.getPersistentDataContainer().has(ROLLED,PersistentDataType.BYTE))rollMother(cat);}
@ -61,9 +68,28 @@ final class JerboaMobs implements Listener {
valid.add(entity.getUniqueId());models.track(entity,"tiny_worm",((Wolf)entity).isAdult()?.8:.45);
}
}
models.retain(valid);retaliation.keySet().retainAll(valid);instantFeeds.entrySet().removeIf(e->e.getValue()+1000<System.currentTimeMillis());
models.retain(valid);retaliation.keySet().retainAll(valid);lastHurt.keySet().retainAll(valid);instantFeeds.entrySet().removeIf(e->e.getValue()+1000<System.currentTimeMillis());
if((ticks+=4)%1200==0)for(var adult:world.getEntitiesByClass(Armadillo.class))autoBreed(adult);
}
/** Mouse-like movement: bolt away from nearby players in short, jinking dashes, and skitter around when undisturbed. */
private void scurry(Mob mob){
if(((ticks/4)+mob.getEntityId())%2!=0)return;
Location at=mob.getLocation();Player threat=null;double best=36;
for(Player player:mob.getWorld().getNearbyPlayers(at,6)){if(player.getGameMode()==GameMode.SPECTATOR||player.getGameMode()==GameMode.CREATIVE||player.isSneaking())continue;double d=player.getLocation().distanceSquared(at);if(d<best){best=d;threat=player;}}
if(threat!=null){
var away=at.toVector().subtract(threat.getLocation().toVector()).setY(0);
if(away.lengthSquared()<1e-4)away=new org.bukkit.util.Vector(random.getAsDouble()-.5,0,random.getAsDouble()-.5);
if(away.lengthSquared()<1e-4)return;
away.normalize().rotateAroundY((random.getAsDouble()-.5)*.9).multiply(8);
mob.getPathfinder().moveTo(at.clone().add(away),1.7);return;
}
if(random.getAsDouble()<.12&&mob.getPathfinder().getCurrentPath()==null){
double angle=random.getAsDouble()*Math.PI*2,run=2+random.getAsDouble()*3;
mob.getPathfinder().moveTo(at.clone().add(Math.cos(angle)*run,0,Math.sin(angle)*run),1.5);
}
}
private boolean recentlyHurt(Entity e){Long at=lastHurt.get(e.getUniqueId());return at!=null&&System.currentTimeMillis()-at<4000;}
@EventHandler(priority=EventPriority.MONITOR,ignoreCancelled=true) public void hurt(EntityDamageEvent event){if(event.getEntity() instanceof Armadillo&&arrakis(event.getEntity())&&isJerboa(event.getEntity()))lastHurt.put(event.getEntity().getUniqueId(),System.currentTimeMillis());}
private void autoBreed(Armadillo adult){
if(!isJerboa(adult)||!adult.isAdult()||!adult.canBreed()||adult.getLoveModeTicks()>0||!adult.isTicking()||random.getAsDouble()>=.20)return;
var nearby=adult.getNearbyEntities(8,4,8);
@ -80,7 +106,7 @@ final class JerboaMobs implements Listener {
adult.getPersistentDataContainer().set(ROLLED,PersistentDataType.BYTE,(byte)1);
if(random.getAsDouble()>=MOTHER_CHANCE||adult.getNearbyEntities(32,16,32).stream().anyMatch(JerboaMobs::mother))return;
Location at=adult.getLocation().clone().add(2,0,2);if(!at.getChunk().isLoaded()||!at.getBlock().isPassable()||!at.clone().add(0,1,0).getBlock().isPassable()||!at.clone().add(0,-1,0).getBlock().getType().isSolid())return;
at.getWorld().spawn(at,Spider.class,s->{s.getPersistentDataContainer().set(KIND,PersistentDataType.BYTE,(byte)2);s.customName(Component.text("Big Mama Jerboa",NamedTextColor.GOLD));s.getAttribute(Attribute.MAX_HEALTH).setBaseValue(6);s.setHealth(6);s.getAttribute(Attribute.MOVEMENT_SPEED).setBaseValue(SPEED);s.getAttribute(Attribute.ATTACK_DAMAGE).setBaseValue(3);var scale=s.getAttribute(Attribute.SCALE);if(scale!=null)scale.setBaseValue(1.4);s.setTarget(null);});
at.getWorld().spawn(at,Spider.class,s->{s.getPersistentDataContainer().set(KIND,PersistentDataType.BYTE,(byte)2);s.customName(Component.text("Big Mama Jerboa",NamedTextColor.GOLD));s.getAttribute(Attribute.MAX_HEALTH).setBaseValue(6);s.setHealth(6);s.getAttribute(Attribute.MOVEMENT_SPEED).setBaseValue(.225);s.getAttribute(Attribute.ATTACK_DAMAGE).setBaseValue(3);var scale=s.getAttribute(Attribute.SCALE);if(scale!=null)scale.setBaseValue(1.4);s.setTarget(null);});
}
private static void consume(Player player,EquipmentSlot hand){if(player.getGameMode()==GameMode.CREATIVE)return;ItemStack item=player.getInventory().getItem(hand);item.setAmount(item.getAmount()-1);player.getInventory().setItem(hand,item);}
private void litter(Armadillo parent,Player breeder){int born=0;UUID reference=null;for(int i=0;i<4;i++){var at=parent.getLocation().clone().add((i%2-.5)*.4,0,(i/2-.5)*.4);var child=spawn(at,-24000);if(child.isValid()){born++;if(reference==null)reference=child.getUniqueId();FaunaProof.record(breeder,"jerboa","breed",child);}}if(born==4)FaunaProof.milestone(breeder,"husbandry_instant_litter",reference);parent.getWorld().spawnParticle(Particle.HEART,parent.getLocation().add(0,.5,0),7,.3,.3,.3);}