Skip to content

Commit dbce6b0

Browse files
committed
Fix crash when pickblocking invalid (or loading) shard block
1 parent c6c3289 commit dbce6b0

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/main/java/net/modfest/scatteredshards/block/ShardBlock.java

+11-6
Original file line numberDiff line numberDiff line change
@@ -115,21 +115,26 @@ public void onEntityCollision(BlockState state, World world, BlockPos pos, Entit
115115
tryCollect(world, player, be);
116116
}
117117
}
118-
118+
119119
@Override
120120
public ItemStack getPickStack(WorldView world, BlockPos pos, BlockState state) {
121-
121+
122122
BlockEntity entity = world.getBlockEntity(pos);
123123
if (world.isClient() && entity instanceof ShardBlockEntity shardEntity) {
124124
Identifier shardId = shardEntity.getShardId();
125125
ShardLibrary library = ScatteredShardsAPI.getClientLibrary();
126+
127+
if (shardId == null || library == null) {
128+
return super.getPickStack(world, pos, state);
129+
}
130+
126131
return createShardBlock(library, shardId, shardEntity.canInteract(), shardEntity.getGlowSize(), shardEntity.getGlowStrength());
127132
} else {
128-
133+
129134
return super.getPickStack(world, pos, state);
130135
}
131136
}
132-
137+
133138
/**
134139
* Creates a shard block
135140
*
@@ -165,10 +170,10 @@ public static ItemStack createShardBlock(ShardLibrary library, Identifier shardI
165170
166171
return stack;*/
167172
}
168-
173+
169174
public static ItemStack createShardBlock(ShardType shardType, Identifier shardId, Shard shard, boolean canInteract, float glowSize, float glowStrength) {
170175
ItemStack stack = new ItemStack(ScatteredShardsContent.SHARD_BLOCK);
171-
176+
172177
NbtCompound blockEntityTag = new NbtCompound();
173178
blockEntityTag.putString("id", ScatteredShardsContent.SHARD_BLOCK_ID.toString()); // required, see NbtComponent.CODEC_WITH_ID
174179
blockEntityTag.putString("Shard", shardId.toString());

0 commit comments

Comments
 (0)