use of stevekung.mods.moreplanets.entity.EntityBlackHole in project MorePlanets by SteveKunG.
the class TileEntityDarkEnergyReceiver method update.
@Override
public void update() {
super.update();
if (!this.world.isRemote) {
if (this.activated && !this.disabled) {
if (!this.successful) {
int radius = 32;
List<Entity> entity = this.world.getEntitiesWithinAABB(Entity.class, new AxisAlignedBB(this.pos.getX() - radius, this.pos.getY() - radius, this.pos.getZ() - radius, this.pos.getX() + radius, this.pos.getY() + radius, this.pos.getZ() + radius));
for (Entity around : entity) {
if (around instanceof EntityLivingBase) {
EntityLivingBase living = (EntityLivingBase) around;
if (!(living instanceof EntityPlayer)) {
living.addPotionEffect(new PotionEffect(MPPotions.DARK_ENERGY, 200, 0));
}
if (around instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) around;
if (!player.capabilities.isCreativeMode && !player.isPotionActive(MPPotions.DARK_ENERGY_PROTECTION)) {
player.addPotionEffect(new PotionEffect(MPPotions.DARK_ENERGY, 200, 0));
}
}
}
}
}
if (this.activatedTick < this.getSuccessfulTick()) {
if (this.activatedTick % 20 == 0) {
this.world.playSound(null, this.pos.getX(), this.pos.getY(), this.pos.getZ(), MPSounds.MACHINE_ACTIVATE_AMBIENT, SoundCategory.BLOCKS, 1.0F, 1.025F);
}
if (this.activatedTick >= this.getSuccessfulTick() - 5 && this.activatedTick <= this.getSuccessfulTick()) {
this.world.playSound(null, this.pos.getX(), this.pos.getY(), this.pos.getZ(), MPSounds.MACHINE_STOP, SoundCategory.BLOCKS, 1.0F, 1.0F);
}
if (!this.failed) {
if (this.world.rand.nextInt(50) == 0) {
EntityDarkLightningBolt bolt = new EntityDarkLightningBolt(this.world);
bolt.setLocationAndAngles(this.pos.getX() + 3, this.pos.getY() + 2.5D, this.pos.getZ() + 3, 0.0F, 0.0F);
this.world.spawnEntity(bolt);
}
if (this.world.rand.nextInt(50) == 0) {
EntityDarkLightningBolt bolt = new EntityDarkLightningBolt(this.world);
bolt.setLocationAndAngles(this.pos.getX() - 3, this.pos.getY() + 2.5D, this.pos.getZ() + 3, 0.0F, 0.0F);
this.world.spawnEntity(bolt);
}
if (this.world.rand.nextInt(50) == 0) {
EntityDarkLightningBolt bolt = new EntityDarkLightningBolt(this.world);
bolt.setLocationAndAngles(this.pos.getX() + 3, this.pos.getY() + 2.5D, this.pos.getZ() - 3, 0.0F, 0.0F);
this.world.spawnEntity(bolt);
}
if (this.world.rand.nextInt(50) == 0) {
EntityDarkLightningBolt bolt = new EntityDarkLightningBolt(this.world);
bolt.setLocationAndAngles(this.pos.getX() - 3, this.pos.getY() + 2.5D, this.pos.getZ() - 3, 0.0F, 0.0F);
this.world.spawnEntity(bolt);
}
this.activatedTick++;
}
}
if (this.failed) {
this.failedTick++;
if (this.world.rand.nextInt(12) == 0) {
EntityDarkLightningBolt bolt = new EntityDarkLightningBolt(this.world);
bolt.setLocationAndAngles(this.pos.getX() + 3, this.pos.getY() + 2.5D, this.pos.getZ() + 3, 0.0F, 0.0F);
this.world.spawnEntity(bolt);
}
if (this.world.rand.nextInt(12) == 0) {
EntityDarkLightningBolt bolt = new EntityDarkLightningBolt(this.world);
bolt.setLocationAndAngles(this.pos.getX() - 3, this.pos.getY() + 2.5D, this.pos.getZ() + 3, 0.0F, 0.0F);
this.world.spawnEntity(bolt);
}
if (this.world.rand.nextInt(12) == 0) {
EntityDarkLightningBolt bolt = new EntityDarkLightningBolt(this.world);
bolt.setLocationAndAngles(this.pos.getX() + 3, this.pos.getY() + 2.5D, this.pos.getZ() - 3, 0.0F, 0.0F);
this.world.spawnEntity(bolt);
}
if (this.world.rand.nextInt(12) == 0) {
EntityDarkLightningBolt bolt = new EntityDarkLightningBolt(this.world);
bolt.setLocationAndAngles(this.pos.getX() - 3, this.pos.getY() + 2.5D, this.pos.getZ() - 3, 0.0F, 0.0F);
this.world.spawnEntity(bolt);
}
if (this.failedTick % 20 == 0) {
this.world.playSound(null, this.pos.getX(), this.pos.getY(), this.pos.getZ(), MPSounds.MACHINE_ACTIVATE_AMBIENT, SoundCategory.BLOCKS, 1.0F, 1.025F);
this.world.playSound(null, this.pos.getX(), this.pos.getY(), this.pos.getZ(), MPSounds.MACHINE_DANGER, SoundCategory.BLOCKS, 5.0F, 1.0F);
}
}
if (TileEntityDarkEnergyReceiver.checkValidMultiblock(this.pos, this.world)) {
this.failed = true;
}
if (this.getEnergyStoredGC() < 20000.0F) {
this.failed = true;
}
for (int yRender = this.pos.getY(); yRender < 256; yRender++) {
IBlockState state = this.world.getBlockState(new BlockPos(this.pos.getX(), yRender, this.pos.getZ()));
Block block = state.getBlock();
if (state.isOpaqueCube() && block != DionaBlocks.DARK_ENERGY_CORE) {
this.failed = true;
}
if (this.facing == 0 || this.facing == 180) {
block = this.world.getBlockState(new BlockPos(this.pos.getX() + 1, yRender + 1, this.pos.getZ())).getBlock();
if (state.isOpaqueCube() && block != DionaBlocks.DARK_ENERGY_CORE) {
this.failed = true;
}
block = this.world.getBlockState(new BlockPos(this.pos.getX() - 1, yRender + 1, this.pos.getZ())).getBlock();
if (state.isOpaqueCube() && block != DionaBlocks.DARK_ENERGY_CORE) {
this.failed = true;
}
}
if (this.facing == -90 || this.facing == 90) {
block = this.world.getBlockState(new BlockPos(this.pos.getX(), yRender + 1, this.pos.getZ() + 1)).getBlock();
if (state.isOpaqueCube() && block != DionaBlocks.DARK_ENERGY_CORE) {
this.failed = true;
}
block = this.world.getBlockState(new BlockPos(this.pos.getX(), yRender + 1, this.pos.getZ() - 1)).getBlock();
if (state.isOpaqueCube() && block != DionaBlocks.DARK_ENERGY_CORE) {
this.failed = true;
}
}
}
if (this.activatedTick == this.getSuccessfulTick()) {
if (!this.successful) {
if (this.world.getBlockState(this.getPos().up()).getBlock() != DionaBlocks.DARK_ENERGY_CORE) {
EntityDarkLightningBolt bolt = new EntityDarkLightningBolt(this.world);
bolt.setLocationAndAngles(this.pos.getX(), this.pos.getY() + 2.5D, this.pos.getZ(), 0.0F, 0.0F);
this.world.playSound((EntityPlayer) null, this.pos.getX(), this.pos.getY() + 2.5D, this.pos.getZ(), SoundEvents.ENTITY_GENERIC_EXPLODE, SoundCategory.BLOCKS, 4.0F, (1.0F + (this.world.rand.nextFloat() - this.world.rand.nextFloat()) * 0.2F) * 0.7F);
this.world.spawnEntity(bolt);
this.world.setBlockState(this.getPos().up(), DionaBlocks.DARK_ENERGY_CORE.getDefaultState());
}
for (Map.Entry<BlockPos, IBlockState> list : multiBlockLists.entrySet()) {
IBlockState state = list.getValue();
BlockPos pos = this.pos.add(list.getKey());
if (state != MPBlocks.DUNGEON_GLOWSTONE.getDefaultState() && state != DionaBlocks.INFECTED_CRYSTALLIZE_SLIME_BLOCK.getDefaultState()) {
for (int i = 0; i < 120; i++) {
MorePlanetsCore.PROXY.spawnParticle(EnumParticleTypesMP.DARK_PORTAL, pos.getX() + this.world.rand.nextDouble() * 1.0D, pos.getY() + this.world.rand.nextDouble() * 1.0D, pos.getZ() + this.world.rand.nextDouble() * 1.0D, 0.0D, -this.world.rand.nextDouble(), 0.0D);
}
this.world.setBlockToAir(pos);
} else {
this.world.setBlockState(pos, Blocks.OBSIDIAN.getDefaultState());
}
}
this.setDisabled(0, true);
this.activatedMessage = true;
this.successful = true;
FMLClientHandler.instance().getClient().player.sendMessage(new JsonUtil().text(GCCoreUtil.translate("gui.status.dark_energy_core_created.name")).setStyle(new JsonUtil().colorFromConfig("green")));
}
}
if (this.failedTick > 600) {
if (!this.spawnedBlackHole) {
EntityBlackHole blackHole = new EntityBlackHole(this.world);
blackHole.setLocationAndAngles(this.pos.getX() + 0.5D, this.pos.getY() + 2.0D, this.pos.getZ() + 0.5D, 0.0F, 0.0F);
this.world.spawnEntity(blackHole);
this.world.createExplosion(null, this.pos.getX(), this.pos.getY(), this.pos.getZ(), 5.0F, true);
this.world.destroyBlock(this.pos, false);
this.spawnedBlackHole = true;
}
}
}
} else {
if (this.activated && !this.successful) {
this.solarRotate++;
this.solarRotate %= 180;
if (this.getEnergyStoredGC() > 0.0F && !this.failed) {
if (this.rodUp < 58) {
this.rodUp++;
}
} else {
if (this.rodUp > 0) {
this.rodUp -= 0.25F;
}
}
}
if (this.successful && this.solarRotate < 180) {
this.solarRotate++;
}
}
}
Aggregations