mirror of
https://github.com/Sollace/Unicopia.git
synced 2025-02-17 10:24:23 +01:00
Added an exertion effect when using magic, improved behaviour of the stom knockback
This commit is contained in:
parent
3d3409730e
commit
d3ddd47ed5
10 changed files with 117 additions and 39 deletions
|
@ -4,6 +4,7 @@ import net.minecraft.client.Minecraft;
|
|||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.item.EnumAction;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraftforge.client.event.EntityViewRenderEvent;
|
||||
import net.minecraftforge.event.AttachCapabilitiesEvent;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||
|
@ -117,6 +118,15 @@ public class Unicopia {
|
|||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void modifyFOV(EntityViewRenderEvent.FOVModifier event) {
|
||||
float fov = event.getFOV();
|
||||
|
||||
fov += PlayerSpeciesList.instance().getPlayer(Minecraft.getMinecraft().player).getExertion() * 5;
|
||||
|
||||
event.setFOV(fov);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void attachCapabilities(AttachCapabilitiesEvent<Entity> event) {
|
||||
FBS.attach(event);
|
||||
|
|
|
@ -19,6 +19,14 @@ public interface IPlayer extends ICaster<EntityPlayer>, InbtSerialisable, IUpdat
|
|||
|
||||
IAbilityReceiver getAbilities();
|
||||
|
||||
float getExertion();
|
||||
|
||||
void setExertion(float exertion);
|
||||
|
||||
default void addExertion(int exertion) {
|
||||
setExertion(getExertion() + exertion/100F);
|
||||
}
|
||||
|
||||
boolean isClientPlayer();
|
||||
|
||||
void copyFrom(IPlayer oldPlayer);
|
||||
|
|
|
@ -61,7 +61,7 @@ class PlayerAbilityDelegate implements IAbilityReceiver, IUpdatable, InbtSeriali
|
|||
if (activeAbility != null && activeAbility.canUse(player.getPlayerSpecies())) {
|
||||
if (!abilityTriggered) {
|
||||
if (warmup < activeAbility.getWarmupTime(player)) {
|
||||
activeAbility.preApply(entity);
|
||||
activeAbility.preApply(player);
|
||||
warmup++;
|
||||
} else if (player.isClientPlayer()) {
|
||||
if (activeAbility.canActivate(entity.getEntityWorld(), player)) {
|
||||
|
@ -76,7 +76,7 @@ class PlayerAbilityDelegate implements IAbilityReceiver, IUpdatable, InbtSeriali
|
|||
}
|
||||
}
|
||||
} else if (cooldown > 0) {
|
||||
activeAbility.postApply(entity);
|
||||
activeAbility.postApply(player);
|
||||
cooldown--;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,8 @@ class PlayerCapabilities implements IPlayer, ICaster<EntityPlayer> {
|
|||
|
||||
private static final DataParameter<Integer> PLAYER_RACE = EntityDataManager
|
||||
.createKey(EntityPlayer.class, DataSerializers.VARINT);
|
||||
private static final DataParameter<Float> EXERTION = EntityDataManager
|
||||
.createKey(EntityPlayer.class, DataSerializers.FLOAT);
|
||||
|
||||
private final PlayerAbilityDelegate powers = new PlayerAbilityDelegate(this);
|
||||
|
||||
|
@ -43,6 +45,7 @@ class PlayerCapabilities implements IPlayer, ICaster<EntityPlayer> {
|
|||
setOwner(player);
|
||||
|
||||
player.getDataManager().register(PLAYER_RACE, Race.HUMAN.ordinal());
|
||||
player.getDataManager().register(EXERTION, 0F);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -73,6 +76,16 @@ class PlayerCapabilities implements IPlayer, ICaster<EntityPlayer> {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getExertion() {
|
||||
return getOwner().getDataManager().get(EXERTION);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setExertion(float exertion) {
|
||||
getOwner().getDataManager().set(EXERTION, Math.max(0, exertion));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendCapabilities(boolean full) {
|
||||
if (!getOwner().getEntityWorld().isRemote) {
|
||||
|
@ -113,6 +126,8 @@ class PlayerCapabilities implements IPlayer, ICaster<EntityPlayer> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
addExertion(-1);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -39,20 +39,22 @@ public interface IPower<T extends IData> extends IKeyBind {
|
|||
return player.posY + player.getEyeHeight() - 1;
|
||||
}
|
||||
|
||||
static void spawnParticles(int particleId, EntityPlayer player, int count) {
|
||||
static void spawnParticles(int particleId, IPlayer player, int count) {
|
||||
|
||||
double halfDist = player.getEyeHeight() / 1.5;
|
||||
double middle = player.getEntityBoundingBox().minY + halfDist;
|
||||
EntityPlayer entity = player.getOwner();
|
||||
|
||||
double halfDist = entity.getEyeHeight() / 1.5;
|
||||
double middle = entity.getEntityBoundingBox().minY + halfDist;
|
||||
|
||||
IShape shape = new Sphere(false, (float)halfDist);
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
Vec3d point = shape.computePoint(player.world.rand);
|
||||
Vec3d point = shape.computePoint(entity.getEntityWorld().rand);
|
||||
|
||||
Particles.instance().spawnParticle(particleId, false,
|
||||
player.posX + point.x,
|
||||
entity.posX + point.x,
|
||||
middle + point.y,
|
||||
player.posZ + point.z,
|
||||
entity.posZ + point.z,
|
||||
0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
@ -114,12 +116,12 @@ public interface IPower<T extends IData> extends IKeyBind {
|
|||
* Called just before the ability is activated.
|
||||
* @param player The current player
|
||||
*/
|
||||
void preApply(EntityPlayer player);
|
||||
void preApply(IPlayer player);
|
||||
|
||||
/**
|
||||
* Called every tick until the cooldown timer runs out.
|
||||
* @param player The current player
|
||||
*/
|
||||
void postApply(EntityPlayer player);
|
||||
void postApply(IPlayer player);
|
||||
|
||||
}
|
||||
|
|
|
@ -123,15 +123,19 @@ public class PowerFeed implements IPower<Hit> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void preApply(EntityPlayer player) { }
|
||||
public void preApply(IPlayer player) {
|
||||
player.addExertion(6);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postApply(EntityPlayer player) {
|
||||
public void postApply(IPlayer player) {
|
||||
EntityPlayer entity = player.getOwner();
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
Particles.instance().spawnParticle(EnumParticleTypes.HEART.getParticleID(), false,
|
||||
player.posX + player.world.rand.nextFloat() * 2 - 1,
|
||||
player.posY + player.world.rand.nextFloat() * 2 - 1,
|
||||
player.posZ + player.world.rand.nextFloat() * 2 - 1,
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -100,12 +100,13 @@ public class PowerGrow implements IPower<Location> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void preApply(EntityPlayer player) {
|
||||
public void preApply(IPlayer player) {
|
||||
player.addExertion(3);
|
||||
IPower.spawnParticles(Unicopia.MAGIC_PARTICLE, player, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postApply(EntityPlayer player) {
|
||||
public void postApply(IPlayer player) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,10 +64,14 @@ public class PowerMagic implements IPower<PowerMagic.Magic> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void preApply(EntityPlayer player) { }
|
||||
public void preApply(IPlayer player) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postApply(EntityPlayer player) { }
|
||||
public void postApply(IPlayer player) {
|
||||
|
||||
}
|
||||
|
||||
class Magic implements IData {
|
||||
|
||||
|
|
|
@ -26,12 +26,14 @@ import net.minecraft.block.material.Material;
|
|||
import net.minecraft.block.properties.IProperty;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.SharedMonsterAttributes;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumParticleTypes;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
@ -94,30 +96,61 @@ public class PowerStomp implements IPower<PowerStomp.Data> {
|
|||
return PowerStomp.Data.class;
|
||||
}
|
||||
|
||||
public static BlockPos getSolidBlockBelow(BlockPos pos, World w) {
|
||||
while (w.isValid(pos)) {
|
||||
pos = pos.down();
|
||||
if (w.getBlockState(pos).isSideSolid(w, pos, EnumFacing.UP)) {
|
||||
return pos;
|
||||
}
|
||||
}
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(EntityPlayer player, Data data) {
|
||||
|
||||
double rad = 4;
|
||||
|
||||
data.hitType = 1;
|
||||
|
||||
if (data.hitType == 0) {
|
||||
player.addVelocity(0, -6, 0);
|
||||
BlockPos pos = player.getPosition();
|
||||
AxisAlignedBB box = new AxisAlignedBB(player.posX - rad, player.posY - rad, player.posZ - rad, player.posX + rad, player.posY + rad, player.posZ + rad);
|
||||
BlockPos ppos = player.getPosition();
|
||||
BlockPos pos = getSolidBlockBelow(ppos, player.getEntityWorld());
|
||||
|
||||
player.addVelocity(0, -(ppos.distanceSq(pos)), 0);
|
||||
|
||||
AxisAlignedBB box = new AxisAlignedBB(
|
||||
player.posX - rad, player.posY - rad, player.posZ - rad,
|
||||
player.posX + rad, player.posY + rad, player.posZ + rad
|
||||
);
|
||||
List<Entity> entities = player.world.getEntitiesWithinAABBExcludingEntity(player, box);
|
||||
|
||||
for (Entity i : entities) {
|
||||
double dist = Math.sqrt(i.getDistanceSq(pos));
|
||||
|
||||
if (dist <= rad + 3) {
|
||||
i.addVelocity(i.posX - player.posX, i.posY - player.posY, i.posZ - player.posZ);
|
||||
double force = dist / 5;
|
||||
i.addVelocity(
|
||||
-(player.posX - i.posX) / force,
|
||||
-(player.posY - i.posY - 2) / force + (dist < 1 ? dist : 0),
|
||||
-(player.posZ - i.posZ) / force);
|
||||
|
||||
DamageSource damage = MagicalDamageSource.causePlayerDamage("smash", player);
|
||||
float amount = 4 / (float)dist;
|
||||
|
||||
double amount = (4 * player.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getAttributeValue()) / (float)dist;
|
||||
|
||||
|
||||
if (i instanceof EntityPlayer) {
|
||||
Race race = PlayerSpeciesList.instance().getPlayer((EntityPlayer)i).getPlayerSpecies();
|
||||
if (race.canUseEarth()) amount /= 3;
|
||||
if (race.canFly()) amount *= 4;
|
||||
if (race.canUseEarth()) {
|
||||
amount /= 3;
|
||||
}
|
||||
|
||||
if (race.canFly()) {
|
||||
amount *= 4;
|
||||
}
|
||||
}
|
||||
i.attackEntityFrom(damage, amount);
|
||||
|
||||
i.attackEntityFrom(damage, (float)amount);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -157,18 +190,17 @@ public class PowerStomp implements IPower<PowerStomp.Data> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void preApply(EntityPlayer player) {
|
||||
player.spawnRunningParticles();
|
||||
public void preApply(IPlayer player) {
|
||||
player.addExertion(40);
|
||||
player.getOwner().spawnRunningParticles();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postApply(EntityPlayer player) {
|
||||
IPlayer prop = PlayerSpeciesList.instance().getPlayer(player);
|
||||
public void postApply(IPlayer player) {
|
||||
int timeDiff = getCooldownTime(player) - player.getAbilities().getRemainingCooldown();
|
||||
|
||||
int timeDiff = getCooldownTime(prop) - prop.getAbilities().getRemainingCooldown();
|
||||
|
||||
if (player.world.getWorldTime() % 1 == 0 || timeDiff == 0) {
|
||||
spawnParticleRing(player, timeDiff, 1);
|
||||
if (player.getOwner().getEntityWorld().getWorldTime() % 1 == 0 || timeDiff == 0) {
|
||||
spawnParticleRing(player.getOwner(), timeDiff, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -142,12 +142,14 @@ public class PowerTeleport implements IPower<Location> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void preApply(EntityPlayer player) {
|
||||
public void preApply(IPlayer player) {
|
||||
player.addExertion(1);
|
||||
|
||||
IPower.spawnParticles(Unicopia.MAGIC_PARTICLE, player, 5);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postApply(EntityPlayer player) {
|
||||
public void postApply(IPlayer player) {
|
||||
IPower.spawnParticles(Unicopia.MAGIC_PARTICLE, player, 5);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue