[SPIGOT-6781] Expose net.minecraft.world.level.block.state.BlockBase.BlockData#canPlace Created: 02/Nov/21  Updated: 23/Nov/21  Resolved: 23/Nov/21

Status: Resolved
Project: Spigot
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Minor
Reporter: JishunaMatata Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: API

Version: 3271-Spigot-3892929-cef1fda
Guidelines Read: Yes

 Description   

It would be nice to have net.minecraft.world.level.block.state.BlockBase.BlockData#canPlace exposed in spigot's BlockData interface, this method is overriden by various blocks to determine if they can be placed at a certain location.

This would be a replacement for the following method that makes use of NMS to call canPlace.

    public static boolean canPlace(BlockData data, Location location) {
        return ((CraftBlockData) data).getState().canPlace(((CraftWorld) location.getWorld()).getHandle(),
                new BlockPosition(location.getX(), location.getY(), location.getZ()));
    }


 Comments   
Comment by md_5 [ 23/Nov/21 ]

From discord:
[11:04 AM] md_5: I'd probably suggest Block#canPlace(BlockData)
[11:04 AM] md_5: but otherwise seems like 10 minutes work

Comment by JishunaMatata [ 02/Nov/21 ]

In this case I am using it to see if the default state of a material can be placed at a given location so I can allow dispensers to place blocks without them being placed in invalid locations (floating saplings, etc).

Comment by md_5 [ 02/Nov/21 ]

Be more specific about your use case please

Generated at Sat Apr 05 09:38:19 UTC 2025 using Jira 10.3.3#10030003-sha1:d220e3fefc8dfc6d47f522d3b9a20c1455e12b7b.