Chisels & Bits - For Forge

Chisels & Bits - For Forge

108M Downloads

Chisel and Bits API -> get vanilla block from item.

Raycoms opened this issue ยท 10 comments

commented

Trying to find a way to get in-code the full vanilla origin block from a bit.

commented
commented

ty

commented

Out of curiosity, what feature are you working on?

commented
commented

I just took a quick look at the Mine Colonies code that refrences C&B, and I noticed 2 things:

  1. 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 with instanceof BlockChiseled. This can be replaced with instanceof 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).
  2. 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
commented

Ahh, ty, this is useful =)

commented

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 IChiseledBlockTileEntity to get the IBitAccess from: https://github.com/AlgorithmX2/Chisels-and-Bits/blob/e5f2d5affe954c773175b6dc9b9160bbac037eaa/src/main/java/mod/chiselsandbits/api/IChiseledBlockTileEntity.java#L23
That, or you need a world and a pos to get an IBitAccess: https://github.com/AlgorithmX2/Chisels-and-Bits/blob/e5f2d5affe954c773175b6dc9b9160bbac037eaa/src/main/java/mod/chiselsandbits/api/IChiselAndBitsAPI.java#L69-L71
And from that IBitAccess, you can get a stack: https://github.com/AlgorithmX2/Chisels-and-Bits/blob/e5f2d5affe954c773175b6dc9b9160bbac037eaa/src/main/java/mod/chiselsandbits/api/IBitAccess.java#L100-L103
Sorry about that.

commented

Is my way to visit the bits and add them to a stack not good?

commented

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.

commented

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.