Skip to content

Commit

Permalink
Spawn particles when a sheep teleports (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
haykam821 authored Mar 4, 2024
1 parent f9e0661 commit a793150
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
22 changes: 21 additions & 1 deletion src/main/java/xyz/nucleoid/farmyfeud/entity/FarmSheepEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.passive.SheepEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.particle.DustParticleEffect;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;
import net.minecraft.util.DyeColor;
Expand All @@ -20,6 +22,7 @@
import net.minecraft.world.Heightmap;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
import org.joml.Vector3f;
import xyz.nucleoid.farmyfeud.game.active.FfActive;
import xyz.nucleoid.map_templates.BlockBounds;
import xyz.nucleoid.plasmid.game.common.team.GameTeamKey;
Expand Down Expand Up @@ -76,6 +79,23 @@ public boolean tryPickUp(long time, GameTeamKey team) {
return false;
}

public void teleportWithPoof(double x, double y, double z) {
if (this.getWorld() instanceof ServerWorld world) {
var colorComponents = this.getColor().getColorComponents();
var particle = new DustParticleEffect(new Vector3f(colorComponents), 2f);

for (int i = 0; i < 20; i++) {
double deltaX = this.random.nextGaussian() * 0.02;
double deltaY = this.random.nextGaussian() * 0.02;
double deltaZ = this.random.nextGaussian() * 0.02;

world.spawnParticles(particle, this.getParticleX(1), this.getRandomBodyY(), this.getParticleZ(1), 1, deltaX, deltaY, deltaZ, 0.1);
}
}

this.teleport(x, y, z);
}

@Nullable
public BlockBounds getHome() {
return this.home;
Expand Down Expand Up @@ -111,7 +131,7 @@ protected void mobTick() {

if (time - this.lastValidTime > 20 * 20) {
Vec3d center = this.home.center();
this.teleport(center.getX(), center.getY() + 0.5, center.getZ());
this.teleportWithPoof(center.getX(), center.getY() + 0.5, center.getZ());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ public void tickSheep(FarmSheepEntity sheep) {
}

sheep.detach();
sheep.teleport(respawnPos.x, respawnPos.y, respawnPos.z);
sheep.teleportWithPoof(respawnPos.x, respawnPos.y, respawnPos.z);
sheep.setFireTicks(0);
}
}
Expand Down

0 comments on commit a793150

Please sign in to comment.