All Projects → AlexIIL → LibBlockAttributes

AlexIIL / LibBlockAttributes

Licence: MPL-2.0 license
Library mod for fabric that adds items and attribute API's for blocks.

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to LibBlockAttributes

serilum-mc-mods
A hub for source code, issues and content suggestions for Serilum's Minecraft mods on CurseForge.
Stars: ✭ 66 (+53.49%)
Mutual labels:  minecraft-mod, fabricmc, minecraft-fabric
mouse-wheelie
"Small" Minecraft mod focusing on inventory utilities, like scrolling, sorting and auto refilling of items
Stars: ✭ 58 (+34.88%)
Mutual labels:  minecraft-mod, fabricmc, minecraft-fabric
Randomly-Adding-Anything
No description or website provided.
Stars: ✭ 42 (-2.33%)
Mutual labels:  minecraft-mod, fabricmc, minecraft-fabric
lazydfu
Fabric mod that makes Minecraft DataFixerUpper initialization lazy
Stars: ✭ 156 (+262.79%)
Mutual labels:  minecraft-mod, fabricmc
FabricProxy
Fabric mod for support forward player data from proxy
Stars: ✭ 40 (-6.98%)
Mutual labels:  minecraft-mod, fabricmc
NaturesCompass
A Minecraft mod that allows you to search for a biome's location anywhere in the world and view information about it.
Stars: ✭ 42 (-2.33%)
Mutual labels:  minecraft-mod, fabricmc
refinedstorage2
Refined Storage is a mass storage mod for Minecraft that offers the player a network-based storage system, allowing them to store items and fluids on a massively expandable device network.
Stars: ✭ 35 (-18.6%)
Mutual labels:  minecraft-mod, fabricmc
Rayon
Rigid body simulation for Minecraft
Stars: ✭ 25 (-41.86%)
Mutual labels:  minecraft-mod, fabricmc
BorderlessMining
A windowed borderless (fullscreen) mod for 1.15.2 and newer versions of Minecraft
Stars: ✭ 34 (-20.93%)
Mutual labels:  minecraft-mod, fabricmc
orion
Continuation of GhostTypes' Orion
Stars: ✭ 35 (-18.6%)
Mutual labels:  minecraft-mod, minecraft-fabric
SimplePipes
A small test pipes mod based around LibBlockAttributes
Stars: ✭ 22 (-48.84%)
Mutual labels:  minecraft-mod, minecraft-fabric
Jumploader
Use Fabric mods in Twitch modpacks!
Stars: ✭ 19 (-55.81%)
Mutual labels:  minecraft-mod, fabricmc
SpruceUI
A Minecraft library mod which adds a new abstraction to create GUI interfaces. Still close to the Vanilla design code-wise.
Stars: ✭ 47 (+9.3%)
Mutual labels:  minecraft-mod, fabricmc
anticope.ml
Welcome to the AntiCope Website! Here you can find a list of free and open-source Meteor Client addons as well as other client-side Fabric Minecraft mods.
Stars: ✭ 39 (-9.3%)
Mutual labels:  minecraft-mod, minecraft-fabric
ImageWorldGenerator
A minecraft mod to generate a world from an image/map
Stars: ✭ 20 (-53.49%)
Mutual labels:  minecraft-mod, fabricmc
meteor-rejects
An addon to Meteor Client that features that won't be added to Meteor. Because they were either rejected or are ports from other clients.
Stars: ✭ 144 (+234.88%)
Mutual labels:  minecraft-mod, minecraft-fabric
modget-minecraft
The Minecraft Mod Package Manager!
Stars: ✭ 47 (+9.3%)
Mutual labels:  minecraft-mod, fabricmc
Requiem
Revamps Minecraft's vanilla death experience and adds various related mechanics.
Stars: ✭ 88 (+104.65%)
Mutual labels:  minecraft-mod, fabricmc
the-hallow
Fabric Community mod for Hacktoberfest!
Stars: ✭ 14 (-67.44%)
Mutual labels:  minecraft-mod, fabricmc
Fabric-Autoswitch
Automagical switching of tools to the best one for the job, for Minecraft
Stars: ✭ 17 (-60.47%)
Mutual labels:  minecraft-mod, fabricmc

LibBlockAttributes

This is a library mod for the Fabric API, based around Minecraft.

This project has 3 major concepts: attributes, item management, and fluid management. Please open an issue if you have issues when using this, or join the CottonMC's discord (#lba channel) for discussion https://discord.gg/BjnuMUs.

Attributes

An "attribute" is just a class that has an instance of "alexiil.mc.lib.attributes.Attribute" stored in a public static final field.

A block can provide attribute instances by implementing AttributeProviderBlock and then offering instances like this:

public class MyBlock extends Block implements AttributeProviderBlock {
    @Override
    public void addAllAttributes(World world, BlockPos pos, BlockState state, AttributeList<?> to) {
        to.offer(an_attribute_instance);
    }
}

A block can request instances of a specific attribute by:

  1. Finding the appropriate public static final Attribute<> field.
    • This defines item attributes in "ItemAttributes", and fluid attributes in "FluidAttributes"
  2. Calling either "getAll", "getFirstOrNull", "getFirst", or "get" and passing in the appropriate world, position, and SearchOption.

For example a hopper-like block might call this:

/**
 * Finds an {@link ItemInsertable} in the given direction.
 *
 * @param world The world object to search within
 * @param thisPos The position to search from.
 * @param direction The direction to search in.
 * @return An {@link ItemInsertable} that we can attempt to insert into.
 */
