Skip to content

Commit 235e36b

Browse files
committed
Added an entity behaviour for the breeze
1 parent 81bcf14 commit 235e36b

File tree

2 files changed

+104
-0
lines changed

2 files changed

+104
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
package com.minelittlepony.unicopia.entity.behaviour;
2+
3+
import com.minelittlepony.unicopia.entity.Living;
4+
import com.minelittlepony.unicopia.entity.player.Pony;
5+
import net.minecraft.entity.Entity;
6+
import net.minecraft.entity.EntityPose;
7+
import net.minecraft.entity.effect.StatusEffectInstance;
8+
import net.minecraft.entity.effect.StatusEffects;
9+
import net.minecraft.entity.mob.BreezeEntity;
10+
import net.minecraft.entity.player.PlayerEntity;
11+
import net.minecraft.entity.projectile.BreezeWindChargeEntity;
12+
import net.minecraft.nbt.NbtCompound;
13+
import net.minecraft.sound.SoundEvents;
14+
import net.minecraft.util.math.MathHelper;
15+
import net.minecraft.util.math.Vec3d;
16+
17+
public class BreezeBehaviour extends EntityBehaviour<BreezeEntity> {
18+
@Override
19+
public void update(Living<?> source, BreezeEntity entity, Disguise spell) {
20+
super.update(source, entity, spell);
21+
22+
Entity src = source.asEntity();
23+
24+
if (src.isOnGround() || src instanceof PlayerEntity player && player.getAbilities().flying) {
25+
return;
26+
}
27+
28+
Vec3d vel = src.getVelocity();
29+
30+
if (vel.y < 0) {
31+
src.setVelocity(vel.multiply(1, 0.8, 1));
32+
}
33+
34+
if (!source.asEntity().isOnGround()) {
35+
vel = vel.multiply(1.2, 1, 1.2);
36+
37+
src.setVelocity(MathHelper.clamp(vel.x, -0.5, 0.5), vel.y, MathHelper.clamp(vel.z, -0.5, 0.5));
38+
}
39+
}
40+
41+
@Override
42+
public void update(Pony player, BreezeEntity entity, Disguise spell) {
43+
44+
if (!player.isClient()) {
45+
46+
if (!player.asEntity().hasStatusEffect(StatusEffects.JUMP_BOOST)) {
47+
player.asEntity().addStatusEffect(new StatusEffectInstance(StatusEffects.JUMP_BOOST, 10, 2, false, false));
48+
}
49+
}
50+
51+
NbtCompound tag = spell.getDisguise().getOrCreateTag();
52+
53+
boolean firing = tag.getBoolean("isFiring");
54+
int fireballCooldown = tag.getInt("fireballCooldown");
55+
int fireballsFired = tag.getInt("fireballsFired");
56+
57+
if (player.sneakingChanged()) {
58+
boolean sneaking = player.asEntity().isSneaking();
59+
60+
if (sneaking) {
61+
firing = true;
62+
fireballCooldown = 0;
63+
fireballsFired = 0;
64+
} else {
65+
firing = false;
66+
}
67+
}
68+
69+
if (firing && fireballCooldown <= 0) {
70+
fireballsFired++;
71+
72+
if (fireballsFired == 1) {
73+
fireballCooldown = 60;
74+
entity.setPose(EntityPose.SHOOTING);
75+
} else if (fireballsFired <= 4) {
76+
fireballCooldown = 6;
77+
} else {
78+
fireballCooldown = 100;
79+
fireballsFired = 0;
80+
entity.setPose(player.asEntity().isOnGround() ? EntityPose.STANDING : EntityPose.LONG_JUMPING);
81+
}
82+
83+
if (fireballsFired > 0) {
84+
entity.playSound(SoundEvents.ENTITY_BREEZE_SHOOT, 1.5F, 1.0F);
85+
86+
Vec3d rot = player.asEntity().getRotationVec(1);
87+
88+
for (int i = 0; i < 1; ++i) {
89+
BreezeWindChargeEntity proj = new BreezeWindChargeEntity(entity, entity.getWorld());
90+
proj.setVelocity(rot.add(entity.getRandom().nextGaussian() * 0.1, 0, entity.getRandom().nextGaussian() * 0.1));
91+
proj.setPosition(proj.getX(), entity.getBodyY(0.5D) + 0.5D, proj.getZ());
92+
entity.getWorld().spawnEntity(proj);
93+
}
94+
}
95+
} else if (!firing) {
96+
entity.setPose(player.asEntity().isOnGround() ? EntityPose.STANDING : EntityPose.LONG_JUMPING);
97+
}
98+
99+
tag.putBoolean("isFiring", firing);
100+
tag.putInt("fireballCooldown", fireballCooldown);
101+
tag.putInt("fireballsFired", fireballsFired);
102+
}
103+
}

src/main/java/com/minelittlepony/unicopia/entity/behaviour/EntityBehaviour.java

+1
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ public static <T extends Entity> EntityBehaviour<T> forEntity(@Nullable T entity
287287
register(SilverfishBehaviour::new, EntityType.SILVERFISH);
288288
register(ChickenBehaviour::new, EntityType.CHICKEN);
289289
register(BlazeBehaviour::new, EntityType.BLAZE);
290+
register(BreezeBehaviour::new, EntityType.BREEZE);
290291
register(MinecartBehaviour::new, EntityType.CHEST_MINECART, EntityType.COMMAND_BLOCK_MINECART, EntityType.FURNACE_MINECART, EntityType.HOPPER_MINECART, EntityType.MINECART, EntityType.SPAWNER_MINECART, EntityType.TNT_MINECART);
291292
register(CamelBehaviour::new, EntityType.CAMEL);
292293
}

0 commit comments

Comments
 (0)