I want to check is the block that the player see is a specific modded block and I don't find answers, can you help me ?
This is the code :
@Mod.EventBusSubscriber
public class CookerCraftingModdedRestrictionsProcedure {
@SubscribeEvent
public static void onPlayerTick(TickEvent.PlayerTickEvent event) {
if (event.phase == TickEvent.Phase.END) {
execute(event, event.player.level, event.player);
}
}
public static void execute(LevelAccessor world, Entity entity) {
execute(null, world, entity);
}
private static void execute(@Nullable Event event, LevelAccessor world, Entity entity) {
if (entity == null)
return;
if ((world.getBlockState(new BlockPos(
entity.level.clip(new ClipContext(entity.getEyePosition(1f), entity.getEyePosition(1f).add(entity.getViewVector(1f).scale(5)),
ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, entity)).getBlockPos().getX(),
entity.level.clip(new ClipContext(entity.getEyePosition(1f), entity.getEyePosition(1f).add(entity.getViewVector(1f).scale(5)),
ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, entity)).getBlockPos().getY(),
entity.level.clip(new ClipContext(entity.getEyePosition(1f), entity.getEyePosition(1f).add(entity.getViewVector(1f).scale(5)),
ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, entity)).getBlockPos().getZ())))
.getBlock().getRegistryName().equals(new ResourceLocation("minecraft", "diamond_ore"))) {
if (entity instanceof Player _player)
_player.closeContainer();
}
}
}
I know it don't work but I don't find anything better.
The imports aren't here but the error is not that.
I want to prevent players from opening the inventory of a specific modded block (here it is vanilla and it is the diamond block but it will be modified)
Hope you can help me.