That's one heck of a commit you've got there...

I may have got a bit behind with version control. A lot behind, in fact. Maybe I'll go back and split this sometime - then again, I probably won't. But hey, at least it's here!
This commit is contained in:
Electroblob77
2019-08-18 00:04:18 +01:00
parent 2680d02304
commit f37812be3e
1564 changed files with 47652 additions and 12984 deletions
@@ -0,0 +1,198 @@
package electroblob.wizardry.entity.projectile;
import electroblob.wizardry.Wizardry;
import electroblob.wizardry.registry.Spells;
import electroblob.wizardry.spell.Spell;
import electroblob.wizardry.util.MagicDamage;
import electroblob.wizardry.util.MagicDamage.DamageType;
import electroblob.wizardry.util.ParticleBuilder;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.projectile.EntitySmallFireball;
import net.minecraft.init.Blocks;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
/**
* It's a fireball - but unlike vanilla fireballs, it actually looks like a fireball, and isn't completely useless for
* attacking things (acceleration from stationary? Really, Mojang? No wonder I had so many blaze rods back in the day...)
*/
@Mod.EventBusSubscriber
public class EntityMagicFireball extends EntityMagicProjectile {
protected static final int ACCELERATION_CONVERSION_FACTOR = 10;
/** The damage dealt by this fireball. If this is -1, the damage for the fireball spell will be used instead;
* this is for when the fireball is not from a spell (i.e. a vanilla fireball replacement). */
protected float damage = -1;
/** The number of seconds entities are set on fire by this fireball. If this is -1, the damage for the fireball
* spell will be used instead; this is for when the fireball is not from a spell (i.e. a vanilla fireball replacement). */
protected int burnDuration = -1;
/** The lifetime of this fireball in ticks. This needs to be stored so that it can be changed for vanilla replacements,
* or mobs that shoot fireballs would have severely reduced range! */
protected int lifetime = 16;
public EntityMagicFireball(World world){
super(world);
this.setSize(0.5f, 0.5f);
}
public void setDamage(float damage){
this.damage = damage;
}
public void setBurnDuration(int burnDuration){
this.burnDuration = burnDuration;
}
public float getDamage(){
// I'm lazy, I'd rather not have an entire fireball spell class just to set two fields on the entity
return damage == -1 ? Spells.fireball.getProperty(Spell.DAMAGE).floatValue() : damage;
}
public int getBurnDuration(){
return burnDuration == -1 ? Spells.fireball.getProperty(Spell.BURN_DURATION).intValue() : burnDuration;
}
@Override
protected void onImpact(RayTraceResult rayTrace){
if(!world.isRemote){
Entity entityHit = rayTrace.entityHit;
if(entityHit != null){
float damage = getDamage() * damageMultiplier;
entityHit.attackEntityFrom(
MagicDamage.causeIndirectMagicDamage(this, this.getThrower(), DamageType.FIRE).setProjectile(),
damage);
if(!MagicDamage.isEntityImmune(DamageType.FIRE, entityHit) && getBurnDuration() > 0)
entityHit.setFire(getBurnDuration());
}else{
boolean flag = true;
if(this.getThrower() != null && this.getThrower() instanceof EntityLiving){
flag = net.minecraftforge.event.ForgeEventFactory.getMobGriefingEvent(this.world, this.getThrower());
}
if(flag){
BlockPos blockpos = rayTrace.getBlockPos().offset(rayTrace.sideHit);
if(this.world.isAirBlock(blockpos)){
this.world.setBlockState(blockpos, Blocks.FIRE.getDefaultState());
}
}
}
//this.playSound(WizardrySounds.ENTITY_MAGIC_FIREBALL_HIT, 2, 0.8f + rand.nextFloat() * 0.3f);
this.setDead();
}
}
@Override
public void onUpdate(){
super.onUpdate();
if(world.isRemote){
for(int i=0; i<5; i++){
double dx = (rand.nextDouble() - 0.5) * width;
double dy = (rand.nextDouble() - 0.5) * height + this.height/2 - 0.1; // -0.1 because flames aren't centred
double dz = (rand.nextDouble() - 0.5) * width;
double v = 0.06;
ParticleBuilder.create(ParticleBuilder.Type.MAGIC_FIRE)
.pos(this.getPositionVector().add(dx - this.motionX/2, dy, dz - this.motionZ/2))
.vel(-v * dx, -v * dy, -v * dz).scale(width*2).time(10).spawn(world);
if(ticksExisted > 1){
dx = (rand.nextDouble() - 0.5) * width;
dy = (rand.nextDouble() - 0.5) * height + this.height / 2 - 0.1;
dz = (rand.nextDouble() - 0.5) * width;
ParticleBuilder.create(ParticleBuilder.Type.MAGIC_FIRE)
.pos(this.getPositionVector().add(dx - this.motionX, dy, dz - this.motionZ))
.vel(-v * dx, -v * dy, -v * dz).scale(width*2).time(10).spawn(world);
}
}
}
}
public void setLifetime(int lifetime){
this.lifetime = lifetime;
}
@Override
public int getLifetime(){
return lifetime;
}
@Override
public boolean hasNoGravity(){
return true;
}
@Override
public boolean canRenderOnFire(){
return false;
}
@Override
public void writeSpawnData(ByteBuf buffer){
buffer.writeInt(lifetime);
super.writeSpawnData(buffer);
}
@Override
public void readSpawnData(ByteBuf buffer){
lifetime = buffer.readInt();
super.readSpawnData(buffer);
}
@Override
public void readEntityFromNBT(NBTTagCompound nbttagcompound){
super.readEntityFromNBT(nbttagcompound);
lifetime = nbttagcompound.getInteger("lifetime");
}
@Override
public void writeEntityToNBT(NBTTagCompound nbttagcompound){
super.writeEntityToNBT(nbttagcompound);
nbttagcompound.setInteger("lifetime", lifetime);
}
@SubscribeEvent
public static void onEntityJoinWorldEvent(EntityJoinWorldEvent event){
// Replaces all vanilla fireballs with wizardry ones
if(Wizardry.settings.replaceVanillaFireballs && event.getEntity() instanceof EntitySmallFireball){
event.setCanceled(true);
EntityMagicFireball fireball = new EntityMagicFireball(event.getWorld());
fireball.thrower = ((EntitySmallFireball)event.getEntity()).shootingEntity;
fireball.setPosition(event.getEntity().posX, event.getEntity().posY, event.getEntity().posZ);
fireball.setDamage(5);
fireball.setBurnDuration(5);
fireball.setLifetime(40);
fireball.motionX = ((EntitySmallFireball)event.getEntity()).accelerationX * ACCELERATION_CONVERSION_FACTOR;
fireball.motionY = ((EntitySmallFireball)event.getEntity()).accelerationY * ACCELERATION_CONVERSION_FACTOR;
fireball.motionZ = ((EntitySmallFireball)event.getEntity()).accelerationZ * ACCELERATION_CONVERSION_FACTOR;
event.getWorld().spawnEntity(fireball);
}
}
}