From 8446e1e1b40060bdb73a7906abd196ba3a20e038 Mon Sep 17 00:00:00 2001 From: Xander Victory Date: Tue, 3 Oct 2017 09:12:34 +0800 Subject: [PATCH] null handling for BasicBlockType.get (cherry picked from commit 37576936e187e9ba347538bed1cc35765b226c5f) --- .../java/mekanism/common/block/states/BlockStateBasic.java | 6 ++++++ src/main/java/mekanism/common/item/ItemBlockBasic.java | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/mekanism/common/block/states/BlockStateBasic.java b/src/main/java/mekanism/common/block/states/BlockStateBasic.java index 6f85904d4..6e961ae2d 100644 --- a/src/main/java/mekanism/common/block/states/BlockStateBasic.java +++ b/src/main/java/mekanism/common/block/states/BlockStateBasic.java @@ -40,6 +40,8 @@ import net.minecraftforge.common.property.IUnlistedProperty; import com.google.common.base.Predicate; import com.google.common.base.Predicates; +import javax.annotation.Nullable; + public class BlockStateBasic extends ExtendedBlockState { public static final PropertyBool activeProperty = PropertyBool.create("active"); @@ -134,6 +136,7 @@ public class BlockStateBasic extends ExtendedBlockState isBeaconBase = beaconBase; } + @Nullable public static BasicBlockType get(IBlockState state) { if(state.getBlock() instanceof BlockBasic) @@ -144,11 +147,13 @@ public class BlockStateBasic extends ExtendedBlockState return null; } + @Nullable public static BasicBlockType get(ItemStack stack) { return get(Block.getBlockFromItem(stack.getItem()), stack.getItemDamage()); } + @Nullable public static BasicBlockType get(Block block, int meta) { if(block instanceof BlockBasic) @@ -159,6 +164,7 @@ public class BlockStateBasic extends ExtendedBlockState return null; } + @Nullable public static BasicBlockType get(BasicBlock blockType, int metadata) { BasicBlockType firstTry = values()[blockType.ordinal() << 4 | metadata]; diff --git a/src/main/java/mekanism/common/item/ItemBlockBasic.java b/src/main/java/mekanism/common/item/ItemBlockBasic.java index 801ea7549..85c270bfb 100644 --- a/src/main/java/mekanism/common/item/ItemBlockBasic.java +++ b/src/main/java/mekanism/common/item/ItemBlockBasic.java @@ -145,7 +145,7 @@ public class ItemBlockBasic extends ItemBlock implements IEnergizedItem, ITierIt { BasicBlockType type = BasicBlockType.get(itemstack); - if(type.hasDescription) + if(type != null && type.hasDescription) { if(!MekKeyHandler.getIsKeyPressed(MekanismKeyHandler.sneakKey)) { @@ -290,7 +290,7 @@ public class ItemBlockBasic extends ItemBlock implements IEnergizedItem, ITierIt if(type != null) { - String name = getUnlocalizedName() + "." + BasicBlockType.get(itemstack).name; + String name = getUnlocalizedName() + "." + type.name; if(type == BasicBlockType.BIN || type == BasicBlockType.INDUCTION_CELL || type == BasicBlockType.INDUCTION_PROVIDER) {