I want to get the BlockType from the block id in order to place a certain block. I found out (by checking what someBlock.getType().getId() returns) that the id is something to “minecraft:dirt” for a dirt block, but it does not work like that.
String blockId = "minecraft:dirt";
if (game.getRegistry().getType(BlockType.class, blockId).isPresent())
BlockType type = game.getRegistry().getType(BlockType.class, blockId).get();
It doesn’t matter which value I enter for blockId, game.getRegistry().getType(BlockType.class, blockId).isPresent() will always return false which means that the block id I entered doesn’t exist.
So what am I doing wrong and what is the correct format of block ids? I’d really appreciate some help ;D
It still won’t solve the underlying question which bugs me a little. In theory using the GameRegistry should work just as well. I guess someone more familiar with the implementation details needs to take a look at this…
Thank you! I had to solve the problem like @Azewilous suggested and set the type manually:
String block_name; // from the commands arguments
BlockType type = null;
case "dirt": type = BlockTypes.DIRT;
case "sometype": type = BlockTypes.SOMETYPE;
// added most important block types
Another problem concerning the PlayerInteractBlockEvent came up (which I don’t want to open a new thread for). Something should be done when a player clicks the left / right mouse button (or whatever is configured as ATTACK and USE). The USE interaction type is being fired twice, the first one takes the actual block the player right clicked on (for example a grass block) and the second one is always bedrock [EDIT: It’s actually not ALWAYS bedrock… it’s only bedrock if there is bedrock in the way of the mouse pointer, below the other blocks. If there is no bedrock in the mouse pointers way, then it’s only fired once]. I guess it shouldn’t be like that, or am I doing something wrong here?
public void onInteract(PlayerInteractBlockEvent e)
// this one works just fine
} else if (e.getInteractionType().equals(EntityInteractionTypes.USE))
// this one gets fired twice