BloodMagic/src/main/java/WayofTime/bloodmagic/alchemyArray/AlchemyArrayEffectBinding.java

72 lines
2.4 KiB
Java
Raw Normal View History

package WayofTime.bloodmagic.alchemyArray;
2017-08-15 21:30:48 -07:00
import WayofTime.bloodmagic.client.render.alchemyArray.BindingAlchemyCircleRenderer;
import net.minecraft.entity.effect.EntityLightningBolt;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
2017-08-15 21:30:48 -07:00
public class AlchemyArrayEffectBinding extends AlchemyArrayEffectCrafting {
public AlchemyArrayEffectBinding(String key, ItemStack outputStack) {
super(key, outputStack, 200);
}
@Override
2017-08-15 21:30:48 -07:00
public boolean update(TileEntity tile, int ticksActive) {
if (ticksActive >= 50 && ticksActive <= 250) {
// TODO: Find a way to spawn lightning from only the server side -
// does not render when just spawned on server, not client.
this.spawnLightningOnCircle(tile.getWorld(), tile.getPos(), ticksActive);
}
2017-08-15 21:30:48 -07:00
if (tile.getWorld().isRemote) {
return false;
}
2017-08-15 21:30:48 -07:00
if (ticksActive >= 300) {
BlockPos pos = tile.getPos();
ItemStack output = outputStack.copy();
EntityItem outputEntity = new EntityItem(tile.getWorld(), pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, output);
2017-01-01 21:43:34 -08:00
tile.getWorld().spawnEntity(outputEntity);
return true;
}
return false;
}
2017-08-15 21:30:48 -07:00
public void spawnLightningOnCircle(World world, BlockPos pos, int ticksActive) {
if (ticksActive % 50 == 0) {
int circle = ticksActive / 50 - 1;
float distance = BindingAlchemyCircleRenderer.getDistanceOfCircle(circle, ticksActive);
float angle = BindingAlchemyCircleRenderer.getAngleOfCircle(circle, ticksActive);
double dispX = distance * Math.sin(angle);
double dispZ = -distance * Math.cos(angle);
EntityLightningBolt lightning = new EntityLightningBolt(world, pos.getX() + dispX, pos.getY(), pos.getZ() + dispZ, true);
2017-01-01 21:43:34 -08:00
world.spawnEntity(lightning);
}
}
@Override
2017-08-15 21:30:48 -07:00
public void writeToNBT(NBTTagCompound tag) {
//EMPTY
}
@Override
2017-08-15 21:30:48 -07:00
public void readFromNBT(NBTTagCompound tag) {
//EMPTY
}
@Override
2017-08-15 21:30:48 -07:00
public AlchemyArrayEffect getNewCopy() {
return new AlchemyArrayEffectBinding(key, outputStack);
}
}