Package de.ellpeck.rockbottom.api
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 Summary
Modifier and TypeMethodDescriptionbooleancollectItems(IInventory inventory, List<IUseInfo> inputs, boolean simulate, List<ItemInstance> out) Searches the inventory for items as IUseInfo specified in the given parameters.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,ICompendiumRecipeclass, or if you create a machine that should automatically construct something.createLogger(String name) Creates aLoggerwith the specified name that will output to the main logger and also written to the log file.voiddefaultConstruct(AbstractPlayerEntity player, PlayerCompendiumRecipe recipe, TileEntity machine) Similar toconstruct(AbstractPlayerEntity, IInventory, IInventory, PlayerCompendiumRecipe, TileEntity, int, List, float)but safe to use on both client and server side (client side sends packet to server).intgenerateBasicHeight(IWorld world, TileLayer layer, int x, INoiseGen noiseGen, int minHeight, int maxHeight, int maxMountainHeight) voidgetBiome(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) intgetColorByLight(int light, TileLayer layer) Gets a color in the world based on a light value between 0 andConstants.MAX_LIGHT.getDefaultPlatformBounds(IWorld world, int x, int y, TileLayer layer, double tileWidth, double tileHeight, TileState state, MovableWorldObject object, BoundingBox objectBox) getSmoothedLevelForPos(IWorld world, int x, int y, int height, int levelTransition, com.google.common.collect.ListMultimap<BiomeLevel, Biome> biomesPerLevel, INoiseGen levelHeightNoise) booleanhasItems(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.voidinitBiomeGen(IWorld world, int seedScramble, int blobSize, long[] layerSeeds, com.google.common.collect.ListMultimap<BiomeLevel, Biome> biomesPerLevel, Map<BiomeLevel, Integer> totalWeights, BiomeGen gen) int[]interpolateLight(IWorld world, int x, int y) Interpolates the light at a position in the world.int[]interpolateWorldColor(int[] interpolatedLight, TileLayer layer) Interpolates the four colors of the corners of a position in the world based on theTileLayerand the interpolated light frominterpolateLight(IWorld, int, int).makeSimplexNoise(long seed) Returns a newINoiseGenof the Simplex Noise kind based on the specified seed.voidopenExtendedPlayerInventory(AbstractPlayerEntity player, IInventory inventory, int containerWidth, Consumer<IInventory> onClosed, ItemContainer.ISlotCallback slotCallback) Opens the player inventory with an additional inventory on the top.voidOpens the players inventory the same as pressingSettings.KEY_INVENTORY.readDataPart(com.google.gson.JsonElement element) voidreadDataSet(com.google.gson.JsonObject main, AbstractDataSet set) Reads a data set directly from a json object head, throwing an exception if something fails.voidreadDataSet(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.voidreadDataSet(DataInput stream, AbstractDataSet set) Reads a data set directly from a data input of any kind, throwing an exception if something fails.voidrenderPlayer(AbstractPlayerEntity player, IGameInstance game, IAssetManager manager, IRenderer g, IPlayerDesign design, float x, float y, float scale, int row, int light) voidwriteDataSet(com.google.gson.JsonObject main, AbstractDataSet set) Writes a data set directly to a json object head, throwing an exception if something fails.voidwriteDataSet(AbstractDataSet set, File file, boolean asJson) Writes a data set to the given file either as binary or as a jsonvoidwriteDataSet(DataOutput stream, AbstractDataSet set) Writes a data set directly to a data output of any kind, throwing an exception if something fails.
-
Method Details
-
writeDataSet
Writes a data set to the given file either as binary or as a json- Parameters:
set- The data set to write to filefile- The file to write toasJson- Wether it should be stored as json
-
readDataSet
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 infile- The file to read fromasJson- Wether or not it should be stored as json
-
writeDataSet
Writes a data set directly to a data output of any kind, throwing an exception if something fails.- Parameters:
stream- The output to write toset- The set to write to the output- Throws:
Exception- if writing fails for some reason
-
readDataSet
Reads a data set directly from a data input of any kind, throwing an exception if something fails.- Parameters:
stream- The input to read fromset- The set to save the input in- Throws:
Exception- if reading fails for some reason
-
writeDataSet
Writes a data set directly to a json object head, throwing an exception if something fails.- Parameters:
main- The json object to write toset- The set to write- Throws:
Exception- if writing fails for some reason
-
readDataSet
Reads a data set directly from a json object head, throwing an exception if something fails.- Parameters:
main- The json object to read fromset- The set to save the input in- Throws:
Exception- if reading fails for some reason
-
readDataPart
- Throws:
Exception
-
interpolateLight
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 worldx- The x coordinatey- The y coordinate- Returns:
- The interpolated light
-
interpolateWorldColor
Interpolates the four colors of the corners of a position in the world based on theTileLayerand the interpolated light frominterpolateLight(IWorld, int, int).- Parameters:
interpolatedLight- The interpolated lightlayer- 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 searchinputs- The list of item infos to findsimulate- 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 toconstruct(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 constructmachine- 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,ICompendiumRecipeclass, 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 fromoutputInventory- The inventory that the output items go intorecipe- The recipe to be constructedmachine- The machineamount- The amount of times this recipe should be constructedavailableInputs- The actualItemInstances used in the construction of the recipe. Can benullif 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
Gets a color in the world based on a light value between 0 andConstants.MAX_LIGHT.- Parameters:
light- The lightlayer- The layer- Returns:
- The color
-
makeSimplexNoise
Returns a newINoiseGenof the Simplex Noise kind based on the specified seed.- Parameters:
seed- The seed- Returns:
- The noise generator
-
createLogger
Creates aLoggerwith 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
-
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
-
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
Opens the players inventory the same as pressingSettings.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.
-