public static ItemInsertable getNeighbourInsertable(World world, BlockPos thisPos, Direction direction) {

    BlockPos offsetPos = thisPos.offset(direction);

    // Note that the direction is always the direction of the search:
    // so it's always from the hopper to it's neighbour, and not the
    // side of the neighbour to search.
    SearchOption option = SearchOptions.inDirection(direction);

    // Note that this object will never be null - it will just return
    // a "rejecting" item insertable that never allows anything to be
    // inserted if there's no valid item insertable there. 
    return ItemAttributes.INSERTABLE.get(world, offsetPos, option);
}

You can create custom attributes by calling one of the create methods in Attributes. Note that attribute instances are never registered anywhere so you should store the attribute in a public static final Attribute<MyAttributeClass> field.

In addition there are three type of attribute:

  • Attribute: The base type, implies nothing about attribute instances but only provides the getAll() and getFirstOrNull() accessor methods.
  • DefaultedAttribute: This implies that it is always possible to have a default instance which can used safely everywhere that normal instances could be. This also provides the getFirst() accessor method.
  • CombinableAttribute: (extends DefaultedAttribute) This implies that it is always possible to combine multiple attribute instances and use them safely everywhere that normal instances can be. This provides the get() method which returns a combined version of getAll().

For example a custom attribute based around a fictional class RobotDockingPort (which could be used by buildcraft robots) would be defined like this:

public static final Attribute<RobotDockingPort> DOCKING_PORT = Attributes.create(RobotDockingPort.class);

Alternatively you can look inside FluidAttributes for an example involving combinable attributes.

Item Management

Everything in the "alexiil.mc.lib.attributes.item" package is dedicated to item management, and is intended for any mod to use.

The core API's are:

  • FixedItemInv* (A version of minecraft's Inventory class that only deals with indexed item slot accessors and modification).
  • FixedItemInvView* (A read-only version of FixedItemInv).
  • GroupedItemInv* (A version of FixedItemInv that operates like a Map<ItemStack, int amount> rather than a List).
  • GroupedItemInvView* (A read-only version of FixedItemInv).
  • ItemInsertable* (containing item insertion)
  • ItemExtractable* (containing item extraction)
  • ItemTransferable (containing item insertion and extraction, which extends ItemInsertable and ItemExtractable).
  • ItemFilter (a Predicate for ItemStacks)
  • ItemInvSlotChangeListener (for listening to changes in a FixedItemInvView - although not all implementations will support this).

(*Is an attribute in ItemAttributes)

In addition there are various utility classes:

  • ItemAttributes (containing all of the item attributes)
  • ItemInvUtil (for accessing attribute versions of the above API's, and a "move" method for moving items from an IItemExtractable to an IItemInsertable).
  • ItemStackUtil (containing general methods around single ItemStack instances that were needed to create this API).
  • ItemStackCollections (utility methods for creating Sets and Maps that compare ItemStack's correctly (as ItemStack itself doesn't override equals() or hashCode()).

The "impl" subpackage is also for public use, and it contains a lot of concrete implementations for the core API's.

Fluid Management

Everything in the "alexiil.mc.lib.attributes.fluid" package is dedicated to fluid management, and is intended for any mod to use. This is heavily based on the item management API, but with a few core changes:

  • Instead of ItemStack we have FluidVolume (with an amount) and FluidKey (without an amount)
  • Slots are called "tanks"
  • Tanks/Slots do not have a pre-defined maximum amount (and neither do fluids themselves as that depends wholly on the container).
  • The units for fluids are based around drips, bottles, and buckets, however custom fluids can use their own units if that makes more sense than the default (buckets).

The core API's are:

  • FixedFluidInv*.
  • FixedFluidInvView* (A read-only version of FixedFluidInv).
  • GroupedFluidInv* (A version of FixedFluidInv that operates like a Map<FluidKey, int amount> rather than a List).
  • GroupedFluidInvView* (A read-only version of GroupedFluidInv).
  • FluidInsertable* (containing fluid insertion)
  • FluidExtractable* (containing fluid extraction)
  • FluidTransferable (containing fluid insertion and extraction, which extends FluidInsertable and FluidExtractable).
  • FluidFilter (a Predicate for FluidKey's)
  • FluidInvTankChangeListener (for listening to changes in a FixedItemInvView - although not all implementations will support this).

(*Is an attribute in FluidAttributes)

In addition there are two utility classes:

  • FluidAttributes (containing all of the fluid attributes mentioned above)
  • FluidVolumeUtil (containing general methods around FluidVulume instances that were needed to create this API).

The "impl" subpackage is also for public use, and it contains a lot of concrete implementations for the core API's.

Maven

Currently you can use this by adding this to your build.gradle:

repositories {
    maven {
        name = "AlexIIL"
        url = "https://maven.alexiil.uk/"
    }
}

dependencies {
    modCompile "alexiil.mc.lib:libblockattributes-all:0.11.0"
}

And depending on "libblockattributes" in your fabric.mod.json. Note that this won't quite work correctly if all 3 of the modules are present, but the encompassing "all" is not. As such it's better to depend on both "libblockattributes_items" and "libblockattributes_fluids" if you need all 3. (You don't need to explicitly depend on "core" because both "items" and "fluids" depend on it).

However you can also depend on smaller parts of this if you don't need to use everything that this offers:

repositories {
    maven {
        name = "AlexIIL"
        url = "https://maven.alexiil.uk/"
    }
}

dependencies {
    // Uncomment out items and/or fluids to depend on either of them.
    // If you do then you can comment out core because items and fluids depend on it.
    // (Both items and fluids depend on core) 
    modCompile "alexiil.mc.lib:libblockattributes-core:0.11.0"
    // modCompile "alexiil.mc.lib:libblockattributes-items:0.11.0"
    // modCompile "alexiil.mc.lib:libblockattributes-fluids:0.11.0"
}

And depend on "libblockattributes_core", "libblockattributes_items", and "libblockattributes_fluids" in your fabric.mod.json.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].