sanity check the enum index calculation value before attempting to use it

(cherry picked from commit cb0f0086b9a70d457ff7bdc1e07451996c185e02)
This commit is contained in:
Xander Victory committed 2017-10-03 09:23:40 +08:00
1 parent 8446e1e1b4
commit 589346011d
1 file changed
+8 -4
@@ -167,11 +167,15 @@ public class BlockStateBasic extends ExtendedBlockState
@Nullable
public static BasicBlockType get(BasicBlock blockType, int metadata)
{
BasicBlockType firstTry = values()[blockType.ordinal() << 4 | metadata];
if(firstTry.blockType == blockType && firstTry.meta == metadata)
int index = blockType.ordinal() << 4 | metadata;
if (index < values().length)
{
return firstTry;
BasicBlockType firstTry = values()[index];
if(firstTry.blockType == blockType && firstTry.meta == metadata)
{
return firstTry;
}
}
for(BasicBlockType type : values())