Chisel and Bits API -> get vanilla block from item.
Raycoms opened this issue ยท 10 comments
IBlockState state = bit.getState();
Block block = state != null ? state.getBlock() : Blocks.AIR;
I just took a quick look at the Mine Colonies code that refrences C&B, and I noticed 2 things:
- In
ChiselAndBitsCheck#checkForChiselAndBitsBlock
https://github.com/ldtteam/minecolonies/blob/version/1.12/src/api/java/com/minecolonies/api/compatibility/candb/ChiselAndBitsCheck.java#L62 you are checking if a block is chiseled withinstanceof BlockChiseled
. This can be replaced withinstanceof IMultiStateBlock
(from C&B's API) to avoid core class reference (as far as I can tell, that's the only one, so you would then only depend on C&B's API, which is ideal). - Each of the 3 times that check is utilized (via
ChiselAndBitsCheck#isChiselAndBitsBlock
https://github.com/ldtteam/minecolonies/blob/version/1.12/src/api/java/com/minecolonies/api/compatibility/candb/ChiselAndBitsCheck.java#L42), it is done so to avoid trying to get an itemstack from a chisled block's blockstate. If it helps, you can use the API to get a stack from such a state:
https://github.com/AlgorithmX2/Chisels-and-Bits/blob/02588704452f1e183290e075bc4cfca6faea2fda/src/main/java/mod/chiselsandbits/api/IChiselAndBitsAPI.java#L135-L136
Actually, scratch point 2. I was looking at the wrong method (that's for getting a bit stack from a state). You actually need to have a tileentity that implements https://github.com/AlgorithmX2/Chisels-and-Bits/blob/e5f2d5affe954c773175b6dc9b9160bbac037eaa/src/main/java/mod/chiselsandbits/api/IChiseledBlockTileEntity.java#L23IChiseledBlockTileEntity
to get the IBitAccess
from:
That, or you need a world and a pos to get an https://github.com/AlgorithmX2/Chisels-and-Bits/blob/e5f2d5affe954c773175b6dc9b9160bbac037eaa/src/main/java/mod/chiselsandbits/api/IChiselAndBitsAPI.java#L69-L71IBitAccess
:
And from that https://github.com/AlgorithmX2/Chisels-and-Bits/blob/e5f2d5affe954c773175b6dc9b9160bbac037eaa/src/main/java/mod/chiselsandbits/api/IBitAccess.java#L100-L103IBitAccess
, you can get a stack:
Sorry about that.
No, it's fine (though it probably couldn't hurt to consolidate those stacks in that method -- unless you're already doing so down the line; I didn't check).
I just wanted to set the record straight after inadvertently posting that bit of misinformation.
Oh, I see, you do want the bit itemstacks. Also, I remembered that I recently added the state count list to IBitAccess: https://github.com/AlgorithmX2/Chisels-and-Bits/blob/3cd65709b4d4a22bbc0fa995834c406e7dee235c/src/main/java/mod/chiselsandbits/api/IBitAccess.java#L133
From that, you could just get the state from each state ID, then the stack from the state: https://github.com/AlgorithmX2/Chisels-and-Bits/blob/02588704452f1e183290e075bc4cfca6faea2fda/src/main/java/mod/chiselsandbits/api/IChiselAndBitsAPI.java#L135-L136
That would be even more efficient.