Interface IApiHandler


public interface IApiHandler
This class exposes a multitude of utility methods that are too big to be inside the API's code and are, as such, inside of the game. To access the API handler, use RockBottomAPI.getApiHandler().
  • Method Details

    • writeDataSet

      void writeDataSet(AbstractDataSet set, File file, boolean asJson)
      Writes a data set to the given file either as binary or as a json
      Parameters:
      set - The data set to write to file
      file - The file to write to
      asJson - Wether it should be stored as json
    • readDataSet

      void readDataSet(AbstractDataSet set, File file, boolean asJson)
      Reads a data set from the given file either as binary or as a json and stores the data in the set.
      Parameters:
      set - The set to store the data in
      file - The file to read from
      asJson - Wether or not it should be stored as json
    • writeDataSet

      void writeDataSet(DataOutput stream, AbstractDataSet set) throws Exception
      Writes a data set directly to a data output of any kind, throwing an exception if something fails.
      Parameters:
      stream - The output to write to
      set - The set to write to the output
      Throws:
      Exception - if writing fails for some reason
    • readDataSet

      void readDataSet(DataInput stream, AbstractDataSet set) throws Exception
      Reads a data set directly from a data input of any kind, throwing an exception if something fails.
      Parameters:
      stream - The input to read from
      set - The set to save the input in
      Throws:
      Exception - if reading fails for some reason
    • writeDataSet

      void writeDataSet(com.google.gson.JsonObject main, AbstractDataSet set) throws Exception
      Writes a data set directly to a json object head, throwing an exception if something fails.
      Parameters:
      main - The json object to write to
      set - The set to write
      Throws:
      Exception - if writing fails for some reason
    • readDataSet

      void readDataSet(com.google.gson.JsonObject main, AbstractDataSet set) throws Exception
      Reads a data set directly from a json object head, throwing an exception if something fails.
      Parameters:
      main - The json object to read from
      set - The set to save the input in
      Throws:
      Exception - if reading fails for some reason
    • readDataPart

      DataPart readDataPart(com.google.gson.JsonElement element) throws Exception
      Throws:
      Exception
    • interpolateLight

      int[] interpolateLight(IWorld world, int x, int y)
      Interpolates the light at a position in the world. The four integers in the returned array specify the light at each four corners of the tile at the position.
      Parameters:
      world - The world
      x - The x coordinate
      y - The y coordinate
      Returns:
      The interpolated light
    • interpolateWorldColor

      int[] interpolateWorldColor(int[] interpolatedLight, TileLayer layer)
      Interpolates the four colors of the corners of a position in the world based on the TileLayer and the interpolated light from interpolateLight(IWorld, int, int).
      Parameters:
      interpolatedLight - The interpolated light
      layer - The layer
      Returns:
      The four colors
    • getDefaultPlatformBounds

      List<BoundingBox> getDefaultPlatformBounds(IWorld world, int x, int y, TileLayer layer, double tileWidth, double tileHeight, TileState state, MovableWorldObject object, BoundingBox objectBox)
    • collectItems

      boolean collectItems(IInventory inventory, List<IUseInfo> inputs, boolean simulate, List<ItemInstance> out)
      Searches the inventory for items as IUseInfo specified in the given parameters.
      Parameters:
      inventory - The inventory to search
      inputs - The list of item infos to find
      simulate - Whether to simulate the process. False will remove the items found from inventory IF it has found all inputs.
      out - The list to be provided which will store the ItemInstances found.
      Returns:
      True enough items are in the inventory and it can be collected. False otherwise.
    • hasItems

      boolean hasItems(IInventory inventory, List<IUseInfo> checklist, int count, List<ItemInstance> outInputs, Map<Integer,Integer> outSlotsToDeduct)
      Checks to see if the given input inventory has enough of the given items in the checklist list. Provide an out map which tell you the (slot, amount) map of slots and the amount of items to deduct from that slot.
      Parameters:
      inventory - The input inventory.
      checklist - The item checklist.
      count - The amount of times each item of the checklist needs to appear.
      outInputs - The output list of item instances found in the inventory. Can be null.
      outSlotsToDeduct - The output map of slot ids to amount of items to deduct from that slot. Can be null.
      Returns:
      True if the given inventory has enough items in the checklist. False otherwise.
    • defaultConstruct

      void defaultConstruct(AbstractPlayerEntity player, PlayerCompendiumRecipe recipe, TileEntity machine)
      Similar to construct(AbstractPlayerEntity, IInventory, IInventory, PlayerCompendiumRecipe, TileEntity, int, List, float) but safe to use on both client and server side (client side sends packet to server).
      Parameters:
      player - The player doing this construction. Can be null if the construction is automated. Note that the skill reward is not used then.
      recipe - The recipe to construct
      machine - The tile entity doing the crafting
    • construct

      List<ItemInstance> construct(AbstractPlayerEntity player, IInventory inputInventory, IInventory outputInventory, PlayerCompendiumRecipe recipe, TileEntity machine, int amount, List<ItemInstance> availableInputs, float skillReward)
      This is a utility method that you can call for custom construction of items via the compendium, if you, for example, create a custom, more complex, ICompendiumRecipe class, or if you create a machine that should automatically construct something.
      Parameters:
      player - The player doing this construction. Can be null if the construction is automated. Note that the skill reward is not used then.
      inputInventory - The inventory that the construction takes items from
      outputInventory - The inventory that the output items go into
      recipe - The recipe to be constructed
      machine - The machine
      amount - The amount of times this recipe should be constructed
      availableInputs - The actual ItemInstances used in the construction of the recipe. Can be null if the inputs should be calculated by the method.
      skillReward - The amount of skill points you get for constructing this recipe
      Returns:
      A list of items that couldn't fit into the output inventory specified
      See Also:
    • getColorByLight

      int getColorByLight(int light, TileLayer layer)
      Gets a color in the world based on a light value between 0 and Constants.MAX_LIGHT.
      Parameters:
      light - The light
      layer - The layer
      Returns:
      The color
    • makeSimplexNoise

      INoiseGen makeSimplexNoise(long seed)
      Returns a new INoiseGen of the Simplex Noise kind based on the specified seed.
      Parameters:
      seed - The seed
      Returns:
      The noise generator
    • createLogger

      Logger createLogger(String name)
      Creates a Logger with the specified name that will output to the main logger and also written to the log file.
      Parameters:
      name - The name
      Returns:
      The new logger
    • renderPlayer

      void renderPlayer(AbstractPlayerEntity player, IGameInstance game, IAssetManager manager, IRenderer g, IPlayerDesign design, float x, float y, float scale, int row, int light)
    • generateBasicHeight

      int generateBasicHeight(IWorld world, TileLayer layer, int x, INoiseGen noiseGen, int minHeight, int maxHeight, int maxMountainHeight)
    • initBiomeGen

      void initBiomeGen(IWorld world, int seedScramble, int blobSize, long[] layerSeeds, com.google.common.collect.ListMultimap<BiomeLevel,Biome> biomesPerLevel, Map<BiomeLevel,Integer> totalWeights, BiomeGen gen)
    • generateBiomeGen

      void generateBiomeGen(IWorld world, IChunk chunk, BiomeGen gen, Map<Biome,INoiseGen> biomeNoiseGens)
    • getBiome

      Biome getBiome(IWorld world, int x, int y, int height, Map<BiomeLevel,Integer> totalWeights, com.google.common.collect.ListMultimap<BiomeLevel,Biome> biomesPerLevel, Random biomeRandom, int blobSize, long[] layerSeeds, INoiseGen levelHeightNoise, int levelTransition, int biomeTransition)
    • getSmoothedLevelForPos

      BiomeLevel getSmoothedLevelForPos(IWorld world, int x, int y, int height, int levelTransition, com.google.common.collect.ListMultimap<BiomeLevel,Biome> biomesPerLevel, INoiseGen levelHeightNoise)
    • openPlayerInventory

      void openPlayerInventory(AbstractPlayerEntity player)
      Opens the players inventory the same as pressing Settings.KEY_INVENTORY.
      Parameters:
      player - The player to open the inventory for.
    • openExtendedPlayerInventory

      void openExtendedPlayerInventory(AbstractPlayerEntity player, IInventory inventory, int containerWidth, Consumer<IInventory> onClosed, ItemContainer.ISlotCallback slotCallback)
      Opens the player inventory with an additional inventory on the top.
      Parameters:
      player - The player opening the container.
      inventory - The extra inventory.
      containerWidth - The amount of slots horizontally before wrapping to next line.
      onClosed - The action to take when the container is closed.