Fixed potential Pattern crash when loading Minecraft. Fixes #3176

Fixes a NPE when using "level" later on in the pattern factory
Normally, this shouldn't be an issue because there is a hasTag() guard (and MC preloads tooltips of items where tag = null)
But for some reason, there is an environment where MC loads the Pattern tooltip (at startup) with a NBT tag
This commit is contained in:
raoulvdberge
2021-12-16 02:30:48 +01:00
parent 07b2dcba63
commit 48873ab12b
3 changed files with 3 additions and 2 deletions

View File

@@ -10,6 +10,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
### Fixed
- Fixed all Refined Storage advancements being granted when joining a world.
- Fixed potential Pattern crash when loading Minecraft.
## [v1.10.0-beta.1] - 2021-12-15

View File

@@ -219,7 +219,7 @@ public class PatternItem extends Item implements ICraftingPatternProvider, IItem
public void appendHoverText(ItemStack stack, @Nullable Level level, List<Component> tooltip, TooltipFlag flag) {
super.appendHoverText(stack, level, tooltip, flag);
if (!stack.hasTag()) {
if (!stack.hasTag() || level == null) {
return;
}

View File

@@ -22,7 +22,7 @@ public class PatternItemBlockEntityRenderer extends BlockEntityWithoutLevelRende
@Override
public void renderByItem(ItemStack stack, ItemTransforms.TransformType transformType, PoseStack poseStack, MultiBufferSource renderTypeBuffer, int combinedLight, int combinedOverlay) {
ICraftingPattern pattern = PatternItem.fromCache(null, stack);
ICraftingPattern pattern = PatternItem.fromCache(Minecraft.getInstance().level, stack);
ItemStack outputStack = pattern.getOutputs().get(0);