Skip to content

Commit

Permalink
Improve null handling even more.
Browse files Browse the repository at this point in the history
This should finally resolve issues where server tick events calling
`doDecay`, etc, cause null pointer issues where the server is null or
the return of `MinecraftServer::overworld` is null.

I'm still convinced that these "issues" are simply masking the fact that
the server is in an errored state, or that these server tick events are
being called before the server has been set up -- all of which make no
sense, as the overworld is the first level created, and as such is
created in the instantiation of the server itself.
  • Loading branch information
noobanidus committed Jan 24, 2024
1 parent ec47db2 commit 16d6a17
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/main/java/noobanidus/mods/lootr/util/ChestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.MenuProvider;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.monster.piglin.PiglinAi;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
Expand Down Expand Up @@ -110,6 +109,10 @@ public static void handleLootChest(Block block, Level level, BlockPos pos, Playe
}
// Check if it already refreshed
MenuProvider provider = DataStorage.getInventory(level, tileId, pos, (ServerPlayer) player, (RandomizableContainerBlockEntity) te, tile::unpackLootTable);
if (provider == null) {
// Error messages are already handled by nested methods in `getInventory`
return;
}
checkScore((ServerPlayer) player, tileId);
if (addOpener(tile, player)) {
te.setChanged();
Expand Down Expand Up @@ -163,6 +166,10 @@ public static void handleLootCart(Level level, LootrChestMinecartEntity cart, Pl
}
}
MenuProvider provider = DataStorage.getInventory(level, cart, (ServerPlayer) player, cart::addLoot);
if (provider == null) {
// Error messages are already handled by nested methods in `getInventory`
return;
}
player.openMenu(provider);
}

Expand Down Expand Up @@ -194,6 +201,10 @@ public static void handleLootInventory(Block block, Level level, BlockPos pos, P
}
}
MenuProvider provider = DataStorage.getInventory(level, tile.getTileId(), stacks, (ServerPlayer) player, pos, tile);
if (provider == null) {
// Error messages are already handled by nested methods in `getInventory`
return;
}
checkScore((ServerPlayer) player, tile.getTileId());
if (addOpener(tile, player)) {
te.setChanged();
Expand Down

0 comments on commit 16d6a17

Please sign in to comment.