Search in sources :

Example 1 with JsonUtil

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

the class BlockBlackHoleStorage method onBlockActivated.

@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
    if (world.isRemote) {
        return true;
    } else {
        TileEntity tile = world.getTileEntity(pos);
        int slot = player.inventory.currentItem;
        if (tile instanceof TileEntityBlackHoleStorage) {
            TileEntityBlackHoleStorage storage = (TileEntityBlackHoleStorage) tile;
            FluidActionResult result = FluidUtil.interactWithFluidHandler(player.inventory.getCurrentItem(), storage.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null), player);
            if (result.isSuccess()) {
                player.inventory.setInventorySlotContents(slot, result.result);
                if (player.inventoryContainer != null) {
                    player.inventoryContainer.detectAndSendChanges();
                }
                return true;
            } else {
                if (player.getGameProfile().getId().toString().equals(storage.ownerUUID)) {
                    if (player.isSneaking() && storage.fluidTank.getFluidAmount() > 0) {
                        Random rand = world.rand;
                        storage.drainExp(player);
                        world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, SoundCategory.PLAYERS, 0.1F, 0.5F * ((rand.nextFloat() - rand.nextFloat()) * 0.7F + 1.8F));
                    } else {
                        player.openGui(MorePlanetsCore.MOD_ID, -1, world, pos.getX(), pos.getY(), pos.getZ());
                    }
                } else {
                    JsonUtil json = new JsonUtil();
                    player.sendMessage(json.text(GCCoreUtil.translate("gui.bh_storage_not_owner.message")).setStyle(json.red()));
                }
            }
        }
        return true;
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Random(java.util.Random) FluidActionResult(net.minecraftforge.fluids.FluidActionResult) JsonUtil(stevekung.mods.moreplanets.util.JsonUtil) TileEntityBlackHoleStorage(stevekung.mods.moreplanets.tileentity.TileEntityBlackHoleStorage)

Example 2 with JsonUtil

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

the class BlockDarkEnergyReceiver method onBlockActivated.

