-
Notifications
You must be signed in to change notification settings - Fork 56
Additional Item Placements
Make an existing item place a block, without replacing the item.
Vanilla ties one item to one block. If you add a "flower pot with a flower in it" block, the flower
item still can't place it, and you can't turn the flower into a BlockItem without breaking every
other mod that references it. This attaches a placement behavior to an item that's already
registered, so right clicking with it can place your block, while the item stays exactly what it was.
From mod setup:
AdditionalItemPlacementsAPI.registerSimplePlacement(Items.SUGAR_CANE, MY_SUGAR_CANE_BLOCK.get());For placement logic that isn't just "place this block", subclass AdditionalItemPlacement and
override what you need (overrideGetPlacementState, overridePlace, overrideUseOn,
overrideUpdatePlacementContext):
AdditionalItemPlacementsAPI.registerPlacement(Items.APPLE, new AdditionalItemPlacement(MY_BLOCK.get()) {
@Override
public BlockState overrideGetPlacementState(BlockPlaceContext context) {
return MY_BLOCK.get().defaultBlockState();
}
});Important
Register during mod setup, on both client and server. Only one placement per item: registering a second one replaces the first and logs a warning.
Basics Platform Helpers Registration Networking Events Configs Config Screen
Resources Runtime Resource Packs Texture Manipulation Resource Helpers Block Set API
Client Custom Models Item Rendering Rendered Textures Post Shaders GUI Toolkit Colors
World Block and Item Interfaces Additional Item Placements Improved Entities Fake Levels World Data Dispenser Behaviors
Utilities Codec Utilities Misc Helpers Commands
Datapacks Villagers Soft Fluids Map Markers Spawn Boxes Global Datapack Folder