Reimplemented the cloud control powers for pegasi

This commit is contained in:
Sollace 2019-02-03 17:43:06 +02:00
parent 04145fa96a
commit 72103173aa
6 changed files with 172 additions and 32 deletions

View file

@ -167,7 +167,11 @@ public class EntityCloud extends EntityFlying implements IAnimals {
@Override @Override
protected void collideWithEntity(Entity other) { protected void collideWithEntity(Entity other) {
if (other instanceof EntityCloud) { if (other instanceof EntityCloud || other instanceof EntityPlayer) {
if (other.posY > posY) {
return;
}
super.collideWithEntity(other); super.collideWithEntity(other);
} }
} }
@ -264,10 +268,17 @@ public class EntityCloud extends EntityFlying implements IAnimals {
} }
if (setRainTimer(getRainTimer() - 1) == 0) { if (setRainTimer(getRainTimer() - 1) == 0) {
if (rand.nextInt(20000) == 0) { if (!getStationary()) {
pomf();
if (getCloudSize() > 1) {
setIsRaining(false);
setCloudSize(getCloudSize() - 1);
} else {
setDead(); setDead();
} }
} }
}
} else { } else {
if (rand.nextInt(8000) == 0 && canRainHere()) { if (rand.nextInt(8000) == 0 && canRainHere()) {
setRaining(); setRaining();
@ -303,11 +314,13 @@ public class EntityCloud extends EntityFlying implements IAnimals {
motionZ = 0; motionZ = 0;
} }
motionX /= (1 + getCloudSize());
motionZ /= (1 + getCloudSize());
super.onUpdate(); super.onUpdate();
double motionFactor = (1 + getCloudSize() / 4);
motionX /= motionFactor;
motionZ /= motionFactor;
hurtTime = 0; hurtTime = 0;
} }
@ -340,38 +353,31 @@ public class EntityCloud extends EntityFlying implements IAnimals {
} }
} }
} }
super.onCollideWithPlayer(player); super.onCollideWithPlayer(player);
} }
@Override @Override
protected void updateAITasks() { protected void updateAITasks() {
if (!getStationary()) { if (!getStationary()) {
super.updateAITasks();
if (!isBeingRidden()) { if (!isBeingRidden()) {
double distance = targetAltitude - posY; double distance = targetAltitude - posY;
if (targetAltitude < posY && !world.isAirBlock(getPosition())) {
distance = 0;
}
if (Math.abs(distance) < 1 && rand.nextInt(7000) == 0) { if (Math.abs(distance) < 1 && rand.nextInt(7000) == 0) {
targetAltitude = getRandomFlyingHeight(); targetAltitude = getRandomFlyingHeight();
distance = targetAltitude - posY; distance = targetAltitude - posY;
} }
if (rand.nextInt(7000) == 0) {
directionX = directionX == 0 ? rand.nextInt(3) - 1 : 0;
}
if (rand.nextInt(7000) == 0) {
directionZ = directionZ == 0 ? rand.nextInt(3) - 1 : 0;
}
if (Math.abs(distance) < 1) { if (Math.abs(distance) < 1) {
distance = 0; distance = 0;
} }
motionX -= 0.02; motionX -= 0.002;
motionX -= (Math.signum(directionX) * 0.699999988079071D - motionX) * 0.10000000149011612D;
motionY += (Math.signum(distance) * 0.699999988079071D - motionY) * 0.10000000149011612D; motionY += (Math.signum(distance) * 0.699999988079071D - motionY) * 0.10000000149011612D;
motionZ -= (Math.signum(directionZ) * 0.699999988079071D - motionZ) * 0.10000000149011612D;
} }
} }
} }
@ -439,6 +445,29 @@ public class EntityCloud extends EntityFlying implements IAnimals {
super.handleStatusUpdate(type); super.handleStatusUpdate(type);
} }
public void handlePegasusInteration(int interationType) {
if (!world.isRemote) {
switch (interationType) {
case 1:
setIsRaining(!getIsRaining());
break;
case 2:
spawnThunderbolt();
break;
}
}
pomf();
}
public void pomf() {
for (int i = 0; i < 50 * getCloudSize(); i++) {
Particles.instance().getEntityEmitter().emitDiggingParticles(this, UBlocks.cloud.getDefaultState());
}
playHurtSound(DamageSource.GENERIC);
}
@Override @Override
public boolean attackEntityFrom(DamageSource source, float amount) { public boolean attackEntityFrom(DamageSource source, float amount) {
Entity attacker = source.getImmediateSource(); Entity attacker = source.getImmediateSource();
@ -515,7 +544,7 @@ public class EntityCloud extends EntityFlying implements IAnimals {
} else if (stack != null && stack.getItem() instanceof ItemSpade) { } else if (stack != null && stack.getItem() instanceof ItemSpade) {
return super.attackEntityFrom(source, amount * 1.5f); return super.attackEntityFrom(source, amount * 1.5f);
} else if (canFly) { } else if (canFly) {
if (player.posY < posY) { if (player.posY < posY || !world.isAirBlock(getPosition())) {
targetAltitude = posY + 5; targetAltitude = posY + 5;
} else if (player.posY > posY) { } else if (player.posY > posY) {
targetAltitude = posY - 5; targetAltitude = posY - 5;
@ -555,7 +584,6 @@ public class EntityCloud extends EntityFlying implements IAnimals {
&& Predicates.ITEM_INTERACT_WITH_CLOUDS.test((EntityItem)e); && Predicates.ITEM_INTERACT_WITH_CLOUDS.test((EntityItem)e);
} }
@Override @Override
protected void dropFewItems(boolean hitByPlayer, int looting) { protected void dropFewItems(boolean hitByPlayer, int looting) {
if (hitByPlayer) { if (hitByPlayer) {
@ -611,7 +639,7 @@ public class EntityCloud extends EntityFlying implements IAnimals {
entity.onGround = true; entity.onGround = true;
entity.motionY += (((floatStrength > 2 ? 1 : floatStrength/2) * 0.699999998079071D) - entity.motionY + boundModifier * 0.7) * 0.10000000149011612D; entity.motionY += (((floatStrength > 2 ? 1 : floatStrength/2) * 0.699999998079071D) - entity.motionY + boundModifier * 0.7) * 0.10000000149011612D;
if (!getStationary()) { if (!getStationary()) {
entity.motionX -= 0.013; entity.motionX -= 0.0105;
} }
if (!getStationary() && entity.motionY > 0.4 && world.rand.nextInt(900) == 0) { if (!getStationary() && entity.motionY > 0.4 && world.rand.nextInt(900) == 0) {
@ -632,15 +660,10 @@ public class EntityCloud extends EntityFlying implements IAnimals {
return false; return false;
} }
@Override
protected void doBlockCollisions() {
super.doBlockCollisions();
}
@Override @Override
public void move(MoverType type, double x, double y, double z) { public void move(MoverType type, double x, double y, double z) {
this.setEntityBoundingBox(this.getEntityBoundingBox().offset(x, y, z)); setEntityBoundingBox(getEntityBoundingBox().offset(x, y, z));
this.resetPositionToBB(); resetPositionToBB();
} }
public int getFloatStrength(Entity entity) { public int getFloatStrength(Entity entity) {

View file

@ -72,6 +72,8 @@ public class EntityWildCloud extends EntityCloud {
@Override @Override
public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, IEntityLivingData pack) { public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, IEntityLivingData pack) {
pack = super.onInitialSpawn(difficulty, pack);
if (!(pack instanceof PackData)) { if (!(pack instanceof PackData)) {
float minSpawnHeight = getMinimumFlyingHeight(); float minSpawnHeight = getMinimumFlyingHeight();
@ -84,6 +86,14 @@ public class EntityWildCloud extends EntityCloud {
collideWithNearbyEntities(); collideWithNearbyEntities();
} }
if (world.isRainingAt(getPosition())) {
setIsRaining(true);
}
if (world.isThundering()) {
setIsThundering(true);
}
pack = new PackData(this); pack = new PackData(this);
} else { } else {
PackData packData = (PackData)pack; PackData packData = (PackData)pack;
@ -91,11 +101,14 @@ public class EntityWildCloud extends EntityCloud {
Vec3d position = packData.getUnOccupiedPosition(getCloudSize()); Vec3d position = packData.getUnOccupiedPosition(getCloudSize());
setIsRaining(packData.leader.getIsRaining());
setIsThundering(packData.leader.getIsThundering());
setLocationAndAngles(position.x, position.y, position.z, packData.leader.rotationYaw, packData.leader.rotationPitch); setLocationAndAngles(position.x, position.y, position.z, packData.leader.rotationYaw, packData.leader.rotationPitch);
collideWithNearbyEntities(); collideWithNearbyEntities();
} }
return super.onInitialSpawn(difficulty, pack); return pack;
} }
static class PackData implements IEntityLivingData { static class PackData implements IEntityLivingData {

View file

@ -0,0 +1,90 @@
package com.minelittlepony.unicopia.power;
import org.lwjgl.input.Keyboard;
import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.UParticles;
import com.minelittlepony.unicopia.entity.EntityCloud;
import com.minelittlepony.unicopia.player.IPlayer;
import com.minelittlepony.unicopia.power.data.Numeric;
import com.minelittlepony.util.vector.VecHelper;
public class PowerCloudBase implements IPower<Numeric> {
@Override
public String getKeyName() {
return "unicopia.power.cloud";
}
@Override
public int getKeyCode() {
return Keyboard.KEY_J;
}
@Override
public int getWarmupTime(IPlayer player) {
return 10;
}
@Override
public int getCooldownTime(IPlayer player) {
return 5;
}
@Override
public boolean canUse(Race playerSpecies) {
return playerSpecies.canInteractWithClouds();
}
@Override
public Numeric tryActivate(IPlayer player) {
EntityCloud cloud = findTarget(player);
if (cloud != null) {
Numeric data = new Numeric(player.getOwner().inventory.currentItem + 1);
cloud.handlePegasusInteration(data.type);
return data;
}
return null;
}
@Override
public Class<Numeric> getPackageType() {
return Numeric.class;
}
@Override
public void apply(IPlayer player, Numeric data) {
EntityCloud cloud = findTarget(player);
if (cloud != null) {
cloud.handlePegasusInteration(data.type);
}
}
protected EntityCloud findTarget(IPlayer player) {
if (player.getOwner().isRiding() && player.getOwner().getRidingEntity() instanceof EntityCloud) {
return (EntityCloud)player.getOwner().getRidingEntity();
}
Object e = VecHelper.getLookedAtEntity(player.getOwner(), 18);
if (e instanceof EntityCloud) {
return (EntityCloud)e;
}
return null;
}
@Override
public void preApply(IPlayer player) {
IPower.spawnParticles(UParticles.MAGIC_PARTICLE, player, 10);
}
@Override
public void postApply(IPlayer player) {
IPower.spawnParticles(UParticles.RAIN_PARTICLE, player, 5);
}
}

View file

@ -32,6 +32,7 @@ public class PowersRegistry {
registerPower(new PowerFeed()); registerPower(new PowerFeed());
registerPower(new PowerCarry()); registerPower(new PowerCarry());
registerPower(new PowerDisguise()); registerPower(new PowerDisguise());
registerPower(new PowerCloudBase());
} }
public boolean hasRegisteredPower(int keyCode) { public boolean hasRegisteredPower(int keyCode) {

View file

@ -0,0 +1,14 @@
package com.minelittlepony.unicopia.power.data;
import com.google.gson.annotations.Expose;
import com.minelittlepony.unicopia.power.IData;
public class Numeric implements IData {
@Expose
public int type;
public Numeric(int t) {
type = t;
}
}

View file

@ -176,8 +176,7 @@ unicopia.power.earth=Secondary Earth Pony ability
unicopia.power.teleport=Primary Unicorn ability unicopia.power.teleport=Primary Unicorn ability
unicopia.power.magic=Secondary Unicorn ability unicopia.power.magic=Secondary Unicorn ability
unicopia.power.rain=Primary Pegasus ability unicopia.power.cloud=Primary Pegasus ability
unicopia.power.thunder=Secondary Pegasus ability
unicopia.power.carry=Pick up & Drop riders unicopia.power.carry=Pick up & Drop riders
unicopia.power.feed=Primary Changeling ability unicopia.power.feed=Primary Changeling ability