mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-23 21:38:00 +01:00
Butterflies will now follow the player if they're holding a flower
This commit is contained in:
parent
aa00b1a9b0
commit
e21cffcf7d
1 changed files with 31 additions and 11 deletions
|
@ -34,6 +34,8 @@ import net.minecraft.nbt.NbtCompound;
|
|||
import net.minecraft.predicate.entity.EntityPredicates;
|
||||
import net.minecraft.sound.SoundEvent;
|
||||
import net.minecraft.registry.tag.BlockTags;
|
||||
import net.minecraft.registry.tag.ItemTags;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
|
@ -151,6 +153,11 @@ public class ButterflyEntity extends AmbientEntity {
|
|||
if (e instanceof PlayerEntity) {
|
||||
PlayerEntity player = (PlayerEntity)e;
|
||||
|
||||
if (player.getStackInHand(Hand.MAIN_HAND).isIn(ItemTags.FLOWERS)) {
|
||||
setTarget(player);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (player.isCreative() || player.isSpectator()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -181,6 +188,7 @@ public class ButterflyEntity extends AmbientEntity {
|
|||
if (!flowerPosition.isPresent()) {
|
||||
setResting(false);
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (getWorld().getBlockState(below).isAir()
|
||||
|
@ -200,6 +208,17 @@ public class ButterflyEntity extends AmbientEntity {
|
|||
} else {
|
||||
ticksResting = 0;
|
||||
|
||||
if (getTarget() instanceof PlayerEntity player) {
|
||||
if (player.isRemoved() || !player.getStackInHand(Hand.MAIN_HAND).isIn(ItemTags.FLOWERS)) {
|
||||
setTarget(null);
|
||||
}
|
||||
if (distanceTo(player) > 3) {
|
||||
moveTowards(player.getBlockPos());
|
||||
} else {
|
||||
this.addVelocity(random.nextFloat() * 0.1 - 0.05F, random.nextFloat() * 0.1, random.nextFloat() * 0.1 - 0.05F);
|
||||
}
|
||||
} else {
|
||||
|
||||
updateFlowerPosition().map(flower -> {
|
||||
if (flower.isWithinDistance(getPos(), 1)) {
|
||||
setResting(true);
|
||||
|
@ -217,6 +236,7 @@ public class ButterflyEntity extends AmbientEntity {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean canBreed() {
|
||||
return age > BREEDING_INTERVAL && breedingCooldown <= 0 && isResting() && getWorld().getOtherEntities(this, getBoundingBox().expand(2), i -> {
|
||||
|
|
Loading…
Reference in a new issue