For example Ic2:generator:
-
GetID in hand:
ItemStack mainHandItem = player.getItemInHand(HandTypes.MAIN_HAND).get();
DataContainer container = mainHandItem.toContainer();
DataQuery query = DataQuery.of(’/’, “UnsafeDamage”);int unsafeDamage = Integer.parseInt(container.get(query).get().toString()); String itemId = mainHandItem.getType().getId(); if (unsafeDamage != 0) { itemId = itemId + ":" + unsafeDamage; }
Return itemId = “ic2:te:3”.
(mainHandItem.getType().getId() for this example return “ic2:te”, returns this the same for all items from IC2)
-
GetID from Listener:
@Listener
public void onBlockPlace(ChangeBlockEvent.Place event, @Root Player player) {
BlockSnapshot targetBlock = event.getTransactions().get(0).getFinal();
final BlockState blockstate = targetBlock .getState();
ItemStack itemStack = ItemStack.builder().fromBlockState(blockstate).build();
id = itemStack.getType().getId();// + “.” + itemStack.getItemDamage();DataContainer container = itemStack.toContainer(); DataQuery query = DataQuery.of('/', "UnsafeDamage"); int unsafeDamage = Integer.parseInt(container.get(query).get().toString()); if (unsafeDamage != 0) { id = id + ":" + unsafeDamage; }
This code Return Id is only (without “:3”) = “ic2:te”. returns this the same for all items from IC2
It doesn’t work right. How to implement the comparison of blocks in hand and blocks placed in the world?