Skip to content

Interfaces

Lumintorious edited this page Jul 28, 2020 · 2 revisions

API Interfaces

Overview

There are two types of interfaces needed to use the API:

  • TemperatureOwner interfaces
  • TemperatureProvider interfaces

Temperature Owners

A temperature owner is an Item Object, Block Object or TileEntity Object that implements an owner interface.

They will be checked either from the player's inventory in case of items, or around the player in the case of the other two.

They all have one method to implement:

  • IItemTemperatureOwner - public ItemModifier getModifier(ItemStack stack, EntityPlayer player)
  • IBlockTemperatureOwner - public BlockModifier getModifier(IBlockState state, BlockPos pos, EntityPlayer player)
  • ITileEntityTemperatureOwner - public TileEntityModifier getModifier(EntityPlayer player)

Use the parameters however you like to return a modifier for an object of your class. Return null in order to not add any modifier. Modifiers with 0 change and 0 potency are also not added.

Provider Interfaces

A temperature provider is a functional interface that is checked for a modifier for each item/block/tile entity.

You need to register them using TemperatureRegistry.ENVIRONMENTAL/ITEMS/BLOCKS/TILE_ENTITIES.register(ITemperatureProvider) methods.

They can be defined as lamda functions (suggested), anonymus classes or actual classes and they are:

  • IEnvironmentalTemperatureProvider - public EnvironmentalModifier getModifier(EntityPlayer player)
  • IItemTemperatureProvider - public ItemModifier getModifier(ItemStack stack, EntityPlayer player)
  • IBlockTemperatureProvider - public BlockModifier getModifier(IBlockState state, BlockPos pos, EntityPlayer player)
  • ITileEntityTemperatureProvider - public TileEntityModifier getModifier(TileEntity tile, EntityPlayer player)

Use the parameters however you like to return a modifier. For tile entities you might want to use instanceof and casting. Return null if you determined that you don't want to create a modifier.

Example:

TemperatureRegistry.TILE_ENTITY register((tile, player) ->{
    if(tile instanceof TECharcoalForge) {
	TECharcoalForge forge = (TECharcoalForge)tile;
	float temp = forge.getField(TECharcoalForge.FIELD_TEMPERATURE);
	float change =  temp / 140f;
	float potency = temp / 350f;
	return new TileEntityModifier("charcoal_forge", change, potency);
    }else {
	return null;
    }
});
Clone this wiki locally