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