Search in sources :

Example 6 with JsonUtil

use of stevekung.mods.moreplanets.util.JsonUtil 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++;
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) SPacketUpdateTileEntity(net.minecraft.network.play.server.SPacketUpdateTileEntity) Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) IBlockState(net.minecraft.block.state.IBlockState) PotionEffect(net.minecraft.potion.PotionEffect) EntityBlackHole(stevekung.mods.moreplanets.entity.EntityBlackHole) EntityDarkLightningBolt(stevekung.mods.moreplanets.module.planets.diona.entity.EntityDarkLightningBolt) JsonUtil(stevekung.mods.moreplanets.util.JsonUtil) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Block(net.minecraft.block.Block) IMultiBlock(micdoodle8.mods.galacticraft.core.tile.IMultiBlock) BlockPos(net.minecraft.util.math.BlockPos) Map(java.util.Map) HashMap(java.util.HashMap)

Example 7 with JsonUtil

use of stevekung.mods.moreplanets.util.JsonUtil in project MorePlanets by SteveKunG.

the class EntityCheeseCubeEyeBoss method onLivingUpdate.

@Override
public void onLivingUpdate() {
    EntityPlayer player = this.world.getClosestPlayer(this.posX, this.posY, this.posZ, 256.0, false);
    if (player != null && !player.equals(this.targetedEntity) && !player.capabilities.isCreativeMode) {
        if (this.getDistanceSq(player) < 400.0D) {
            this.getNavigator().getPathToEntityLiving(player);
            this.targetedEntity = player;
        }
    } else {
        this.targetedEntity = null;
    }
    if (this.spawner != null) {
        List<EntityPlayer> playersWithin = this.world.getEntitiesWithinAABB(EntityPlayer.class, this.spawner.getRangeBounds());
        this.entitiesWithin = playersWithin.size();
        if (this.entitiesWithin == 0 && this.entitiesWithinLast != 0) {
            List<EntityPlayer> playerWithin = this.world.getEntitiesWithinAABB(EntityPlayer.class, this.spawner.getRangeBoundsPlus11());
            for (EntityPlayer player2 : playerWithin) {
                JsonUtil json = new JsonUtil();
                player2.sendMessage(new JsonUtil().text(GCCoreUtil.translate("gui.skeleton_boss.message")).setStyle(json.red()));
            }
            this.setDead();
            return;
        }
        this.entitiesWithinLast = this.entitiesWithin;
    }
    this.bossInfo.setPercent(this.getHealth() / this.getMaxHealth());
    super.onLivingUpdate();
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) JsonUtil(stevekung.mods.moreplanets.util.JsonUtil)

Example 8 with JsonUtil

use of stevekung.mods.moreplanets.util.JsonUtil in project MorePlanets by SteveKunG.

the class ItemSpaceWarperCore method onItemRightClick.

@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
    JsonUtil json = new JsonUtil();
    ItemStack itemStack = player.getHeldItem(hand);
    if (!player.world.isRemote) {
        if (player.isSneaking()) {
            if (GCCoreUtil.getDimensionID(world) == 0 || world.provider instanceof IGalacticraftWorldProvider) {
                if (!itemStack.hasTagCompound()) {
                    itemStack.setTagCompound(new NBTTagCompound());
                    itemStack.getTagCompound().setInteger("DimensionID", GCCoreUtil.getDimensionID(world));
                    itemStack.getTagCompound().setInteger("X", MathHelper.floor(player.posX));
                    itemStack.getTagCompound().setInteger("Y", MathHelper.floor(player.posY));
                    itemStack.getTagCompound().setInteger("Z", MathHelper.floor(player.posZ));
                    itemStack.getTagCompound().setFloat("Pitch", player.rotationPitch);
                    itemStack.getTagCompound().setFloat("Yaw", player.rotationYaw);
                    player.sendMessage(json.text(GCCoreUtil.translate("gui.warp_core_data_add.message")));
                    return new ActionResult<>(EnumActionResult.SUCCESS, itemStack);
                } else {
                    player.sendMessage(json.text(GCCoreUtil.translate("gui.warp_core_data_add_fail.message")));
                }
            } else {
                player.sendMessage(json.text(GCCoreUtil.translate("gui.space_dimension_only.message")).setStyle(json.red()));
            }
        }
    }
    return new ActionResult<>(EnumActionResult.PASS, itemStack);
}
Also used : ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) IGalacticraftWorldProvider(micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack) JsonUtil(stevekung.mods.moreplanets.util.JsonUtil)

