mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
142 lines
3.6 KiB
Java
142 lines
3.6 KiB
Java
package com.hbm.entity.logic;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
import com.hbm.blocks.ModBlocks;
|
|
import com.hbm.entity.effect.EntityEMPBlast;
|
|
import com.hbm.explosion.ExplosionLarge;
|
|
import com.hbm.interfaces.IConsumer;
|
|
import com.hbm.interfaces.ISource;
|
|
import com.hbm.packet.PacketDispatcher;
|
|
import com.hbm.packet.ParticleBurstPacket;
|
|
|
|
import cofh.api.energy.IEnergyProvider;
|
|
import net.minecraft.block.Block;
|
|
import net.minecraft.entity.Entity;
|
|
import net.minecraft.init.Blocks;
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
import net.minecraft.tileentity.TileEntity;
|
|
import net.minecraft.world.World;
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
|
|
|
public class EntityEMP extends Entity {
|
|
|
|
List<int[]> machines;
|
|
int life = 2 * 60 * 20;
|
|
|
|
public EntityEMP(World p_i1582_1_) {
|
|
super(p_i1582_1_);
|
|
}
|
|
|
|
@Override
|
|
public void onUpdate() {
|
|
|
|
if(!worldObj.isRemote) {
|
|
if(machines == null) {
|
|
allocate();
|
|
} else {
|
|
shock();
|
|
}
|
|
|
|
if(this.ticksExisted > life)
|
|
this.setDead();
|
|
}
|
|
}
|
|
|
|
private void allocate() {
|
|
|
|
machines = new ArrayList();
|
|
|
|
int radius = 100;
|
|
|
|
for(int x = -radius; x <= radius; x++) {
|
|
|
|
int x2 = (int) Math.pow(x, 2);
|
|
|
|
for(int y = -radius; y <= radius; y++) {
|
|
|
|
int y2 = (int) Math.pow(y, 2);
|
|
|
|
for(int z = -radius; z <= radius; z++) {
|
|
|
|
int z2 = (int) Math.pow(z, 2);
|
|
|
|
if(Math.sqrt(x2 + y2 + z2) <= radius) {
|
|
add((int)posX + x, (int)posY + y, (int)posZ + z);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void shock() {
|
|
|
|
for(int i = 0; i < machines.size(); i++) {
|
|
emp(
|
|
machines.get(i)[0],
|
|
machines.get(i)[1],
|
|
machines.get(i)[2]
|
|
);
|
|
}
|
|
}
|
|
|
|
private void add(int x, int y, int z) {
|
|
TileEntity te = worldObj.getTileEntity(x, y, z);
|
|
|
|
if (te != null && te instanceof ISource) {
|
|
machines.add(new int[] { x, y, z });
|
|
} else if (te != null && te instanceof IConsumer) {
|
|
machines.add(new int[] { x, y, z });
|
|
} else if (te != null && te instanceof IEnergyProvider) {
|
|
machines.add(new int[] { x, y, z });
|
|
}
|
|
}
|
|
|
|
private void emp(int x, int y, int z) {
|
|
|
|
Block b = worldObj.getBlock(x,y,z);
|
|
TileEntity te = worldObj.getTileEntity(x, y, z);
|
|
|
|
boolean flag = false;
|
|
|
|
if (te != null && te instanceof ISource) {
|
|
|
|
((ISource)te).setSPower(0);
|
|
flag = true;
|
|
}
|
|
if (te != null && te instanceof IConsumer) {
|
|
|
|
((IConsumer)te).setPower(0);
|
|
flag = true;
|
|
}
|
|
if (te != null && te instanceof IEnergyProvider) {
|
|
|
|
((IEnergyProvider)te).extractEnergy(ForgeDirection.UP, ((IEnergyProvider)te).getEnergyStored(ForgeDirection.UP), false);
|
|
((IEnergyProvider)te).extractEnergy(ForgeDirection.DOWN, ((IEnergyProvider)te).getEnergyStored(ForgeDirection.DOWN), false);
|
|
((IEnergyProvider)te).extractEnergy(ForgeDirection.NORTH, ((IEnergyProvider)te).getEnergyStored(ForgeDirection.NORTH), false);
|
|
((IEnergyProvider)te).extractEnergy(ForgeDirection.SOUTH, ((IEnergyProvider)te).getEnergyStored(ForgeDirection.SOUTH), false);
|
|
((IEnergyProvider)te).extractEnergy(ForgeDirection.EAST, ((IEnergyProvider)te).getEnergyStored(ForgeDirection.EAST), false);
|
|
((IEnergyProvider)te).extractEnergy(ForgeDirection.WEST, ((IEnergyProvider)te).getEnergyStored(ForgeDirection.WEST), false);
|
|
flag = true;
|
|
}
|
|
|
|
if(flag && rand.nextInt(20) == 0) {
|
|
|
|
PacketDispatcher.wrapper.sendToAll(new ParticleBurstPacket(x, y, z, Block.getIdFromBlock(Blocks.stained_glass), 3));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@Override
|
|
protected void entityInit() { }
|
|
|
|
@Override
|
|
protected void readEntityFromNBT(NBTTagCompound nbt) { }
|
|
|
|
@Override
|
|
protected void writeEntityToNBT(NBTTagCompound nbt) { }
|
|
|
|
}
|