Reliquary Reincarnations

Reliquary Reincarnations

51M Downloads

[1.15.2] [Compat] A player is not provided for the DirectionalPlaceContext used by the LanternOfParanoia

Laikulo opened this issue ยท 3 comments

commented

This can result in a crash whenever a mod tries to check something about the player (sneaking, creative mod, etc) and doesn't check for nulls.

While it would be nice if everyone checked for nulls, it might be a good idea to pass the player along, especially for mods that care about who is placing something.

Related issue: jaquadro/StorageDrawers#820

This function:

public void inventoryTick(ItemStack stack, World world, Entity entity, int itemSlot, boolean isSelected) {
if (!isEnabled(stack) || world.isRemote) {
return;
}
if (entity instanceof PlayerEntity) {
PlayerEntity player = (PlayerEntity) entity;
BlockPos.getAllInBox(player.getPosition().add(-getRange(), -getRange() / 2, -getRange()), player.getPosition().add(getRange(), getRange() / 2, getRange()))
.anyMatch(pos -> {
int lightLevel = player.world.getLightFor(LightType.BLOCK, pos);
if (lightLevel > Settings.COMMON.items.lanternOfParanoia.minLightLevel.get()) {
return false;
}
BlockState state = world.getBlockState(pos);
Block block = state.getBlock();
BlockItemUseContext context = new DirectionalPlaceContext(world, pos, Direction.DOWN, ItemStack.EMPTY, Direction.UP);
if (block instanceof FlowingFluidBlock || (!block.isAir(state, world, pos) && !state.isReplaceable(BlockItemUseContext.func_221536_a(context, pos, Direction.DOWN)))) {
return false;
}
return tryToPlaceTorchAround(stack, pos, player, world);
});
}
}

commented

closing this as it needs to be solved on storage drawers side

commented

Well, this is not an easy thing to do - either recalculate placement direction and position to a placement vector or implement a completely new class that's like DirectionalPlaceContext with player passed in. And at the same time getPlayer() of PlacementContext is defined as Nullable so mods absolutely have to be ready for it to be null, there are also implementations in vanilla that use DirectionalPlaceContext so they will return null as well. I will keep this around for a bit if I decide to add something additional in Reliquary, but at this point I am leaning towards just leaving it the way it is.

commented

Ah, for some reason I thought DirectionalPlaceContext already had that. I've been out of the game for a bit, so I'm a bit rusty on what has what.

As far as this specific interaction, I've opened a PR against Storage Drawers to add a null check, and am currently using that modded mod. I'll look around and see if I spot an easier solution.