Example 9 with JsonUtil

use of stevekung.mods.moreplanets.util.JsonUtil in project MorePlanets by SteveKunG.

the class ItemBlockShieldGenerator method placeBlockAt.

@Override
public boolean placeBlockAt(ItemStack itemStack, EntityPlayer player, World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, IBlockState state) {
    BlockPos vecToAdd = new BlockPos(pos.getX(), pos.getY() + 1, pos.getZ());
    Block block = world.getBlockState(vecToAdd).getBlock();
    if (world.getBlockState(vecToAdd).getMaterial() != Material.AIR && !block.isReplaceable(world, vecToAdd)) {
        if (world.isRemote) {
            FMLClientHandler.instance().getClient().ingameGUI.setOverlayMessage(new JsonUtil().text(I18n.format("gui.warning.noroom")).setStyle(new JsonUtil().red()).getFormattedText(), false);
        }
        return false;
    } else {
        if (!vecToAdd.equals(pos)) {
            MPBlocks.DUMMY_BLOCK.makeFakeBlock(world, vecToAdd, pos, BlockDummy.BlockType.SHIELD_GENERATOR_TOP);
        }
        return super.placeBlockAt(itemStack, player, world, pos, facing, hitX, hitY, hitZ, state);
    }
}
Also used : Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) JsonUtil(stevekung.mods.moreplanets.util.JsonUtil)

Example 10 with JsonUtil

use of stevekung.mods.moreplanets.util.JsonUtil in project MorePlanets by SteveKunG.

the class ItemBlockBlackHoleStorage method placeBlockAt.

@Override
public boolean placeBlockAt(ItemStack itemStack, EntityPlayer player, World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, IBlockState state) {
    for (int y = -24; y <= 24; y++) {
        for (int x = -24; x <= 24; x++) {
            for (int z = -24; z <= 24; z++) {
                BlockPos posAt = pos.add(x, y, z);
                Block block = world.getBlockState(posAt).getBlock();
                for (int y2 = 0; y2 < 3; y2++) {
                    BlockPos posAt1 = pos.add(0, y2, 0);
                    Block block1 = world.getBlockState(posAt1).getBlock();
                    if (world.getBlockState(posAt1).getMaterial() != Material.AIR && !block1.isReplaceable(world, posAt1)) {
                        if (world.isRemote) {
                            FMLClientHandler.instance().getClient().ingameGUI.setOverlayMessage(new JsonUtil().text(I18n.format("gui.warning.noroom")).setStyle(new JsonUtil().red()).getFormattedText(), false);
                        }
                        return false;
                    }
                }
                if (block == MPBlocks.BLACK_HOLE_STORAGE) {
                    if (world.isRemote) {
                        FMLClientHandler.instance().getClient().ingameGUI.setOverlayMessage(new JsonUtil().text(I18n.format("gui.bh_storage.too_close.message")).setStyle(new JsonUtil().red()).getFormattedText(), false);
                    }
                    return false;
                }
            }
        }
    }
    return super.placeBlockAt(itemStack, player, world, pos, facing, hitX, hitY, hitZ, state);
}
Also used : Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) JsonUtil(stevekung.mods.moreplanets.util.JsonUtil)

Aggregations

JsonUtil (stevekung.mods.moreplanets.util.JsonUtil)16 EntityPlayer (net.minecraft.entity.player.EntityPlayer)7 BlockPos (net.minecraft.util.math.BlockPos)7 Block (net.minecraft.block.Block)5 ItemStack (net.minecraft.item.ItemStack)3 TileEntity (net.minecraft.tileentity.TileEntity)3 Map (java.util.Map)2 IBlockState (net.minecraft.block.state.IBlockState)2 ActionResult (net.minecraft.util.ActionResult)2 EnumActionResult (net.minecraft.util.EnumActionResult)2 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)2 HashMap (java.util.HashMap)1 Random (java.util.Random)1 IGalacticraftWorldProvider (micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider)1 IMultiBlock (micdoodle8.mods.galacticraft.core.tile.IMultiBlock)1 Entity (net.minecraft.entity.Entity)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 Item (net.minecraft.item.Item)1 ItemBlock (net.minecraft.item.ItemBlock)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1