From 408dee3fbb5e84fe72e700ea423c63707eae011a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Sat, 15 Jan 2022 19:37:39 +0100 Subject: [PATCH] Paranoia null checks. --- .../bus/BlockEntityDeviceBusController.java | 12 +++++++----- .../java/li/cil/oc2/common/item/WrenchItem.java | 6 +++++- .../li/cil/oc2/data/WrenchRecipeBuilder.java | 16 +++++++++++++--- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/main/java/li/cil/oc2/common/bus/BlockEntityDeviceBusController.java b/src/main/java/li/cil/oc2/common/bus/BlockEntityDeviceBusController.java index e805ee17..cd339a63 100644 --- a/src/main/java/li/cil/oc2/common/bus/BlockEntityDeviceBusController.java +++ b/src/main/java/li/cil/oc2/common/bus/BlockEntityDeviceBusController.java @@ -53,11 +53,13 @@ public final class BlockEntityDeviceBusController extends CommonDeviceBusControl if (element instanceof final BlockDeviceBusElement blockElement) { final LevelAccessor elementLevel = blockElement.getLevel(); final BlockPos elementPosition = blockElement.getPosition(); - newTrackedChunks.add(new TrackedChunk(elementLevel, elementPosition)); - newTrackedChunks.add(new TrackedChunk(elementLevel, elementPosition.relative(Direction.NORTH))); - newTrackedChunks.add(new TrackedChunk(elementLevel, elementPosition.relative(Direction.EAST))); - newTrackedChunks.add(new TrackedChunk(elementLevel, elementPosition.relative(Direction.SOUTH))); - newTrackedChunks.add(new TrackedChunk(elementLevel, elementPosition.relative(Direction.WEST))); + if (elementLevel != null) { + newTrackedChunks.add(new TrackedChunk(elementLevel, elementPosition)); + newTrackedChunks.add(new TrackedChunk(elementLevel, elementPosition.relative(Direction.NORTH))); + newTrackedChunks.add(new TrackedChunk(elementLevel, elementPosition.relative(Direction.EAST))); + newTrackedChunks.add(new TrackedChunk(elementLevel, elementPosition.relative(Direction.SOUTH))); + newTrackedChunks.add(new TrackedChunk(elementLevel, elementPosition.relative(Direction.WEST))); + } } } diff --git a/src/main/java/li/cil/oc2/common/item/WrenchItem.java b/src/main/java/li/cil/oc2/common/item/WrenchItem.java index d435d1fe..4fd5ab7c 100644 --- a/src/main/java/li/cil/oc2/common/item/WrenchItem.java +++ b/src/main/java/li/cil/oc2/common/item/WrenchItem.java @@ -2,6 +2,7 @@ package li.cil.oc2.common.item; import li.cil.oc2.common.tags.BlockTags; import net.minecraft.client.Minecraft; +import net.minecraft.client.multiplayer.MultiPlayerGameMode; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.server.level.ServerPlayer; @@ -53,7 +54,10 @@ public final class WrenchItem extends ModItem { } if (level.isClientSide()) { - Minecraft.getInstance().gameMode.destroyBlock(pos); + final MultiPlayerGameMode gameMode = Minecraft.getInstance().gameMode; + if (gameMode != null) { + gameMode.destroyBlock(pos); + } } else if (player instanceof final ServerPlayer serverPlayer) { serverPlayer.gameMode.destroyBlock(pos); } diff --git a/src/main/java/li/cil/oc2/data/WrenchRecipeBuilder.java b/src/main/java/li/cil/oc2/data/WrenchRecipeBuilder.java index 991a7930..ad00f1f3 100644 --- a/src/main/java/li/cil/oc2/data/WrenchRecipeBuilder.java +++ b/src/main/java/li/cil/oc2/data/WrenchRecipeBuilder.java @@ -13,6 +13,7 @@ import net.minecraft.advancements.critereon.RecipeUnlockedTrigger; import net.minecraft.data.recipes.FinishedRecipe; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.Tag; +import net.minecraft.world.item.CreativeModeTab; import net.minecraft.world.item.Item; import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.item.crafting.RecipeSerializer; @@ -84,7 +85,10 @@ public final class WrenchRecipeBuilder { } public void save(final Consumer consumerIn) { - this.save(consumerIn, ForgeRegistries.ITEMS.getKey(this.result)); + final ResourceLocation key = ForgeRegistries.ITEMS.getKey(this.result); + if (key != null) { + this.save(consumerIn, key); + } } public void save(final Consumer consumerIn, final String save) { @@ -99,7 +103,10 @@ public final class WrenchRecipeBuilder { public void save(final Consumer consumerIn, final ResourceLocation id) { this.validate(id); this.advancementBuilder.parent(new ResourceLocation("recipes/root")).addCriterion("has_the_recipe", RecipeUnlockedTrigger.unlocked(id)).rewards(AdvancementRewards.Builder.recipe(id)).requirements(RequirementsStrategy.OR); - consumerIn.accept(new WrenchRecipeBuilder.Result(id, this.result, this.count, this.group == null ? "" : this.group, this.ingredients, this.advancementBuilder, new ResourceLocation(id.getNamespace(), "recipes/" + this.result.getItemCategory().getRecipeFolderName() + "/" + id.getPath()))); + final CreativeModeTab itemCategory = this.result.getItemCategory(); + if (itemCategory != null) { + consumerIn.accept(new WrenchRecipeBuilder.Result(id, this.result, this.count, this.group == null ? "" : this.group, this.ingredients, this.advancementBuilder, new ResourceLocation(id.getNamespace(), "recipes/" + itemCategory.getRecipeFolderName() + "/" + id.getPath()))); + } } private void validate(final ResourceLocation id) { @@ -140,7 +147,10 @@ public final class WrenchRecipeBuilder { json.add("ingredients", jsonarray); final JsonObject jsonobject = new JsonObject(); - jsonobject.addProperty("item", ForgeRegistries.ITEMS.getKey(this.result).toString()); + final ResourceLocation key = ForgeRegistries.ITEMS.getKey(this.result); + if (key != null) { + jsonobject.addProperty("item", key.toString()); + } if (this.count > 1) { jsonobject.addProperty("count", this.count); }