Skip to content

Commit

Permalink
Fixed potential Pattern crash when loading Minecraft. Fixes #3176
Browse files Browse the repository at this point in the history
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
  • Loading branch information
raoulvdberge committed Dec 16, 2021
1 parent 07b2dcb commit 48873ab
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public BlockEntityWithoutLevelRenderer getItemStackRenderer() {
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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public PatternItemBlockEntityRenderer(BlockEntityRenderDispatcher dispatcher, En

@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);

Expand Down

0 comments on commit 48873ab

Please sign in to comment.