Spawning particles can now be done with an ICaster<>

This commit is contained in:
Sollace 2019-02-07 13:32:55 +02:00
parent 6cb2ee69b9
commit cfa36497b7
9 changed files with 21 additions and 25 deletions

View file

@ -9,6 +9,7 @@ import com.minelittlepony.unicopia.player.IPlayer;
import com.minelittlepony.util.shape.IShape;
import com.minelittlepony.util.shape.Sphere;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.DamageSource;
import net.minecraft.util.math.Vec3d;
@ -41,10 +42,7 @@ public interface IPower<T extends IData> extends IKeyBind {
return player.posY + player.getEyeHeight() - 1;
}
static void spawnParticles(int particleId, IPlayer player, int count) {
EntityPlayer entity = player.getOwner();
static void spawnParticles(int particleId, Entity entity, int count) {
double halfDist = entity.getEyeHeight() / 1.5;
double middle = entity.getEntityBoundingBox().minY + halfDist;

View file

@ -80,11 +80,11 @@ public class PowerCloudBase implements IPower<Numeric> {
@Override
public void preApply(IPlayer player) {
IPower.spawnParticles(UParticles.UNICORN_MAGIC, player, 10);
player.spawnParticles(UParticles.UNICORN_MAGIC, 10);
}
@Override
public void postApply(IPlayer player) {
IPower.spawnParticles(UParticles.RAIN_DROPS, player, 5);
player.spawnParticles(UParticles.RAIN_DROPS, 5);
}
}

View file

@ -54,12 +54,12 @@ public class PowerDisguise extends PowerFeed {
@Override
public void preApply(IPlayer player) {
player.addEnergy(2);
IPower.spawnParticles(UParticles.CHANGELING_MAGIC, player, 5);
player.spawnParticles(UParticles.CHANGELING_MAGIC, 5);
}
@Override
public void postApply(IPlayer player) {
player.setEnergy(0);
IPower.spawnParticles(UParticles.CHANGELING_MAGIC, player, 5);
player.spawnParticles(UParticles.CHANGELING_MAGIC, 5);
}
}

View file

@ -7,7 +7,6 @@ import javax.annotation.Nullable;
import org.lwjgl.input.Keyboard;
import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.particle.Particles;
import com.minelittlepony.unicopia.player.IPlayer;
import com.minelittlepony.unicopia.power.data.Hit;
import com.minelittlepony.util.MagicalDamageSource;
@ -129,13 +128,7 @@ public class PowerFeed implements IPower<Hit> {
public void postApply(IPlayer player) {
EntityPlayer entity = player.getOwner();
for (int i = 0; i < 10; i++) {
Particles.instance().spawnParticle(EnumParticleTypes.HEART.getParticleID(), false,
entity.posX + entity.world.rand.nextFloat() * 2 - 1,
entity.posY + entity.world.rand.nextFloat() * 2 - 1,
entity.posZ + entity.world.rand.nextFloat() * 2 - 1,
0, 0.25, 0);
}
IPower.spawnParticles(EnumParticleTypes.HEART.getParticleID(), entity, 10);
}
}

View file

@ -6,6 +6,7 @@ import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.UParticles;
import com.minelittlepony.unicopia.player.IPlayer;
import com.minelittlepony.unicopia.power.data.Location;
import com.minelittlepony.util.WorldEvent;
import com.minelittlepony.util.vector.VecHelper;
import net.minecraft.block.BlockDoublePlant;
@ -85,10 +86,10 @@ public class PowerGrow implements IPower<Location> {
if (g.canGrow(w, pos, state, w.isRemote) && g.canUseBonemeal(w, w.rand, pos, state)) {
if (ItemDye.applyBonemeal(new ItemStack(Items.DYE, 1), w, pos)) {
w.playEvent(2005, pos, 0);
WorldEvent.BONEMEAL.play(w, pos, 0);
if (g instanceof BlockDoublePlant) {
w.playEvent(2005, pos.up(), 0);
WorldEvent.BONEMEAL.play(w, pos.up(), 0);
}
}
@ -103,7 +104,7 @@ public class PowerGrow implements IPower<Location> {
player.addExertion(3);
if (player.getWorld().isRemote) {
IPower.spawnParticles(UParticles.UNICORN_MAGIC, player, 1);
player.spawnParticles(UParticles.UNICORN_MAGIC, 1);
}
}

View file

@ -56,11 +56,11 @@ public class PowerMagic implements IPower<Hit> {
@Override
public void preApply(IPlayer player) {
IPower.spawnParticles(UParticles.UNICORN_MAGIC, player, 5);
player.spawnParticles(UParticles.UNICORN_MAGIC, 5);
}
@Override
public void postApply(IPlayer player) {
IPower.spawnParticles(UParticles.UNICORN_MAGIC, player, 5);
player.spawnParticles(UParticles.UNICORN_MAGIC, 5);
}
}

View file

@ -159,12 +159,11 @@ public class PowerTeleport implements IPower<Location> {
@Override
public void preApply(IPlayer player) {
player.addExertion(3);
IPower.spawnParticles(UParticles.UNICORN_MAGIC, player, 5);
player.spawnParticles(UParticles.UNICORN_MAGIC, 5);
}
@Override
public void postApply(IPlayer player) {
IPower.spawnParticles(UParticles.UNICORN_MAGIC, player, 5);
player.spawnParticles(UParticles.UNICORN_MAGIC, 5);
}
}

View file

@ -8,6 +8,7 @@ import java.util.stream.Stream;
import javax.annotation.Nullable;
import com.minelittlepony.unicopia.player.IOwned;
import com.minelittlepony.unicopia.power.IPower;
import com.minelittlepony.util.shape.IShape;
import com.minelittlepony.util.vector.VecHelper;
@ -49,6 +50,10 @@ public interface ICaster<E extends EntityLivingBase> extends IOwned<E>, ILevelle
return getEntity().getPositionVector();
}
default void spawnParticles(int particleId, int count) {
IPower.spawnParticles(particleId, getEntity(), count);
}
default void spawnParticles(IShape area, int count, Consumer<Vec3d> particleSpawner) {
Random rand = getWorld().rand;

View file

@ -54,7 +54,7 @@ public enum WorldEvent {
XP_POP(2002), PROJECTILE_HIT(2002),
EYE_OF_ENDER(2003),
MOB_SPAWN(2004),
BONEMEAN(2005),
BONEMEAL(2005),
DRAGON_BREATH(2006),
POTION_INSTANT(2007),
DRAGON_DEFEATED(3000),