@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (world.isRemote) {
        return true;
    } else {
        if (player.isSneaking()) {
            if (world.getTileEntity(pos) instanceof TileEntityDarkEnergyReceiver) {
                TileEntityDarkEnergyReceiver tile = (TileEntityDarkEnergyReceiver) world.getTileEntity(pos);
                if (TileEntityDarkEnergyReceiver.checkValidMultiblock(pos, world)) {
                    for (Map.Entry<BlockPos, IBlockState> list : TileEntityDarkEnergyReceiver.multiBlockLists.entrySet()) {
                        BlockPos blockpos = list.getKey();
                        IBlockState blockstate = list.getValue();
                        BlockPos newPos = pos.add(blockpos);
                        JsonUtil json = new JsonUtil();
                        if (world.getBlockState(newPos) != blockstate) {
                            Item item = Item.getItemFromBlock(blockstate.getBlock());
                            String name = item.getItemStackDisplayName(new ItemStack(item, 1, blockstate.getBlock().getMetaFromState(blockstate)));
                            player.sendMessage(json.text("Missing block " + name + " at " + newPos.getX() + " " + newPos.getY() + " " + newPos.getZ()).setStyle(json.red()));
                        }
                    }
                } else {
                    if (!tile.disabled) {
                        if (tile.getEnergyStoredGC() > 20000.0F) {
                            if (!tile.isActivated()) {
                                tile.setActivated(true);
                                tile.getWorld().playSound(player, tile.getPos(), MPSounds.MACHINE_START, SoundCategory.BLOCKS, 1.0F, 1.0F);
                                player.sendMessage(new JsonUtil().text(GCCoreUtil.translate("gui.dark_energy_success.message")).setStyle(new JsonUtil().colorFromConfig("green")));
                                return true;
                            } else {
                                player.sendMessage(new JsonUtil().text(GCCoreUtil.translate("gui.dark_energy_already_active.message")).setStyle(new JsonUtil().red()));
                                return false;
                            }
                        } else {
                            if (!tile.isActivated()) {
                                player.sendMessage(new JsonUtil().text(GCCoreUtil.translate("gui.dark_energy_no_power.message")).setStyle(new JsonUtil().red()));
                                return false;
                            }
                        }
                    } else {
                        player.sendMessage(new JsonUtil().text(GCCoreUtil.translate("gui.dark_energy_disabled.message")).setStyle(new JsonUtil().red()));
                        return false;
                    }
                }
            }
        } else {
            if (world.getTileEntity(pos) instanceof TileEntityDarkEnergyReceiver) {
                TileEntityDarkEnergyReceiver tile = (TileEntityDarkEnergyReceiver) world.getTileEntity(pos);
                if (tile.failedTick > 0 && !tile.successful) {
                    int failedTick = 600 - tile.failedTick;
                    String s = "s";
                    if (failedTick < 40) {
                        s = "";
                    }
                    player.sendMessage(new JsonUtil().text(GCCoreUtil.translateWithFormat("gui.dark_energy_malfunction.message", this.ticksToElapsedTime(failedTick)) + " second" + s + "!").setStyle(new JsonUtil().red()));
                    return false;
                } else {
                    if (!tile.failed) {
                        player.openGui(MorePlanetsCore.MOD_ID, -1, world, pos.getX(), pos.getY(), pos.getZ());
                    }
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : Item(net.minecraft.item.Item) IBlockState(net.minecraft.block.state.IBlockState) TileEntityDarkEnergyReceiver(stevekung.mods.moreplanets.tileentity.TileEntityDarkEnergyReceiver) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) Map(java.util.Map) JsonUtil(stevekung.mods.moreplanets.util.JsonUtil)

Example 3 with JsonUtil

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

the class BlockSpaceWarpPadFull method onBlockActivated.

@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (world.isRemote) {
        return true;
    } else {
        if (!player.isSneaking()) {
            TileEntity tile = world.getTileEntity(pos);
            if (tile instanceof TileEntitySpaceWarpPadFull) {
                TileEntitySpaceWarpPadFull warpPad = (TileEntitySpaceWarpPadFull) tile;
                JsonUtil json = new JsonUtil();
                if (!warpPad.disabled) {
                    if (warpPad.hasWarpCore()) {
                        if (warpPad.getDestinationPos() == null) {
                            player.sendMessage(json.text(GCCoreUtil.translate("gui.no_warp_destination.message")).setStyle(json.red()));
                            return true;
                        } else {
                            if (warpPad.getEnergyStoredGC() >= 5000.0F) {
                                warpPad.storage.setEnergyStored(warpPad.storage.getEnergyStoredGC() - 5000.0F);
                                TeleportUtil.teleportEntity(player, warpPad.getDimensionId(), warpPad.getDestinationPos().getX(), warpPad.getDestinationPos().getY(), warpPad.getDestinationPos().getZ(), warpPad.getRotationPitch(), warpPad.getRotationYaw());
                                world.playSound(null, pos, SoundEvents.ENTITY_ENDERMEN_TELEPORT, SoundCategory.PLAYERS, 0.75F, 1.0F);
                                MPLog.debug("Teleport player to %s, %s, %s, %s, %s", warpPad.getDestinationPos().getX(), warpPad.getDestinationPos().getY(), warpPad.getDestinationPos().getZ(), warpPad.getDimensionId(), WorldUtil.getProviderForDimensionClient(warpPad.getDimensionId()).getDimensionType().getName());
                                return true;
                            } else {
                                player.sendMessage(json.text(GCCoreUtil.translate("gui.status.missingpower.name")).setStyle(json.red()));
                                return true;
                            }
                        }
                    } else {
                        player.sendMessage(json.text(GCCoreUtil.translate("gui.status.warp_core_required.name")).setStyle(json.red()));
                        return true;
                    }
                } else {
                    player.sendMessage(json.text(GCCoreUtil.translate("gui.dark_energy_disabled.message")).setStyle(json.red()));
                    return true;
                }
            }
        } else {
            player.openGui(MorePlanetsCore.INSTANCE, -1, world, pos.getX(), pos.getY(), pos.getZ());
            return true;
        }
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntitySpaceWarpPadFull(stevekung.mods.moreplanets.tileentity.TileEntitySpaceWarpPadFull) JsonUtil(stevekung.mods.moreplanets.util.JsonUtil)

Example 4 with JsonUtil

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

the class ItemBlockNuclearWasteTank 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());
    BlockPos vecToAdd1 = new BlockPos(pos.getX(), pos.getY() + 2, pos.getZ());
    Block block = world.getBlockState(vecToAdd).getBlock();
    Block block1 = world.getBlockState(vecToAdd1).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 (world.getBlockState(vecToAdd1).getMaterial() != Material.AIR && !block1.isReplaceable(world, vecToAdd1)) {
        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.NUCLEAR_WASTE_TANK_MIDDLE);
        }
        if (!vecToAdd1.equals(pos)) {
            MPBlocks.DUMMY_BLOCK.makeFakeBlock(world, vecToAdd1, pos, BlockDummy.BlockType.NUCLEAR_WASTE_TANK_TOP);
        }
        return super.placeBlockAt(itemStack, player, world, pos, facing, hitX, hitY, hitZ, state);
    }
}
Also used : Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) BlockPos(net.minecraft.util.math.BlockPos) JsonUtil(stevekung.mods.moreplanets.util.JsonUtil)

Example 5 with JsonUtil

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

the class EntityInfectedCrystallizeSlimeBoss method onLivingUpdate.

@Override
public void onLivingUpdate() {
    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 player : playerWithin) {
                JsonUtil json = new JsonUtil();
                player.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)

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