WorldEdit
WorldEdit copied to clipboard
Check valid block types in block operations
Block operations that take a blocktype parameter from the user (such as //set) should check that the provided blocktype is really a block and not an item. Otherwise weird behavior will occur: //set gold sets the selection to gold blocks, but //set diamond sets the selection to water.
This could be done in the GetBlockTypeMeta function
After a talk with @Seadragon91 he said we need to check for metas as well. I don't think we should prevent people from using invalid meta's, since some metas in Minecraft aren't officially registered as a different block, but give a different texture nonetheless. Instead we should change the default meta. Currently every time somebody didn't give a meta value it gives 0 in return. This isn't always valid. For example chests don't have a 0 meta value.
If we change this line to
-- g_DefaultMetas doesn't exist yet though
return BlockID, g_DefaultMetas[BlockID] or 0, true
it should fix //set 54 (chest) but it wouldn't fix //set chest.
That should be fixed here. By checking if :%d+$ matches on the blockname. If it doesn't match you give the default meta in return.
That is something not exactly related to this issue. This issue was about trying to use items instead of blocks - //set diamond is actually a request to set the blocks to type E_ITEM_DIAMOND, while the user's intent was more likely //set diamondore or //set diamondblock. I think WE would be right to report an error and refuse the set in the invalid case.