Wiki 9Minecraft Bag Of Yurting Wiki
Bag Of Yurting WikiDocumentation › Api Reference

Api Reference

This documentation is no longer valid as of 1.19.1-3.0.0.0;
the API has been removed for maintainability.

Blockentities that work in vanilla structure NBT should generally be compatible with Bag of Yurting.
Blocks that don't should be blacklisted via the tags by mods/modpacks to prevent problems.

The API documentation has been left as-is for archival purposes.

Bag of Yurting adds several API features for improving mod compatibility.

Contents
  1. Using the API
  2. Block Data Transformers
    1. Block Data Serializer
    2. Block Data Deserializer
  3. History

Using the API

Mods can use Bag of Yurting in their development workspace by adding the following to their build.gradle:

repositories {
	// repo to get Bag of Yurting jars from
	maven { url "https://cubicinterpolation.net/maven/" }
}

dependencies {
	// compile against the API only
	compileOnly fg.deobf("commoble.bagofyurting:${$bagofyurting_branch}:${$bagofyurting_version}:api")
	// use the production jar when running minecraft from dev
	runtimeOnly fg.deobf("commoble.bagofyurting:${$bagofyurting_branch}:${$bagofyurting_version}")
}

Where

  • {$bagofyurting_branch} is e.g. bagofyurting-1.16.4
  • {$bagofyurting_version} is e.g. 1.2.0.0

The API is only available on branches bagofyurting-1.16.4 and newer and versions 1.2.0.0 and newer.

A debug jar with full sources is available for easier debugging, which can be used by compiling against :debug instead of :api. It is not recommended to compile against the debug jar when building production jars, as binary-breaking changes are more likely to occur with it.

Mods can have soft dependencies on BagOfYurting and avoid classloading possibly-not-present Bag of Yurting classes by creating and using a proxy class:

if (ModList.get().isLoaded("bagofyurting"))
{
	YourBagOfYurtingProxy.doBagOfYurtingStuff();
}

and in a separate class:

public class YourBagOfYurtingProxy
{
	public static void doBagOfYurtingStuff()
	{
		BagOfYurtingAPI.registerBlockDataTransformer(yourTileEntityType, serializer, deserializer);
	}
}

Block Data Transformers

Bags of Yurting can move and reorient any block that correctly implements the rotate block method, and the data of block entities such as chests is generally retained when these blocks are moved. However, some block entities added by mods may have position- or rotation- sensitive data, for which there is no builtin way to automatically transform when these blocks are moved. Bag of Yurting's API allows mods to register special serializers to specific blockentity types that will be used instead of the normal save/load methods when these blocks are loaded into the bag or unloaded into the world.

For example, if a mod has a tile entity that stores a rotation value inside its data, the mod could register a block data transformer that uses the yurting context given to rotate the value accordingly when the bag of yurting saves or loads the data.

A serializer/deserializer pair can be registered to a TileEntityType using BagOfYurtingAPI.registerBlockDataTransformer in FMLCommonSetupEvent:

	/**
	 * Register block data transformers to a tile entity type. Call this during FMLCommonSetupEvent.
	 * This is safe to call during multithreaded modloading. It will stop being safe to call once modloading concludes.
	 * @param <T> The class type of the tile entity, e.g. ChestTileEntity. Generic bounds on the de/serialization
	 * function parameters must be no higher than TileEntity and no lower than T.
	 * e.g. if T is LockableLootTileEntity, you can provide a function that requires a TileEntity,
	 * but not one that requires a ChestTileEntity.
	 * @param type The type of the tile entity; only one pair of data transformers can be assigned to a given type
	 * @param serializer Yurt-context-sensitive serializer for the given block entity type
	 * @param deserializer Yurt-context-sensitive deserializer for the given block entity type
	 */
	public static <T extends TileEntity> void registerBlockDataTransformer(TileEntityType<T> type,
		BlockDataSerializer<? super T> serializer,
		BlockDataDeserializer<? super T> deserializer);

If no serializers are registered to a tile entity type, the standard save/load methods will be used instead.

Block Data Serializer

BlockDataSerializers are run when block entity data is copied from the world into a bag of yurting when storing blocks in the bag. This occurs after it is determined what blocks should be stored in the bag, but before any blocks are actually removed from the world.

@FunctionalInterface
public interface BlockDataSerializer<T>
{
	/**
	 * Function that writes a blockentity's data into the supplied compoundNBT.
	 * This is called after what-blocks-to-remove are determined, but before any blocks are actually removed from the world.
	 * Making changes to the world at this point will not change which blocks are stored in the bag.
	 * @param blockEntity The blockentity instance being yurted. Has world/pos/state context if needed.
	 * @param nbt An empty nbt compound that the implementer should write data into.
	 * This should be a standard-format blockentity compound; if no BlockDataSerializer is assigned to the relevant tile entity type,
	 * then TileEntity::write is used by default instead.
	 * The rotation should be applied to any rotation-sensitive data.
	 * @param rotation A rotation that should be applied to any rotation-sensitive data.
	 * @param minYurt The minimal corner of the yurt region.
	 * @param maxYurt The maximal corner of the yurt region.
	 * @param origin The blockpos in absolute worldspace that the bag of yurting was used on (the bottom center of the yurt region)
	 * @param newOffset The position that the translated-and-rotated te position will be stored as in yurt data (as an offset relative to the 0,0,0 origin)
	 */
	public void writeWithYurtContext(T blockEntity, CompoundNBT nbt, Rotation rotation, BlockPos minYurt, BlockPos maxYurt, BlockPos origin, BlockPos newOffset);
}

Block Data Deserializer

Block Data Deserializers are run after all blocks and blockentities have been placed into the world when unloading blocks from a bag.

@FunctionalInterface
public interface BlockDataDeserializer<T>
{
	/**
	 * Function that reads a standard-format blockentity compound into the given blockentity, applying transformations
	 * from yurt context if necessary. This function is called for each blockentity that becomes unyurted into the world,
	 * after all blocks and blockentities have been placed into the world.
	 * 
	 * Be aware that minYurt and maxYurt are based on the yurting radius of the bag item, and the area defined by them
	 * may be larger than the area actually changed during the unyurting.
	 * 
	 * @param blockEntity The new blockentity that data is being read into.
	 * @param input The compound from yurt data that we are reading into the blockentity.
	 * @param world The world that the blockentity was placed in.
	 * @param pos The position that the blockentity was placed at.
	 * If the blockentity has any absolute-position-sensitive data that must be translated when yurted,
	 * it is recommended to subtract the old position when serializing and to add the new position when deserializing.
	 * (The position of the blockentity itself is handled automatically and does not need to be manually transformed by the implementor).
	 * @param state The new blockstate in the world at the te's position
	 * @param rotation A rotation to apply to any rotation-sensitive data in the blockentity.
	 * @param minYurt The minimal corner of the yurt region being placed into the world.
	 * @param maxYurt The maximal corner of the yurt region being placed into the world
	 * @param origin The position that the bag of yurting was used at to unload blocks (the bottom-center of the yurting region)
	 * 
	 */
	public void readWithYurtContext(T blockEntity, CompoundNBT input, World world, BlockPos pos, BlockState state, Rotation rotation, BlockPos minYurt, BlockPos maxYurt, BlockPos origin);
}

History

Version Changelog
1.19.1-3.0.0.0 Removed API
1.16.4-1.2.0.0 Added API