mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-20 20:22:33 +00:00
99 lines
2.6 KiB
Java
99 lines
2.6 KiB
Java
/**
|
|
* This class was created by <Vazkii>. It's distributed as
|
|
* part of the Botania Mod. Get the Source Code in github:
|
|
* https://github.com/Vazkii/Botania
|
|
*
|
|
* Botania is Open Source and distributed under the
|
|
* Botania License: http://botaniamod.net/license.php
|
|
*
|
|
* File Created @ [Jul 25, 2015, 12:35:51 AM (GMT)]
|
|
*/
|
|
package vazkii.botania.common.entity;
|
|
|
|
import net.minecraft.entity.Entity;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
import net.minecraft.world.World;
|
|
import vazkii.botania.common.core.helper.Vector3;
|
|
import vazkii.botania.common.item.ModItems;
|
|
import vazkii.botania.common.item.lens.ItemLens;
|
|
|
|
public class EntityManaStorm extends Entity {
|
|
|
|
private static final String TAG_TIME = "time";
|
|
private static final String TAG_BURSTS_FIRED = "burstsFired";
|
|
private static final String TAG_DEATH_TIME = "deathTime";
|
|
|
|
public static final int TOTAL_BURSTS = 250;
|
|
public static final int DEATH_TIME = 200;
|
|
|
|
public int liveTime;
|
|
public int burstsFired;
|
|
public int deathTime;
|
|
|
|
public EntityManaStorm(World p_i1582_1_) {
|
|
super(p_i1582_1_);
|
|
}
|
|
|
|
@Override
|
|
protected void entityInit() {
|
|
// NO-OP
|
|
}
|
|
|
|
@Override
|
|
public void onUpdate() {
|
|
super.onUpdate();
|
|
liveTime++;
|
|
|
|
int diffTime = Math.max(1, 30 - (int) (liveTime / 45f));
|
|
if(burstsFired < TOTAL_BURSTS && liveTime % diffTime == 0) {
|
|
if(!worldObj.isRemote)
|
|
spawnBurst();
|
|
burstsFired++;
|
|
}
|
|
|
|
if(burstsFired >= TOTAL_BURSTS) {
|
|
deathTime++;
|
|
if(deathTime >= DEATH_TIME) {
|
|
setDead();
|
|
worldObj.newExplosion(this, posX, posY, posZ, 8F, true, true);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void spawnBurst() {
|
|
EntityManaBurst burst = new EntityManaBurst(worldObj);
|
|
burst.setPosition(posX, posY, posZ);
|
|
|
|
float motionModifier = 0.5F;
|
|
burst.setColor(0x20FF20);
|
|
burst.setMana(120);
|
|
burst.setStartingMana(340);
|
|
burst.setMinManaLoss(50);
|
|
burst.setManaLossPerTick(1F);
|
|
burst.setGravity(0F);
|
|
|
|
ItemStack lens = new ItemStack(ModItems.lens, 1, ItemLens.STORM);
|
|
burst.setSourceLens(lens);
|
|
|
|
Vector3 motion = new Vector3(Math.random() - 0.5, Math.random() - 0.5, Math.random() - 0.5).normalize().multiply(motionModifier);
|
|
burst.setMotion(motion.x, motion.y, motion.z);
|
|
worldObj.spawnEntityInWorld(burst);
|
|
}
|
|
|
|
@Override
|
|
protected void readEntityFromNBT(NBTTagCompound cmp) {
|
|
liveTime = cmp.getInteger(TAG_TIME);
|
|
burstsFired = cmp.getInteger(TAG_BURSTS_FIRED);
|
|
deathTime = cmp.getInteger(TAG_DEATH_TIME);
|
|
}
|
|
|
|
@Override
|
|
protected void writeEntityToNBT(NBTTagCompound cmp) {
|
|
cmp.setInteger(TAG_TIME, liveTime);
|
|
cmp.setInteger(TAG_BURSTS_FIRED, burstsFired);
|
|
cmp.setInteger(TAG_DEATH_TIME, deathTime);
|
|
}
|
|
|
|
}
|